Skip to main content

Core

Struct Core 

Source
pub struct Core<P> { /* private fields */ }
Expand description

The scheduling engine. See the crate docs.

Implementations§

Source§

impl<P> Core<P>

Source

pub fn new(cfg: CoreConfig) -> Self

Create an engine. Structural errors (no pools, duplicate names, min_workers > max_workers) panic; use CoreConfig::validate first to report them gracefully. Out-of-range numeric settings are clamped to safe values.

Source

pub fn set_emit_transitions(&mut self, on: bool)

Emit Action::Status for every transition, not only terminal ones.

Source

pub fn config(&self) -> &CoreConfig

The (sanitized) configuration the engine runs with.

Source

pub fn pool_id(&self, name: &str) -> Option<PoolId>

Id of the pool named name.

Source

pub fn pool_name(&self, pool: PoolId) -> &Arc<str> ⓘ

Name of pool. Panics if pool is not from this engine.

Source

pub fn pool_capacity(&self, pool: PoolId) -> u32

Current worker capacity of pool. Panics if pool is not from this engine.

Source

pub fn totals(&self) -> &Totals

Counters since start.

Source

pub fn poll_action(&mut self) -> Option<Action<P>>

Next action for the driver.

Source

pub fn drain_actions(&mut self, out: &mut Vec<Action<P>>)

Move all pending actions into out.

Source

pub fn has_actions(&self) -> bool

Whether actions are waiting to be polled.

Source

pub fn next_wakeup(&self) -> Option<Time>

Earliest time at which tick has work to do.

Source

pub fn tick(&mut self, now: Time)

Advance time: fire due timers and dispatch.

Source

pub fn submit( &mut self, now: Time, spec: TaskSpec<P>, ) -> Result<Submitted, SubmitError>

Submit one task.

Source

pub fn try_submit( &mut self, now: Time, spec: TaskSpec<P>, ) -> Result<Submitted, (SubmitError, TaskSpec<P>)>

Like Core::submit, but hands the spec back on rejection (e.g. to retry after SubmitError::Full).

Source

pub fn submit_batch( &mut self, now: Time, specs: Vec<TaskSpec<P>>, ) -> Result<Vec<Submitted>, (usize, SubmitError)>

Submit several tasks atomically. Dependencies may reference keys defined in the batch (in any order). Either all are admitted or none.

Source

pub fn complete(&mut self, now: Time, lease: LeaseId, outcome: Outcome) -> bool

Report the outcome of an attempt. Returns false for unknown or stale leases.

Source

pub fn heartbeat(&mut self, now: Time, lease: LeaseId) -> bool

Extend a lease (remote workers). Returns false if the lease is unknown.

Source

pub fn cancel(&mut self, now: Time, target: &TaskRef) -> bool

Cancel a task. Running attempts are aborted. Returns false if not live.

Source

pub fn set_capacity(&mut self, now: Time, pool: PoolId, capacity: u32)

Report the capacity actually available in a pool (its unlabeled workers).

Source

pub fn set_group_capacity( &mut self, now: Time, pool: PoolId, labels: &[(Arc<str>, Arc<str>)], capacity: u32, )

Report the capacity of the workers of pool that carry exactly labels. Tasks that require labels run only in groups whose labels include them; tasks without requirements run in any group, preferring the least specialized. The pool’s capacity is the sum over its groups.

Source

pub fn status(&self, target: &TaskRef) -> Option<TaskStatus>

Current status of a task (live or retained).

Source

pub fn resolve(&self, target: &TaskRef) -> Option<TaskId>

Id of a live or retained task by id or key.

Source

pub fn live_tasks(&self) -> usize

Number of live (non-terminal) tasks.

Source

pub fn list_tasks<S: AsRef<str>>( &self, pools: &[S], statuses: &[TaskStatus], after: Option<TaskId>, limit: usize, ) -> Vec<TaskSummary>

Live tasks in id order: those in one of pools (any pool if empty) with one of statuses (any if empty), with ids above after, at most limit. Unknown pools match nothing.

Source

pub fn add_recurring( &mut self, now: Time, spec: RecurringSpec<P>, ) -> Result<(), String>

Add or replace a recurring (cron) schedule.

Source

pub fn remove_recurring(&mut self, now: Time, name: &str) -> bool

Remove a recurring schedule. An occurrence already materialized still runs.

Source

pub fn recurring_names(&self) -> Vec<Arc<str>>

Names of all recurring schedules.

Source

pub fn list_recurring(&self) -> Vec<RecurringInfo>

All recurring schedules, by name.

Source

pub fn recover(&mut self, now: Time, rec: Recovered<P>)

Restore state from durable storage. Call once, before any submission.

Source

pub fn snapshot(&mut self, now: Time) -> Snapshot

Advance to now (firing due timers) and return current state and metrics.

Auto Trait Implementations§

§

impl<P> Freeze for Core<P>
where Vec<Slot<P>>: Freeze, BTreeMap<Arc<str>, Recurring<P>>: Freeze, VecDeque<Action<P>>: Freeze,

§

impl<P> RefUnwindSafe for Core<P>
where Vec<Slot<P>>: RefUnwindSafe, BTreeMap<Arc<str>, Recurring<P>>: RefUnwindSafe, VecDeque<Action<P>>: RefUnwindSafe,

§

impl<P> Send for Core<P>
where Vec<Slot<P>>: Send, BTreeMap<Arc<str>, Recurring<P>>: Send, VecDeque<Action<P>>: Send,

§

impl<P> Sync for Core<P>
where Vec<Slot<P>>: Sync, BTreeMap<Arc<str>, Recurring<P>>: Sync, VecDeque<Action<P>>: Sync,

§

impl<P> Unpin for Core<P>
where Vec<Slot<P>>: Unpin, BTreeMap<Arc<str>, Recurring<P>>: Unpin, VecDeque<Action<P>>: Unpin,

§

impl<P> UnsafeUnpin for Core<P>
where Vec<Slot<P>>: UnsafeUnpin, BTreeMap<Arc<str>, Recurring<P>>: UnsafeUnpin, VecDeque<Action<P>>: UnsafeUnpin,

§

impl<P> UnwindSafe for Core<P>
where Vec<Slot<P>>: UnwindSafe, BTreeMap<Arc<str>, Recurring<P>>: UnwindSafe, VecDeque<Action<P>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.