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>) -> CoordinatorService
pub fn new(store: Arc<dyn SchedulerStore>) -> CoordinatorService
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<(), ChrononError>
pub async fn upsert_job(&self, job: Job) -> Result<(), ChrononError>
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<(), ChrononError>
pub async fn pause_job(&self, job_id: &str) -> Result<(), ChrononError>
Disable scheduling for job_id without deleting the row.
Sourcepub async fn resume_job(&self, job_id: &str) -> Result<(), ChrononError>
pub async fn resume_job(&self, job_id: &str) -> Result<(), ChrononError>
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>, ChrononError>
pub async fn list_runs( &self, job_id: Option<&str>, status: Option<&str>, offset: usize, limit: usize, ) -> Result<Vec<Run>, ChrononError>
Paginated run listing with optional job_id and status string filters.
Unrecognized status strings are ignored (no filter).
Sourcepub async fn get_run(&self, run_id: &str) -> Result<Option<Run>, ChrononError>
pub async fn get_run(&self, run_id: &str) -> Result<Option<Run>, ChrononError>
Load a single run by run_id.
Sourcepub async fn list_revisions(
&self,
job_id: &str,
) -> Result<Vec<JobRevision>, ChrononError>
pub async fn list_revisions( &self, job_id: &str, ) -> Result<Vec<JobRevision>, ChrononError>
Revision history for job_id, oldest first per store ordering.
Sourcepub async fn run_now(&self, job_id: &str) -> Result<String, ChrononError>
pub async fn run_now(&self, job_id: &str) -> Result<String, ChrononError>
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.
Sourcepub async fn run_now_with_params(
&self,
job_id: &str,
params_override: Option<Value>,
) -> Result<String, ChrononError>
pub async fn run_now_with_params( &self, job_id: &str, params_override: Option<Value>, ) -> Result<String, ChrononError>
Enqueue an immediate run, optionally overriding params JSON.
Auto Trait Implementations§
impl !RefUnwindSafe for CoordinatorService
impl !UnwindSafe for CoordinatorService
impl Freeze for CoordinatorService
impl Send for CoordinatorService
impl Sync for CoordinatorService
impl Unpin for CoordinatorService
impl UnsafeUnpin for CoordinatorService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more