Skip to main content

RunLedger

Struct RunLedger 

Source
pub struct RunLedger { /* private fields */ }
Expand description

The run ledger, shared by the cron scheduler, the Drone handlers and the Schedule routes.

Implementations§

Source§

impl RunLedger

Source

pub fn event_input(&self, run_id: &str) -> Option<Value>

The input kept for run run_id (what the graph reads as {{trigger.*}}). It stays while the run lives, so a run that waited through a delay, its turn or a restart, and a retry of it, read the same event.

Source

pub fn admit_event( &self, job: &CronJob, event_id: &str, source: &str, input: &Value, ) -> Admission

Record the event event_id for job and decide whether its run starts. Taken is an event the job already heard of; Skipped is a fire that Pause all, the rate limit, overlap policy or a cap refused (it has its row). An event that starts no run stays heard but does not count toward the rate limit.

Source§

impl RunLedger

Source

pub fn install_jobs(&self, jobs: Arc<Store>)

Where jobs are, for the policy of other jobs’ runs.

Source

pub fn install_worker_stop(&self, stop: BlockHook)

How to stop a worker a spawn job started, once its run ended.

Source

pub fn admit_cron( &self, job: &CronJob, trigger: &str, scheduled_for_ms: Option<i64>, triggered_by: &str, ) -> Admission

Insert the row of a cron fire and decide whether it starts (see the module doc). A scheduled slot that policy skips is a collapsed skipped (overlap) row; Run now is refused.

Source

pub fn stop_run( &self, run: &JobRun, infra_status: &str, why: &str, summary: &str, ) -> bool

Close a running run that was stopped on purpose, and interrupt its turn. false when it had ended already. A run another channel’s instance follows isn’t closed here: that instance is asked to stop it (remote.rs), so the row closes only once its agent’s turn is interrupted. false for it too.

Source

pub fn enforce_timeouts(&self) -> usize

Stop this channel’s runs that ran past their job’s timeout_minutes (infra timeout). Returns how many.

Source

pub fn close_if_past_timeout(&self, drone_run_id: &str) -> bool

A Drone run a restart left open, that a job started and whose job’s timeout_minutes ran out while AgentMux was down: close it as timed out (the way the timeout pass does) and say so, so it is not taken up again and able to act before the first pass. false for a run with no such timeout, or one that has time left.

Source

pub fn start_waiting(&self) -> Vec<Started> ⓘ

Start the waiting runs that policy now lets start, oldest first, each against what is running after the ones before it. Runs of a job that is gone or paused end; a retry waits out its backoff first. The caller starts the returned runs.

Source

pub fn pending_may_start(&self, job: &CronJob, run_id: &str) -> bool

Whether a pending catch-up delivery of job may start now: the same answer a waiting run gets (overlap, group, the global limit). A job that would cancel its own running run does so here, as a new slot would.

Source

pub fn pending_delivery_done(&self, run_id: &str)

The delivery of a pending fire ended (it started, or stays pending to be retried): its place is the ledger’s again.

Source

pub fn task_filed(&self, run_id: &str, job_name: &str, work_id: &str, num: i64)

A task run filed its task: the run is done, outcome ok, linked to the task (links.kanban_task, with its queue id).

Source§

impl RunLedger

Source

pub fn ingest_cloud_event( &self, envelope: &SignedJobEvent, reporters: &Reporters, jobs: &dyn CloudJobs, now_ms: i64, ) -> Result<Applied, Dropped>

Write one cloud event into the ledger, if it is genuine: its key pinned, its signature good, its job approved with that key, and not seen before. A refused event is counted (drops) and logged, not shown as a run.

Source§

impl RunLedger

Source

pub fn follow_forwarded( &self, run_id: &str, block_id: &str, delivery_started_ms: i64, ) -> bool

A delivery this instance just placed in block_id was forwarded here with request_id run_id. When that names a cron run another channel fired and nobody follows yet, take the follow-up: mark it running with this pane’s account, note this channel in its links and follow its turn here, from delivery_started_ms, taken before the injection: a turn the delivery started, even one already over, is this run’s whole turn, as on the local path (record_delivery). Called before the delivery’s answer goes back, so the firing instance sees the run is followed. Never inserts a row, so the slot lease stays the firing scheduler’s.

