pub struct ChrononBuilder { /* private fields */ }Expand description
Builds a crate::Chronon runtime with explicit adapter injection.
Hosts call fluent setters then Self::build. Missing store is the only hard requirement;
context factory, telemetry, and registry fall back to no-op defaults.
Choose topology with .embedded() / .coordinator_only() /
.worker() / .remote_coordinator() — see
DeploymentShape. Use .auto_registry() to pick up #[chronon::script]
handlers linked into this binary (required on Mode 2 workers).
§Examples
Mode 1 — embedded with an empty registry:
use std::sync::Arc;
use chronon_backend_mem::InMemorySchedulerStore;
use chronon_runtime::{ChrononBuilder, DeploymentShape};
let store = Arc::new(InMemorySchedulerStore::new());
let chronon = ChrononBuilder::new()
.scheduler_store(store)
.embedded()
.build()
.unwrap();
assert_eq!(chronon.deployment, DeploymentShape::Embedded);
assert_eq!(chronon.executor().script_count(), 0);Mode 2 worker shape (scripts must be registered on this binary):
use std::sync::Arc;
use chronon_backend_mem::InMemorySchedulerStore;
use chronon_runtime::{ChrononBuilder, DeploymentShape};
let chronon = ChrononBuilder::new()
.scheduler_store(Arc::new(InMemorySchedulerStore::new()))
.instance_id("worker-a")
.worker("general")
.build()
.unwrap();
assert!(matches!(chronon.deployment, DeploymentShape::Worker(_)));Implementations§
Source§impl ChrononBuilder
impl ChrononBuilder
Sourcepub fn scheduler_store(self, store: Arc<dyn SchedulerStore>) -> Self
pub fn scheduler_store(self, store: Arc<dyn SchedulerStore>) -> Self
Required unless Self::scheduler_store_from_global is used.
Sourcepub fn scheduler_store_from_global(self) -> Result<Self>
pub fn scheduler_store_from_global(self) -> Result<Self>
Installs the process-global default store (e.g. mem backend); errors if unset.
Sourcepub fn context_factory(self, factory: Arc<dyn ContextFactory>) -> Self
pub fn context_factory(self, factory: Arc<dyn ContextFactory>) -> Self
Factory used when executing scripts; defaults to NoOpContextFactory.
Sourcepub fn telemetry_sink(self, sink: Arc<dyn TelemetrySink>) -> Self
pub fn telemetry_sink(self, sink: Arc<dyn TelemetrySink>) -> Self
Metrics sink shared by scheduler and executor; defaults to NoOpSink.
Sourcepub fn script_registry(self, registry: Arc<ScriptRegistry>) -> Self
pub fn script_registry(self, registry: Arc<ScriptRegistry>) -> Self
Script registry for the executor; use Self::auto_registry to populate from inventory.
Sourcepub fn instance_id(self, id: impl Into<String>) -> Self
pub fn instance_id(self, id: impl Into<String>) -> Self
Stable id for scheduler leader election and worker rows; random UUID if omitted.
Sourcepub fn coordinator_only(self) -> Self
pub fn coordinator_only(self) -> Self
Coordinator-only: tick and partition assigner, no worker slots (Mode 2 coordinator).
Sourcepub fn worker(self, pool_id: impl Into<String>) -> Self
pub fn worker(self, pool_id: impl Into<String>) -> Self
Worker-only: claim and execute runs for pool_id (Mode 2 worker).
Sourcepub fn remote_coordinator(self, base_url: impl Into<String>) -> Self
pub fn remote_coordinator(self, base_url: impl Into<String>) -> Self
Remote client shape: no local loops; pair with crate::RemoteCoordinatorClient (Mode 3).
crate::Chronon::run returns an error for this shape — schedule via the HTTP client.
Sourcepub fn auto_registry(self) -> Self
pub fn auto_registry(self) -> Self
Populate registry from inventory (#[chronon::script] link-time registration).
In Mode 2, call this on worker binaries (that is where scripts execute).
Sourcepub fn tick_interval_ms(self, ms: u64) -> Self
pub fn tick_interval_ms(self, ms: u64) -> Self
Scheduler tick period in milliseconds; overrides CHRONON_TICK_INTERVAL_MS when set.
Sourcepub fn build(self) -> Result<Chronon>
pub fn build(self) -> Result<Chronon>
Assemble crate::Chronon; returns ChrononError::Internal if store was not configured.