Skip to content

sqlite

etrack.providers.adapters.outbox.sqlite

providers/adapters/outbox/sqlite: SqliteAdapter — the outbox in one SQLite file, on the standard library.

One table, one row per undelivered item: append inserts once per key (a key already there is not appended again), claim leases what is due in one statement, ack deletes, release and dead settle, requeue gives a dead item a fresh deadline. The connection is the process's own, in WAL mode with synchronous=FULL: a committed append survives a killed process and a lost machine alike. Every call runs on a worker thread, one at a time, so the loop never waits on the disk.

SqliteAdapter

SqliteAdapter(path: Path)

The outbox in a SQLite file: durable on commit, read and written off the loop, one call at a time.

ack async

ack(key: str) -> None

Delivered: the item leaves the outbox.

append async

append(key: str, item: bytes) -> bool

The item stored under key, due now; False when the key is already there (nothing is appended twice).

claim async

claim(limit: int, lease: timedelta) -> Sequence[Entry]

Up to limit due items, the oldest first, each leased for lease and counted as one more attempt.

dead async

dead(key: str, reason: str) -> None

Given up, with why: kept, never claimed again unless requeued.

health async

health() -> bool

Open, and its file answers.

of async

of(key: str) -> Entry | None

The item under key while it is undelivered; None once delivered or never appended.

release async

release(key: str, due: datetime, reason: str) -> None

Not delivered this time: due again at due, with why.

report async

report() -> Mapping[EntryState, int]

How many items are pending and dead.

requeue async

requeue(key: str) -> bool

A dead item due again now, its attempts and its deadline started afresh; False when it is not dead.

Statement

Bases: StrEnum

Every statement the adapter runs: the outbox's whole SQL, in one place.