pub struct CoordinatorService { /* private fields */ }Expand description
Job and run CRUD backed by SchedulerStore — no background loops.
Use this when the host (or Axum handlers) needs to upsert jobs, pause/resume, list runs,
or trigger Self::run_now without owning scheduler ticks. Obtained from
crate::Chronon::coordinator_service or constructed with Self::new for HTTP /
Mode 3 API hosts.
| Method | Role |
|---|---|
Self::upsert_job | Insert/update; computes partition hash and cron next_run_at |
Self::run_now | Enqueue an immediate run (required for ScheduleKind::Manual) |
Self::list_jobs / Self::list_runs | Admin / HTTP list |
For remote processes that cannot share the store, use crate::RemoteCoordinatorClient
against a host that mounts chronon_router (Mode 3).
§Examples
use std::sync::Arc;
use chronon_backend_mem::InMemorySchedulerStore;
use chronon_core::{Job, ScheduleKind, SchedulerStore};
use chronon_runtime::CoordinatorService;
let store = Arc::new(InMemorySchedulerStore::new());
let coordinator = CoordinatorService::new(store.clone());
let mut job = Job::new("manual-job", "noop");
job.schedule_kind = ScheduleKind::Manual;
coordinator.upsert_job(job.clone()).await?;
let run_id = coordinator.run_now(&job.job_id).await?;
let run = store.get_run(&run_id).await?.expect("queued");
assert_eq!(run.status, chronon_core::RunStatus::Queued);Implementations§
Source§impl CoordinatorService
impl CoordinatorService
Sourcepub fn new(store: Arc<dyn SchedulerStore>) -> Self
pub fn new(store: Arc<dyn SchedulerStore>) -> Self
Wraps an existing store; does not start background tasks.
Sourcepub fn store(&self) -> Arc<dyn SchedulerStore>
pub fn store(&self) -> Arc<dyn SchedulerStore>
Underlying store for advanced host queries.
Sourcepub async fn upsert_job(&self, job: Job) -> Result<()>
pub async fn upsert_job(&self, job: Job) -> Result<()>
Insert or update a job, computing partition hash and next cron fire time when needed.
Appends a JobRevision when current_revision changes.
§Examples
use std::sync::Arc;
use chronon_backend_mem::InMemorySchedulerStore;
use chronon_core::{Job, ScheduleKind};
use chronon_runtime::CoordinatorService;
let store = Arc::new(InMemorySchedulerStore::new());
let coordinator = CoordinatorService::new(store);
let mut job = Job::new("nightly", "noop");
job.schedule_kind = ScheduleKind::Manual;
coordinator.upsert_job(job).await?;
assert_eq!(coordinator.list_jobs().await?.len(), 1);End-to-end with a real script: cargo run -p uf-chronon --example script_macro --features mem
(stringly job) or script_handle_job (typed ScriptHandle defaults).
Sourcepub async fn get_job_by_name(&self, job_name: &str) -> Option<Job>
pub async fn get_job_by_name(&self, job_name: &str) -> Option<Job>
Load a job by human-readable job_name.
Sourcepub async fn pause_job(&self, job_id: &str) -> Result<()>
pub async fn pause_job(&self, job_id: &str) -> Result<()>
Disable scheduling for job_id without deleting the row.
Sourcepub async fn resume_job(&self, job_id: &str) -> Result<()>
pub async fn resume_job(&self, job_id: &str) -> Result<()>
Re-enable scheduling for job_id.
Sourcepub async fn list_runs(
&self,
job_id: Option<&str>,
status: Option<&str>,
offset: usize,
limit: usize,
) -> Result<Vec<Run>>
pub async fn list_runs( &self, job_id: Option<&str>, status: Option<&str>, offset: usize, limit: usize, ) -> Result<Vec<Run>>
Paginated run listing with optional job_id and status string filters.
Unrecognized status strings are ignored (no filter).
Sourcepub async fn list_revisions(&self, job_id: &str) -> Result<Vec<JobRevision>>
pub async fn list_revisions(&self, job_id: &str) -> Result<Vec<JobRevision>>
Revision history for job_id, oldest first per store ordering.
Sourcepub async fn run_now(&self, job_id: &str) -> Result<String>
pub async fn run_now(&self, job_id: &str) -> Result<String>
Enqueue an immediate run using the job’s stored params_json.
Returns the new run_id. Errors with ChrononError::JobNotFound when missing.
Manual jobs (ScheduleKind::Manual) are never due for the tick loop; use this
(or HTTP POST /jobs/run_now) to trigger them. Works for any schedule kind.
§Examples
use std::sync::Arc;
use chronon_backend_mem::InMemorySchedulerStore;
use chronon_core::{Job, ScheduleKind};
use chronon_runtime::CoordinatorService;
let coordinator = CoordinatorService::new(Arc::new(InMemorySchedulerStore::new()));
let mut job = Job::new("probe", "noop");
job.schedule_kind = ScheduleKind::Manual;
coordinator.upsert_job(job.clone()).await?;
let run_id = coordinator.run_now(&job.job_id).await?;
assert!(!run_id.is_empty());Runnable sample: cargo run -p uf-chronon --example run_now --features mem.