QueueDao

Functions

Link copied to clipboard
abstract suspend fun countNotSent(): Long
Link copied to clipboard
abstract fun countNotSentFlow(): Flow<Long>

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.

Link copied to clipboard
abstract suspend fun deleteById(id: String): Int
Link copied to clipboard
abstract suspend fun deleteByUserId(userId: String): Int
Link copied to clipboard
abstract suspend fun deleteFailedOlderThan(cutoffMs: Long): Int
Link copied to clipboard
abstract suspend fun deleteOldestEligible(limit: Int): Int

Deletes oldest non-sent, non-quarantined events. Used for backpressure.

Link copied to clipboard
abstract suspend fun deleteQuarantinedOlderThan(cutoffMs: Long): Int
Link copied to clipboard
abstract suspend fun deleteSentOlderThan(cutoffMs: Long): Int
Link copied to clipboard
abstract suspend fun getAnomalous(threshold: Float): List<QueueEventEntity>
Link copied to clipboard
abstract suspend fun getByUserId(userId: String): List<QueueEventEntity>
Link copied to clipboard
abstract suspend fun insert(e: QueueEventEntity)
Link copied to clipboard
abstract suspend fun loadNextBatch(nowMs: Long, limit: Int): List<QueueEventEntity>

Returns oldest eligible PENDING and FAILED events for processing. Eligibility = not permanent + backoff gate passed.

Link copied to clipboard
abstract suspend fun loadQuarantinedSummaries(limit: Int): List<QuarantinedEventRow>
Link copied to clipboard
abstract suspend fun markBatchFailureNoAttemptBump(id: String, error: String, nextAttemptAtMs: Long, nowMs: Long)

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.

Link copied to clipboard
abstract suspend fun markFailed(id: String, error: String, quarantineReason: String?, nextAttemptAtMs: Long, permanentFailure: Int, nowMs: Long)
Link copied to clipboard
abstract suspend fun markSending(id: String, nowMs: Long)
Link copied to clipboard
abstract suspend fun markSent(id: String, nowMs: Long)
Link copied to clipboard
abstract suspend fun reconcileStaleSending(staleBeforeEpochMs: Long, nowMs: Long): Int

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.

Link copied to clipboard
abstract suspend fun sumNotSentBytes(): Long