APScheduler 4 on pgdorm — 1-RTT release_job, SKIP LOCKED & LISTEN/NOTIFY#
APScheduler 4's PostgreSQL backend (SQLAlchemyDataStore + AsyncpgEventBroker) pulls in SQLAlchemy, asyncpg, and greenlet, and executes release_job across multiple sequential statements. PgdormDataStore + PgdormEventBroker runs a real AsyncScheduler directly on assimilated pgdorm Table + TypeTable models with 1-RTT release_job, FOR UPDATE SKIP LOCKED leases, and native Pool.listen/notify.
Before vs. After#
| Dimension | Upstream SQLAlchemyDataStore |
PgdormDataStore + PgdormEventBroker |
|---|---|---|
release_job (insert result + delete job + decr running_jobs + COMMIT) |
4+ wire round trips via SQLAlchemy AsyncSession |
1 wire RTT (tx.pipeline(commit=True)) |
| Job & schedule leases | SQLAlchemy ORM + greenlet bridge |
Native FOR UPDATE SKIP LOCKED + = ANY($1) |
Enum columns (joboutcome, coalescepolicy) |
Native PG ENUMs (ALTER TYPE pain) |
Assimilated pg.TypeTable + IntEnum PKs |
| Event fanout | Separate asyncpg connection pool |
Built-in pool.listen() / pool.notify() |
tests/cases/apscheduler/datastore.py — 1-RTT release_job pipeline
async with self._pool.transaction() as tx, tx.pipeline(commit=True) as pipe:
if result.expires_at > result.finished_at:
pipe.add(pg.insert(ApsJobResult).values(res_row).on_conflict_do_nothing())
pipe.add(pg.delete(ApsJob).where(ApsJob.job_id == job.id))
pipe.add(
pg.update(ApsTask)
.set(running_jobs=ApsTask.running_jobs - 1)
.where((ApsTask.task_id == job.task_id) & (ApsTask.running_jobs > 0))
)
Adoption Ladder (Live PostgreSQL)#
| Status | Rung | Today | Blocked by |
|---|---|---|---|
| ✅ | Audit the live schema | 5 tables; left untouched: nothing | — |
| ❌ | Bind models to the live schema, zero DDL | 6 residual ops after bind | #31 |
| ❌ | Build a fresh database from the models alone | type "coalescepolicy" does not exist (pipeline step 1) | #31 |
| ✅ | Assimilate the upstream schema into idiomatic pgdorm (with TypeTables) | 22 assimilation ops applied cleanly, 0 blockers, 0 residual ops | — |
| ✅ | Run core DataStore + EventBroker operations (add_task, acquire_jobs, release_job, listen/notify) | 5 of 5 named queries, each graded upstream | — |
| ✅ | Run real APScheduler AsyncScheduler jobs end-to-end on pgdorm | Live AsyncScheduler + 1-RTT release_job pipeline + SKIP LOCKED + Pool.listen/notify | — |