48 lines
1.9 KiB
Diff
48 lines
1.9 KiB
Diff
--- a/src/org/droidtv/gel/gathering/GatheringService.java
|
|
+++ b/src/org/droidtv/gel/gathering/GatheringService.java
|
|
@@
|
|
- OneTimeWorkRequest request = GELWorker.buildWorkRequest(intent);
|
|
- workManager.enqueueUniqueWork("GEL_WORK",
|
|
- ExistingWorkPolicy.APPEND_OR_REPLACE, request);
|
|
+ eventOutbox.enqueue(EventRecord.from(intent), EventClassifier.forIntent(intent));
|
|
+ OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(GELDrainWorker.class)
|
|
+ .keepResultsForAtLeast(10, TimeUnit.MINUTES)
|
|
+ .build();
|
|
+ workManager.enqueueUniqueWork("GEL_DRAIN", ExistingWorkPolicy.KEEP, request);
|
|
|
|
--- a/src/org/droidtv/gel/gathering/GELWorker.java
|
|
+++ b/src/org/droidtv/gel/gathering/GELDrainWorker.java
|
|
@@
|
|
- Intent intent = intentFromWorkData(getInputData());
|
|
- gatheringService.dispatch(intent);
|
|
- return Result.success();
|
|
+ final long deadline = SystemClock.elapsedRealtime() + TimeUnit.MINUTES.toMillis(8);
|
|
+ while (SystemClock.elapsedRealtime() < deadline) {
|
|
+ EventRecord event = eventOutbox.peekOldest();
|
|
+ if (event == null) {
|
|
+ SystemClock.sleep(500);
|
|
+ if (eventOutbox.peekOldest() == null) return Result.success();
|
|
+ continue;
|
|
+ }
|
|
+ gatheringService.dispatch(event.toIntent());
|
|
+ eventOutbox.ack(event.sequence); // only after successful dispatch
|
|
+ }
|
|
+ return Result.retry(); // same WorkSpec; no appended dependency
|
|
|
|
--- /dev/null
|
|
+++ b/src/org/droidtv/gel/gathering/EventOutbox.sql
|
|
@@
|
|
+CREATE TABLE gel_event_outbox(
|
|
+ sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
+ action TEXT NOT NULL,
|
|
+ payload BLOB NOT NULL,
|
|
+ coalesce_key TEXT UNIQUE,
|
|
+ created_ms INTEGER NOT NULL,
|
|
+ attempts INTEGER NOT NULL DEFAULT 0
|
|
+);
|
|
|
|
# Add one PeriodicWorkRequest named GEL_DRAIN_WATCHDOG with KEEP (15 minutes)
|
|
# for crash/race recovery. Enforce a 4,096-row/8-MiB cap with an explicit
|
|
# dropped-event counter. Only repetitive alarm/state snapshots may coalesce;
|
|
# command/debug actions and events with delivery semantics may not.
|