Source

pub fn check_remote(&self, run_id: &str, armed_at_ms: i64, now: i64) -> bool

Judge the watched cross-channel run run_id at now and write a close it calls for. true when it needs no more watching.

Source

pub fn install_remote_stop(&self, hook: RemoteStopHook)

How to ask another channel’s instance to stop a run it follows.

Source

pub fn remote_stop_done(&self, run_id: &str)

The follower stopped the run: its row is closed. This instance’s Jobs tab and a run waiting on this one’s place move on.

Source

pub fn remote_stop_failed(&self, run_id: &str, error: &str)

The ask couldn’t be delivered: say why in the run’s links, where the operator and the next pass see it. The row stays open.

Source

pub fn stop_followed_here( &self, run_id: &str, block_id: &str, from_channel: &str, ) -> Result<bool, String>

The following side of Self::request_remote_stop: close the run this instance follows, as a local stop does, and interrupt its pane’s turn, when from_channel fired the run and asked, in the run’s row, for this stop. The status, reason and summary are the row’s, not the request’s. Ok(false) when it had ended already; an error when the run is not one this process follows in block_id, was fired by another channel than from_channel, or carries no stop of that channel’s.

Source§

impl RunLedger

Source

pub fn install_caps(&self, limits: LimitsSource, target: TargetOf)

Weigh runs against Settings’ caps from now on, finding each run’s account and provider with target. Once. Without it the defaults apply and only a job’s own spend is weighed.

Source

pub fn limits(&self) -> Limits

Source

pub fn run_cap_usd(&self, job: &CronJob) -> f64

The most one run of job may spend.

Source

pub fn over_cap_today(&self, job: &CronJob) -> Option<&'static str>

The cap job is over today, for the Jobs tab (“over cap today”): its own daily cap or messages a day as of now, or an account cap that skipped one of its runs today.

Source§

impl RunLedger

Source

pub fn watch_cloud(&self, jobs: &[WatchedJob], now_ms: i64) -> Watched

One pass of the watchdog over jobs at now_ms. Blocking. A job that gave up a slot or a run is told to the Jobs tab and the incident keeper. Running it again changes nothing.

Source§

impl RunLedger

Source

pub fn watch_local( &self, watch: &mut LocalWatch, jobs: &[CronJob], now_ms: i64, ) -> usize

One pass over the enabled local jobs jobs at now_ms: a missed row (not_started) for each slot past its grace with no row of any kind. Returns how many it wrote. Blocking; running it again changes nothing.

Source§

impl RunLedger

Source

pub fn new( store: Arc<Store>, mstore: Option<Arc<Store>>, broker: Arc<Broker>, ) -> Arc<Self> ⓘ

A ledger over store (the work store), following turns on broker. Needs a tokio runtime (the follower’s task).

Source

pub fn new_in( store: Arc<Store>, mstore: Option<Arc<Store>>, broker: Arc<Broker>, channel: &str, ) -> Arc<Self> ⓘ

Self::new as the instance of channel: tests run two channels’ ledgers in one process.

Source

pub fn store(&self) -> &Arc<Store> ⓘ

Source

pub fn install_incidents(&self, jobs: Option<Arc<Store>>)

Open an incident when a job fails, from now on (§3.4). jobs is where cron jobs are, for a job’s owner.

Source

pub fn changed(&self, job_id: &str)

Tell the Jobs tab job job_id’s runs changed (JobsChanged); "" for a change to every job. A job’s change is also looked at for an incident.

Source

pub fn paused_all(&self) -> Option<JobFlag>

Pause all, when the operator has it on: since when, and by whom.

Source

pub fn set_paused_all(&self, on: bool, by: &str) -> Result<(), StoreError>

Turn Pause all on or off. The caller has checked that the operator asked: agents can’t (§7).

Source

pub fn record_skip_slot(&self, job: &CronJob, slot_ms: i64, why: &str)

A slot of job that didn’t fire because the job, or every job, was paused (reason): counted into the job’s newest row when that is the same skip, else a new skipped row; either way the slot keeps its own leased row, so no scheduler fires it later (§3.1, §3.3).

