Skip to main content

Crate chronon_backend_postgres

Crate chronon_backend_postgres 

Source
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

§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§

PostgresSchedulerStore
PostgreSQL-backed scheduler store.

Functions§

postgres_store_from_env
Connect using CHRONON_POSTGRES_SCHEMA when set (isolated schema for multi-process E2E).
postgres_test_url
Resolve a PostgreSQL URL for tests.