RoomOpOutbox

Room-backed OpOutbox. The replay semantics (dead-letter on permanent/exhausted, stop-on-transient to preserve order) live here; the DAO only moves rows. Payload is an opaque string — the caller serializes before enqueue and deserializes inside its send, so this stays transport-agnostic.

Constructors

Link copied to clipboard
constructor(dao: OpOutboxDao)

Functions

Link copied to clipboard
open suspend override fun deadLetters(): List<OpEntry>

Dead-lettered ops, for inspection or a manual-retry UI.

Link copied to clipboard
open suspend override fun enqueue(type: String, payload: String): String

Append an op; returns its id (= idempotency key). Triggering replay afterwards is the caller's job.

Link copied to clipboard
open override fun pending(): Flow<List<OpEntry>>

Observe live (non-dead) queue contents, oldest-first — drives a "N pending" sync indicator.

Link copied to clipboard
open suspend override fun replay(maxAttempts: Int = DEFAULT_MAX_ATTEMPTS, isPermanent: (Throwable) -> Boolean = { false }, send: suspend (OpEntry) -> Unit)

Drain PENDING ops oldest-first. For each, calls send; on success the op is deleted. On failure: if isPermanent returns true for the error, or the op has now failed maxAttempts times, it is dead-lettered and replay continues; otherwise the failure is recorded and replay STOPS (preserving order) — the next trigger resumes from the same op.

Link copied to clipboard
open suspend override fun requeue(id: String)

Requeue a dead-lettered op (reset attempts + status to PENDING) for a manual retry.