Skip to content

Commit 40bf9e7

Browse files
eriedclaude
andcommitted
fix(upload): eagerly cancel upload work when prerequisites disappear
The worker-level gate from the previous commit caught the case lazily (next scheduled run sees the missing prerequisite and bails), but the cancelled work still sat in WorkManager's queue until its backoff timer elapsed. If the retry was parked on the 32m / 1h step, that's the window the cancelled work would sit "scheduled but doomed". Now the three opt-out paths drop the unique-work entry immediately: - SyncManager.clearSyncFolder → cancels BOTH workers - SettingsViewModel.unlinkOnline → cancels eucstats - SettingsViewModel.deleteOnline → cancels eucstats (post-success) clearSyncFolder cancels both because eucstats's rider id file lives in the SAF folder; losing the folder loses online identity too. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c43fe51 commit 40bf9e7

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

app/src/main/java/com/eried/eucplanet/data/sync/SyncManager.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ class SyncManager @Inject constructor(
376376
lastSettingsBackupAt = null,
377377
onlineUploadEnabled = false, // online upload requires a folder
378378
))
379+
// Both destinations just lost their prerequisites: folder is gone, and
380+
// the rider id file went with it. Drop any pending retries so we don't
381+
// sit on a backed-off worker that would only no-op when it finally fires.
382+
cancelTripUpload()
383+
cancelEucStatsUpload()
379384
}
380385

381386
/** The chosen folder's DocumentFile, or null if none or no longer accessible. */
@@ -687,6 +692,23 @@ class SyncManager @Inject constructor(
687692
)
688693
}
689694

695+
/** Cancel any queued / in-backoff folder-upload work. Used when the rider
696+
* unlinks the sync folder so a long-tail retry doesn't sit waiting for a
697+
* destination that no longer exists. */
698+
fun cancelTripUpload() {
699+
WorkManager.getInstance(context).cancelUniqueWork(UPLOAD_WORK_NAME)
700+
}
701+
702+
/** Cancel any queued / in-backoff eucstats-upload work. Used when the rider
703+
* toggles leaderboards off, deletes their account, or unlinks the sync
704+
* folder (since the rider id lives in that folder). Without this, a retry
705+
* parked on the 32m / 1h step would still fire later and find the
706+
* prerequisites gone; cancelling here keeps the trip icons and WorkManager
707+
* state in lockstep. */
708+
fun cancelEucStatsUpload() {
709+
WorkManager.getInstance(context).cancelUniqueWork(EUCSTATS_UPLOAD_WORK_NAME)
710+
}
711+
690712
/** Schedule the eucstats worker for [attempt]. See [scheduleTripUploadAttempt]
691713
* for semantics; this one also carries the CONNECTED network constraint. */
692714
fun scheduleEucStatsUploadAttempt(attempt: Int) {

app/src/main/java/com/eried/eucplanet/ui/settings/SettingsViewModel.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,10 @@ class SettingsViewModel @Inject constructor(
20132013
}
20142014
}
20152015
settingsRepository.update(settingsRepository.get().copy(onlineUploadEnabled = false))
2016+
// Drop any queued / in-backoff retries; the gate inside the worker
2017+
// would catch them anyway but cancelling now keeps the unique-work
2018+
// entry from sitting around until its delay elapses.
2019+
syncManager.cancelEucStatsUpload()
20162020
}
20172021
}
20182022

@@ -2085,7 +2089,12 @@ class SettingsViewModel @Inject constructor(
20852089
// Remove the local recovery file too, so the just-deleted profile is
20862090
// not offered for "restore" on the next Join (it no longer exists
20872091
// server-side). Best-effort, only when the server delete succeeded.
2088-
if (ok) syncManager.deleteRiderIdFile()
2092+
if (ok) {
2093+
syncManager.deleteRiderIdFile()
2094+
// Drop any queued / in-backoff eucstats retries so they don't
2095+
// wake up later and hit a deleted account.
2096+
syncManager.cancelEucStatsUpload()
2097+
}
20892098
onResult(ok)
20902099
}
20912100
}

0 commit comments

Comments
 (0)