aide-de-camp-sqlite
A SQLite backed implementation of the job Queue.
NOTE: It is possible that a single job gets sent to two runners. This is due to SQLite lacking
row locking and BEGIN EXCLUSIVE TRANSACTION
not working well (it was very slow) for this use
case. This is only an issue at high concurrency, in which case you probably don't want to use
SQLite in the first place. In other words, this isn't “Exactly Once” kind of queue.
Schema
TEXT PRIMARY KEY,
queue TEXT NOT NULL default 'default',
job_type TEXT not null,
payload blob not null,
retries int not null default 0,
scheduled_at INTEGER not null,
started_at INTEGER,
enqueued_at INTEGER not null default (strftime('%s', 'now')),
priority TINYINT not null default 0,
);
(
jid TEXT PRIMARY KEY,
queue TEXT NOT NULL,
job_type TEXT not null,
payload blob not null,
retries int not null,
scheduled_at INTEGER not null,
started_at INTEGER not null,
enqueued_at INTEGER not null,
died_at INTEGER not null default (strftime('%s', 'now')),
priority TINYINT not null default 0,
);
(
scheduled_at asc,
started_at asc,
queue,
job_type
);
(
jid
Crate includes SQLx MIGRATOR
that could be used to manage schema.
NOTE: SQLx doesn't support multiple migrators in the same database. That means ADC should either have dedicated schema/database or it's your responsibility to apply migrations.
Example
use ;
use ;
use async_trait;
use SqlitePool;
;
async