Skip to main content

Crate wabot_addon_async_pg

Crate wabot_addon_async_pg 

Source
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 scheduledAt restricted 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: nextRunAt for the due scan, and a unique index on name so two nodes reconciling the same cron can’t create two rows.

Structs§

PgCronJobRepository
PgJobRepository

Constants§

CRON_JOBS_TABLE
JOBS_TABLE
Default table names. Match the TS @repository({ table }) values so both stacks address the same rows.