Expand description
Postgres JobRepository + CronJobRepository — port of wabot-ts
addon/async/pg (JobPgQueries / CronJobPgQueries).
Both are PgJsonbStore wrappers: the entity lives in a data
JSONB column and the queries read it with data->>'field'
expressions, exactly like the TS versions, so the SQL is
recognisable side by side.
ⓘ
let db = PgDatabase::from_env().await?;
let jobs = Arc::new(PgJobRepository::new(db.pool().clone()));
let crons = Arc::new(PgCronJobRepository::new(db.pool().clone()));
register_job_repository(&c, jobs);
register_cron_job_repository(&c, crons);
register_locker(&c, PgLocker::arc(db.pool().clone())); // multi-node safe
register_async_runtime(&c);§Indexes
Both stores declare the indexes their hot queries need, created alongside the table on first use:
- jobs: a partial index over
scheduledAtrestricted to unfinished rows — that’s the scheduler’s every-tick query, and the partial predicate keeps the index small as completed jobs pile up. - jobs:
(commandName, dedupKey)for the dedup lookup. - cron jobs:
nextRunAtfor the due scan, and a unique index onnameso two nodes reconciling the same cron can’t create two rows.
Structs§
Constants§
- CRON_
JOBS_ TABLE - JOBS_
TABLE - Default table names. Match the TS
@repository({ table })values so both stacks address the same rows.