pub struct Scheduler { /* private fields */ }Expand description
Host-side scheduler skeleton.
One per Uni instance. M11 cutover wires tokio::spawn driving and
persistence into uni_system.background_jobs. Currently the
scheduler is paused — registered jobs are stored but not executed.
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn add_job(&self, id: QName)
pub fn add_job(&self, id: QName)
Register a new job with the legacy Manual schedule.
Equivalent to add_scheduled_job(id, Schedule::Manual). The
job becomes eligible immediately and fires on the next tick
(no-op while paused).
Sourcepub fn add_scheduled_job(&self, id: QName, schedule: Schedule)
pub fn add_scheduled_job(&self, id: QName, schedule: Schedule)
Register a new job with an explicit schedule.
The job’s next_fire_at is computed from the schedule plus
the current SystemTime. The scheduler picks it up on the
first Self::tick / Self::tick_at whose now is at or
past next_fire_at (no-op while paused).
Sourcepub fn cancel(&self, id: &QName) -> bool
pub fn cancel(&self, id: &QName) -> bool
Cancel a scheduled job by id.
Returns true if the job was found and cancelled.
Sourcepub fn list(&self) -> Vec<SchedulerJobRecord>
pub fn list(&self) -> Vec<SchedulerJobRecord>
List all known jobs and their statuses (snapshot).
Sourcepub fn cancel_token_for(&self, id: &QName) -> Option<CancellationToken>
pub fn cancel_token_for(&self, id: &QName) -> Option<CancellationToken>
Look up the cancellation token associated with a registered job.
Returns None if no job matches id. The returned clone shares
state with the record’s token, so callers can both await
cancelled().await and observe the same cancel signal trip via
Self::cancel.
Used by the host driver to wrap each dispatched
spawn_blocking in a tokio::select! against cancelled().await,
so shutdown / explicit cancel propagates without waiting for the
job body to poll CancellationToken::is_cancelled.
Sourcepub fn tick(&self) -> Vec<QName>
pub fn tick(&self) -> Vec<QName>
Drive the scheduler with the current wall-clock time.
Equivalent to tick_at(SystemTime::now()). See Self::tick_at
for the full semantics.
Sourcepub fn tick_at(&self, now: SystemTime) -> Vec<QName>
pub fn tick_at(&self, now: SystemTime) -> Vec<QName>
Pop every pending job whose schedule has fired at or before
now, transition each to Running, and return their ids for
the caller to dispatch.
M11 substantive driver primitive. This is the synchronous,
runtime-free heart of the scheduler — the eventual Tokio
driver wraps a poll loop that calls tick_at(SystemTime::now()),
dispatches the returned jobs (e.g., via tokio::spawn invoking
each job’s BackgroundJobProvider::execute), and calls
Scheduler::mark_finished when each completes.
Schedule semantics (delegated to
crate::traits::background::Schedule::next_after):
- A job is “due” iff
status == Pending,next_fire_at.is_none()ornext_fire_at <= now, and the cancel token is not already triggered. Manualjobs havenext_fire_at = nowat registration and so are immediately due (matching legacytick()behavior).Once(at)jobs become due only whennow >= at.Periodic(every)jobs become dueeveryafter each fire.Cron(expr)jobs become due at the next cron instant computed via thecroncrate.
Honors pause: returns empty when Self::is_paused.
Honors cancellation: skips jobs whose cancel token is
already triggered (filtering them out of the return).
Sourcepub fn running_count(&self) -> usize
pub fn running_count(&self) -> usize
Number of jobs currently in Running state. Useful for
observability (e.g., a metrics gauge).
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of pending jobs ready for the next tick.
Sourcepub fn requeue_orphaned_runs(&self) -> usize
pub fn requeue_orphaned_runs(&self) -> usize
Reset every Running job back to Pending — used by the
driver to recover from a crash where jobs were started but not
finished. The host restores the scheduler state from
uni_system.background_jobs and calls this to make all
previously-Running jobs eligible for re-dispatch.
Sourcepub fn mark_started(&self, id: &QName)
pub fn mark_started(&self, id: &QName)
Mark a job as starting a new run.
Used by tests + the M11 cutover driver. Updates the record’s
status to Running and stamps last_started_at.
Sourcepub fn mark_finished(&self, id: &QName, success: bool)
pub fn mark_finished(&self, id: &QName, success: bool)
Mark a job’s run as finished (success or failure).
Recomputes next_fire_at from the job’s Schedule using
SystemTime::now() as the reference point. If the schedule has
another fire upcoming (Periodic, Cron, or a Once whose instant
is still in the future — which shouldn’t normally happen after
it has just fired), the job transitions back to Pending so
the next Self::tick_at can pick it up. Otherwise the job
stays in its terminal state (Idle on success,
FailedRetrying on failure).
Trait Implementations§
Source§impl SchedulerControl for Scheduler
impl SchedulerControl for Scheduler
Source§fn add_scheduled_job(&self, id: QName, schedule: Schedule)
fn add_scheduled_job(&self, id: QName, schedule: Schedule)
schedule.Source§fn list(&self) -> Vec<SchedulerJobRecord>
fn list(&self) -> Vec<SchedulerJobRecord>
Source§fn submit_cypher(&self, _cypher: &str) -> Result<(), FnError>
fn submit_cypher(&self, _cypher: &str) -> Result<(), FnError>
uni-db::scheduler::SchedulerHost override
dispatches through its crate::traits::background::JobHost. Read moreAuto Trait Implementations§
impl !Freeze for Scheduler
impl !RefUnwindSafe for Scheduler
impl Send for Scheduler
impl Sync for Scheduler
impl Unpin for Scheduler
impl UnsafeUnpin for Scheduler
impl UnwindSafe for Scheduler
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
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