Queue Dao
Functions
Room-reactive variant of countNotSent. Emits a new value whenever rows matching the state != 'SENT' predicate are inserted, updated, or deleted. Cheaper and more responsive than polling on a timer.
Deletes oldest non-sent, non-quarantined events. Used for backpressure.
Returns oldest eligible PENDING and FAILED events for processing. Eligibility = not permanent + backoff gate passed.
Record a batch-level failure without bumping per-event attempts. Used when the whole batch fails for reasons outside the individual event (network transient, auth error, schema-level permanent). Without this, a single 30-minute outage processed as 50-event batches would march every event to maxAttemptsPerEvent and quarantine the fleet's backlog despite nothing being wrong with the events.
Rescue SENDING rows stranded across a process restart. An event is marked SENDING just before transport; if the process dies mid-flight, the row stays SENDING forever and loadNextBatch never picks it up (it only selects PENDING/FAILED), so the event silently rots until retention deletes it.