feat(worker): add prefetch scheduling to reschedule logic
When a notification is displayed and rescheduled for the next occurrence, now also schedule a background fetch to prefetch content 5 minutes before the next notification time. - Add DailyNotificationFetcher import to DailyNotificationWorker - In scheduleNextNotification(), after successfully scheduling notification, calculate fetch time (5 minutes before next scheduled time) - Create DailyNotificationFetcher instance and schedule prefetch - Add logging with DN|RESCHEDULE_PREFETCH_SCHEDULED tag for observability - Fall back to immediate fetch if fetch time is in the past This ensures the prefetch → cache → schedule → display pipeline continues for subsequent notifications, not just the initial scheduling.
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.timesafari.dailynotification.storage.DailyNotificationStorageRoom;
|
||||
import com.timesafari.dailynotification.entities.NotificationContentEntity;
|
||||
import com.timesafari.dailynotification.DailyNotificationFetcher;
|
||||
|
||||
/**
|
||||
* WorkManager worker for processing daily notifications
|
||||
@@ -512,6 +513,36 @@ public class DailyNotificationWorker extends Worker {
|
||||
// Log next scheduled time in readable format
|
||||
String nextTimeStr = formatScheduledTime(nextScheduledTime);
|
||||
Log.i(TAG, "DN|RESCHEDULE_OK id=" + content.getId() + " next=" + nextTimeStr);
|
||||
|
||||
// Schedule background fetch for next notification (5 minutes before scheduled time)
|
||||
try {
|
||||
DailyNotificationStorage storageForFetcher = new DailyNotificationStorage(getApplicationContext());
|
||||
DailyNotificationStorageRoom roomStorageForFetcher = new DailyNotificationStorageRoom(getApplicationContext());
|
||||
DailyNotificationFetcher fetcher = new DailyNotificationFetcher(
|
||||
getApplicationContext(),
|
||||
storageForFetcher,
|
||||
roomStorageForFetcher
|
||||
);
|
||||
|
||||
// Calculate fetch time (5 minutes before notification)
|
||||
long fetchTime = nextScheduledTime - TimeUnit.MINUTES.toMillis(5);
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
if (fetchTime > currentTime) {
|
||||
fetcher.scheduleFetch(fetchTime);
|
||||
Log.i(TAG, "DN|RESCHEDULE_PREFETCH_SCHEDULED id=" + content.getId() +
|
||||
" next_fetch=" + fetchTime +
|
||||
" next_notification=" + nextScheduledTime);
|
||||
} else {
|
||||
Log.w(TAG, "DN|RESCHEDULE_PREFETCH_PAST id=" + content.getId() +
|
||||
" fetch_time=" + fetchTime +
|
||||
" current=" + currentTime);
|
||||
fetcher.scheduleImmediateFetch();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "DN|RESCHEDULE_PREFETCH_ERR id=" + content.getId() +
|
||||
" error scheduling prefetch", e);
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "DN|RESCHEDULE_ERR id=" + content.getId());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user