Harden sync retry and expose batch backup operation

This commit is contained in:
bponders12-cell 2026-09-01 20:45:40 -04:00
parent 6fd81fc1e6
commit 2146a718fb
1 changed files with 17 additions and 3 deletions

View File

@ -63,7 +63,19 @@ class SyncManager extends ChangeNotifier {
return item; return item;
} }
/// Rearms only authentication-blocked work. Call this after a successful login/link. /// Enqueues every local ride for the selected cloud provider. Existing
/// synced/queued items remain idempotent and are not duplicated.
Future<int> backupAllRideIds(Iterable<int> rideIds, {String? targetProviderId}) async {
var enqueued = 0;
for (final rideId in rideIds) {
await enqueueRide(rideId, targetProviderId: targetProviderId, autoProcess: false);
enqueued++;
}
if (enqueued > 0) unawaited(processQueue());
return enqueued;
}
/// Rearms authentication-blocked work. Call this after a successful login/link.
Future<void> retryAuthRequired() async { Future<void> retryAuthRequired() async {
for (final item in _outbox.getAllItems().where((i) => i.status == SyncStatus.authRequired)) { for (final item in _outbox.getAllItems().where((i) => i.status == SyncStatus.authRequired)) {
await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true)); await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true));
@ -88,7 +100,6 @@ class SyncManager extends ChangeNotifier {
notifyListeners(); notifyListeners();
try { try {
final now = _now(); final now = _now();
// Snapshot eligible items once; each item is durably marked before network I/O.
final eligibleItems = _outbox.getEligibleItems(now); final eligibleItems = _outbox.getEligibleItems(now);
for (final item in eligibleItems) { for (final item in eligibleItems) {
final provider = _providers[item.providerId]; final provider = _providers[item.providerId];
@ -141,8 +152,11 @@ class SyncManager extends ChangeNotifier {
} }
} }
/// Re-arms retryable/pending work and terminal failures. Failed items are
/// intentionally retained until the retry is explicitly requested.
Future<void> retryAllPending() async { Future<void> retryAllPending() async {
for (final item in _outbox.getPendingItems()) { final retryable = _outbox.getAllItems().where((i) => i.status.isPending || i.status == SyncStatus.failed).toList(growable: false);
for (final item in retryable) {
await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true)); await _outbox.update(item.copyWith(status: SyncStatus.queued, clearLastError: true, clearNextRetry: true));
} }
await processQueue(); await processQueue();