pendingAndFailed method
- int limit = 100,
Oldest-first list of events eligible for a sync attempt now: all
pending/syncing rows, plus failed rows that are (a) under
maxAttempts and (b) past their exponential-backoff window. Rows past
the attempt cap stay failed and are surfaced in the "Needs attention"
UI (where the user can markPending to retry) rather than retried
automatically.
Implementation
List<OutboxEvent> pendingAndFailed({int limit = 100}) {
_requireReady();
final rs = _db!.select(
'''
SELECT * FROM outbox_events
WHERE state IN ('pending','syncing')
OR (state = 'failed' AND attempt_count < ?)
ORDER BY created_at ASC
LIMIT ?
''',
[maxAttempts, limit],
);
final now = DateTime.now().toUtc();
return rs
.map(OutboxEvent.fromRow)
.where((e) => e.state != 'failed' || failedRowIsDue(e, now))
.toList(growable: false);
}