chronon (public crate)
Public crate re-exporting split upstream crates.
Cargo features
# crates.io package is uf-chronon; Rust import stays `use chronon::…`.
= { = "uf-chronon", = "0.1", = false, = ["mem", "axum"] }
| Feature | Forwards to | Notes |
|---|---|---|
mem |
chronon-backend-mem |
In-process store for dev and tests |
sqlite |
chronon-backend-sqlite |
File or :memory: SQLite |
postgres |
chronon-backend-postgres |
Shared PostgreSQL pool |
redis |
chronon-backend-redis |
SQL durability + Redis claim queue — enable postgres too |
telemetry-console |
Documents console sink usage (always available via ConsoleSink) |
|
axum |
chronon-axum router and state types |
Prelude
use *;
Configuration
Settings merge in this order (explicit builder values win over environment defaults):
| Setting | Builder API | Environment variable | Default |
|---|---|---|---|
| Scheduler store | .scheduler_store() / .scheduler_store_from_global() |
— | required |
| Context factory | .context_factory() |
— | NoOpContextFactory |
| Telemetry | .telemetry_sink() |
— | NoOpSink |
| Script registry | .script_registry() / .auto_registry() |
— | empty or inventory |
| Tick interval | .tick_interval_ms() |
CHRONON_TICK_INTERVAL_MS |
250 ms |
| Instance id | .instance_id() |
— | random UUID |
| Partition count | — (env only) | CHRONON_NUM_PARTITIONS |
64 |
| Tick batch limit | — | CHRONON_TICK_BATCH_LIMIT |
500 |
| Worker pool | — | CHRONON_WORKER_POOL |
"general" |
| Worker concurrency | — | CHRONON_WORKER_CONCURRENCY |
4 |
Backend connection (not on ChrononBuilder)
| Backend | How to configure |
|---|---|
| PostgreSQL | Connection URL to PostgresSchedulerStore::connect or CHRONON_POSTGRES_URL / CHRONON_TEST_POSTGRES_URL for tests |
| SQLite | File path (SqliteSchedulerStore::new) or URL (connect, including :memory:) |
| Redis overlay | URL to RedisQueueLayer::connect; optional key_prefix (default chronon); CHRONON_REDIS_URL / CHRONON_TEST_REDIS_URL in tests |
Builder .tick_interval_ms() overrides CHRONON_TICK_INTERVAL_MS. Partition count and lease TTLs are read from the environment only — see chronon-scheduler rustdoc for the full env-var table.
How to run examples
Navigational index: examples/README.md (when-to-use ladder + success checks for every example).
Canonical teaching path (start here). Topology docs: Embedded / Coordinator–worker / Remote HTTP client.
1. Embedded — sqlite_boot (standalone)
One process, file-backed store. No external services.
# optional: CHRONON_SQLITE_PATH=:memory: or a custom file path
# default path: /tmp/chronon-example.db
Success: stderr prints Chronon booted with SQLite store (…).
2. Coordinator–worker (multi-process — run as a set)
Coordinator and workers share one store. They are not useful alone.
| Rule | Detail |
|---|---|
| Shared env | Same CHRONON_SQLITE_PATH or same Postgres/Redis URLs on every process |
| Start order | Coordinator first (init_partitions), then workers |
| Workers | Each needs a unique CHRONON_INSTANCE_ID; optional CHRONON_WORKER_POOL (default general) |
| Scripts | Execute on workers only; example daemons register daemon-noop |
Local SQLite (no Postgres/Redis) — 1 coordinator + 2 workers:
# Terminal 1 — coordinator
# Terminal 2 — worker A
CHRONON_INSTANCE_ID=worker-a
# Terminal 3 — worker B
CHRONON_INSTANCE_ID=worker-b
Production claim path (Postgres + Redis) — same pattern:
# Terminal 1 — coordinator
# Terminal 2 / 3 — workers (unique instance ids)
CHRONON_INSTANCE_ID=worker-a
CHRONON_INSTANCE_ID=worker-b
Stop with Ctrl-C on each process. Real apps link #[chronon::script] into worker binaries and use .auto_registry().
3. Remote HTTP client — remote_http_client (standalone)
App schedules via RemoteCoordinatorClient (no local Chronon loops). This demo spins a short-lived mem API host, then upserts + run_now.
Production: Chronon does not authenticate /api/chronon/*. Wrap with host auth — see axum_auth_wrap and repository SECURITY.md.
4. Combined production shape — authenticated_remote_postgres_redis (standalone)
Postgres + Redis storage, StaticTokenAdminAuth gating every
route, and RemoteCoordinatorClient against the mounted API — the three earlier pieces
composed into one auth-gated remote coordinator. Requires PostgreSQL and Redis:
Success: missing token denied, x-chronon-admin-token allowed. RemoteCoordinatorClient has no
header hook today, so the deny path uses the client as-is and the allow path attaches
x-chronon-admin-token directly (reqwest in the example, curl for manual checks):
Other examples
| Example | Topology | Features | Notes |
|---|---|---|---|
script_macro, script_handle_job, run_now, embedded_tick |
Embedded | mem |
API / scheduling demos |
store_router_boot |
Embedded | mem |
Global store router |
telemetry_console |
Embedded | mem,telemetry-console |
ConsoleSink telemetry via tracing |
domain_context_factory |
Embedded | mem |
Custom ContextFactory; fail-closed identity |
custom_store_stub |
Embedded | mem |
Decorator SchedulerStore sketch |
postgres_boot, postgres_redis_boot |
Embedded | postgres / postgres,redis |
Store wiring |
axum_host, axum_auth_wrap |
Embedded + HTTP | mem,axum |
Router / Bearer demo |
postgres_coordinator_daemon, postgres_worker_daemon |
Coordinator–worker | postgres |
Postgres-only split |
Documentation
API reference: cargo doc -p uf-chronon --all-features --open. See root README.md for architecture.