Expand description
§cronoq-store-sqlite
A SQLite Store for cronoq: durable state in one local file, no database server.
- Write-ahead state: every engine state transition is committed in batches, one transaction per batch, before submitters are acknowledged. The file uses SQLite’s WAL journal and, by default, syncs it on every commit.
- Leader and standbys: several processes on the same host may open the same file. One
leads through a lease row in
cronoq_leaderthat it renews; the others wait and take over once the lease runs out. Taking over bumps a fencing epoch. - Fencing: each commit re-reads the epoch and lease holder inside its write transaction
(SQLite serializes writers) and fails with
StoreError::Fencedif another process took over, so a paused old leader can never write after a standby replaced it. - Recovery: a new leader loads live tasks, recently finished ones (for key deduplication), every finished task a live task still depends on, and recurring schedules. Rows that cannot be decoded are quarantined (marked failed).
- Files: the database is created readable and writable by its owner only (on Unix). Keep it on a local filesystem: SQLite’s WAL mode does not work over network filesystems.
Times are stored as wall-clock Unix nanoseconds; strings are stored with NUL replaced by U+FFFD, as in the PostgreSQL store. Lease expiry uses the wall clock, which processes on one host share.
use bytes::Bytes;
use cronoq::{Pool, Scheduler};
use cronoq_store_sqlite::SqliteStore;
let store = SqliteStore::open("/var/lib/cronoq/state.db").await?;
let sched = Scheduler::<Bytes, Bytes>::builder()
.pool(Pool::new("default").executor_fn(|_ctx, p: std::sync::Arc<Bytes>| async move {
Ok::<_, cronoq::TaskError>((*p).clone())
}))
.store(store.clone())
.build() // blocks until this process is the leader
.await?;
tokio::select! {
_ = store.leadership_lost() => { /* step down: stop serving, exit or rejoin */ }
_ = tokio::signal::ctrl_c() => {}
}Structs§
- Sqlite
Store - SQLite-backed
Store. Cheap to clone. - Sqlite
Store Config - Store configuration.
Type Aliases§
- Task
Record - Persisted view of a task, for lookups by id or key.