Source

pub fn begin_cron( &self, job: &CronJob, trigger: &str, scheduled_for_ms: Option<i64>, triggered_by: &str, ) -> Begin

Insert the scheduled row of a cron fire before firing it. For a slot, that insert is the lease (§3.1): a second scheduler sharing the job finds the slot taken.

Source

pub fn record_delivery( &self, run_id: &str, job: &CronJob, outcome: &FireOutcome, scheduled: bool, delivery_started_ms: i64, )

Record what a cron fire’s delivery decided for run run_id of job. delivery_started_ms is when the delivery began: delivery can wait for the turn it starts, so that turn may begin, or even end, before the answer. A scheduled fire also ends the job’s older pending fire: it is superseded when this one is pending in its place, else expired (its next fire time came).

Source

pub fn record_pending_delivery( &self, run: &JobRun, outcome: &FireOutcome, delivery_started_ms: i64, )

A pending fire was delivered, or failed for good, when its agent came back (CronScheduler::deliver_pending, which expires it first once its next fire time has passed). Still missing, or a failure the held-jekt replay also retries (the agent still starting, a rate limit, a full queue, not signed in yet), keeps it pending for the next wake or sweep. delivery_started_ms as for Self::record_delivery.

Source

pub fn expire_pending(&self, run_id: &str)

End a pending fire whose next fire time passed, or whose job is gone.

Source

pub fn waiting_here(&self) -> Vec<JobRun>

This channel’s pending fires still waiting for their agent.

Source

pub fn record_missed_while_off( &self, job: &CronJob, first_slot_ms: i64, count: i64, )

Write the collapsed skip for slots missed while AgentMux was off (app_not_running, §3.2): count slots from first_slot_ms.

Source

pub fn turn_finished( &self, run_id: &str, infra_status: &str, cost: Option<RunCost>, summary: &str, )

The followed turn ended (or never showed up).

Source

pub fn drone_started( &self, drone_run_id: &str, drone_id: &str, drone_name: &str, started_at_ms: i64, trigger: &Value, ) -> Option<String>

A Drone run started: its manual row, running, linked to the run.

Source

pub fn drone_started_by( &self, drone_run_id: &str, drone_id: &str, drone_name: &str, started_at_ms: i64, trigger: &Value, triggered_by: &str, ) -> Option<String>

Self::drone_started for a run somebody other than the operator started: triggered_by is the agent’s id (an agent that fires a drone with Drone is recorded as itself).

Source

pub fn drone_attached( &self, run_id: &str, drone_run_id: &str, trigger: &Value, now: i64, )

A job’s drone action started Drone run drone_run_id: the job’s own row (made when the fire began) runs from now and links to it, and drone_finished closes it. No transcript: the run is the Drone’s.

Source

pub fn drone_finished( &self, run_id: &str, ok: bool, block_states: &HashMap<String, BlockState>, error: &str, )

A Drone run ended: ok and the summed cost of its Agent blocks, or error with its message.

Source

pub fn drone_stopped( &self, run_id: &str, block_states: &HashMap<String, BlockState>, reason: &str, )

A Drone run was cancelled: its row closes interrupted with the reason, unless whoever stopped it (a timeout, cancel_other) closed it already.

Source

pub fn recover_after_restart(&self) -> usize

After a restart: close what this channel left open (§3.2). Cron runs still scheduled or running, and Drone runs still running, were interrupted, in the ledger and in db_drone_runs; so were the runs it followed for another channel (#1988). A run another channel follows goes on there, and is watched again from here. Pending fires stay: they wait for their agent across a restart. Call before the scheduler starts.

Source

pub fn open_run_of_drone(&self, drone_run_id: &str) -> Option<String>

The open ledger row of Drone run drone_run_id, written by this channel: the one a run taken up again after a restart goes on under.

Source

pub fn recover_after_restart_except(&self, resuming: &HashSet<String>) -> usize

recover_after_restart, except that the Drone runs in resuming (by Drone run id) are being taken up again from their checkpoints: their rows stay open, in the ledger and in db_drone_runs, and they finish as any run does.

Auto Trait Implementations§

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more