Expand description
PostgreSQL SchedulerStore for Chronon.
When to use: shared durable storage for Mode 1 or Mode 2 coordinator–worker
clusters. For higher claim throughput, wrap with PostgresRedisSchedulerStore
(chronon-backend-redis).
Getting started: Mode 1 / Mode 2.
§Stack position
chronon (facade, `postgres` feature) → chronon-backend-postgres → chronon-backend-sql-common → chronon-core§Entry points
PostgresSchedulerStore::connect— open a pool and bootstrap schemaPostgresSchedulerStore::connect_isolated— isolated schema for parallel testspostgres_test_url— resolve test URL fromCHRONON_POSTGRES_URL/CHRONON_TEST_POSTGRES_URL
§Mode 1 — Embedded
ⓘ
use std::sync::Arc;
use chronon::prelude::*;
use chronon::PostgresSchedulerStore;
let url = std::env::var("CHRONON_POSTGRES_URL")?;
let store = PostgresSchedulerStore::connect(&url).await?;
let chronon = ChrononBuilder::new()
.scheduler_store(Arc::new(store))
.context_factory(Arc::new(JsonScriptContextFactory))
.embedded()
.auto_registry()
.build()?;Runnable: cargo run -p uf-chronon --example postgres_boot --features postgres
§Mode 2 — Coordinator binary
Shared CHRONON_POSTGRES_URL with workers. Tick only:
ⓘ
use std::sync::Arc;
use chronon::prelude::*;
use chronon::PostgresSchedulerStore;
let url = std::env::var("CHRONON_POSTGRES_URL")?;
let store = PostgresSchedulerStore::connect(&url).await?;
let mut chronon = ChrononBuilder::new()
.scheduler_store(Arc::new(store))
.context_factory(Arc::new(JsonScriptContextFactory))
.instance_id("coordinator-0")
.coordinator_only()
.build()?;
chronon.scheduler.init_partitions().await;
chronon.run().await?;§Mode 2 — Worker binary
Same Postgres URL, unique CHRONON_INSTANCE_ID, scripts via .auto_registry():
ⓘ
use std::sync::Arc;
use chronon::prelude::*;
use chronon::PostgresSchedulerStore;
let url = std::env::var("CHRONON_POSTGRES_URL")?;
let store = PostgresSchedulerStore::connect(&url).await?;
let mut chronon = ChrononBuilder::new()
.scheduler_store(Arc::new(store))
.context_factory(Arc::new(JsonScriptContextFactory))
.instance_id(std::env::var("CHRONON_INSTANCE_ID").unwrap_or_else(|_| "worker-1".into()))
.auto_registry()
.worker("general")
.build()?;
chronon.run().await?;Production claim path: Postgres + Redis.
Structs§
- Postgres
Scheduler Store - PostgreSQL-backed scheduler store.
Functions§
- postgres_
store_ from_ env - Connect using
CHRONON_POSTGRES_SCHEMAwhen set (isolated schema for multi-process E2E). - postgres_
test_ url - Resolve a PostgreSQL URL for tests.