Skip to main content

Scheduler

Struct Scheduler 

Source
struct Scheduler<'a> {
Show 36 fields run_id: &'a str, plan: Plan, node_of: HashMap<&'a str, &'a FlowNode>, incoming: HashMap<&'a str, Vec<&'a FlowEdge>>, outgoing: HashMap<&'a str, Vec<&'a FlowEdge>>, decided: HashMap<&'a str, bool>, finished: HashSet<&'a str>, failed: HashSet<&'a str>, ready: VecDeque<(&'a str, bool)>, queued: HashSet<&'a str>, held: Vec<&'a FlowEdge>, rounds: HashMap<&'a str, u32>, loop_started: HashMap<String, Instant>, spent: f64, spent_by: HashMap<&'a str, f64>, history: HashMap<&'a str, VecDeque<Value>>, scope: ExecutionScope, response: Option<Value>, run_cap_usd: Option<f64>, cancel: Cancel, cancelled: bool, in_flight: Vec<(&'a str, bool)>, running_ro: Vec<(&'a str, bool)>, waiting: Option<(&'a str, bool)>, deadlines: BTreeMap<String, i64>, resume_on: BTreeMap<String, String>, wait_timeouts: BTreeMap<String, i64>, chain: Vec<String>, lookup: Option<Arc<dyn DroneLookup>>, late_spend: Arc<LateSpend>, replay: Option<Arc<Replay>>, recorder: Option<(Recorder, GraphRef)>, started: Instant, elapsed_before_ms: u64, tx: &'a UnboundedSender<RunEvent>, states: &'a Arc<Mutex<HashMap<String, BlockState>>>,
}

Fields§

§run_id: &'a str§plan: Plan§node_of: HashMap<&'a str, &'a FlowNode>§incoming: HashMap<&'a str, Vec<&'a FlowEdge>>

The edges into a block, back-edges left out.

§outgoing: HashMap<&'a str, Vec<&'a FlowEdge>>§decided: HashMap<&'a str, bool>

Edges decided this pass of their loop: true when they carry the run on.

§finished: HashSet<&'a str>

Blocks that ran or were skipped this pass of their loop.

§failed: HashSet<&'a str>

The blocks that failed this pass of their loop and whose failure the graph handled.

§ready: VecDeque<(&'a str, bool)>§queued: HashSet<&'a str>§held: Vec<&'a FlowEdge>

Edges out of a loop that were not taken, decided when nothing can run.

§rounds: HashMap<&'a str, u32>

How many times each guard has sent the run round its loop.

§loop_started: HashMap<String, Instant>§spent: f64§spent_by: HashMap<&'a str, f64>§history: HashMap<&'a str, VecDeque<Value>>§scope: ExecutionScope§response: Option<Value>§run_cap_usd: Option<f64>§cancel: Cancel§cancelled: bool

Set when the run ended because cancel did, so that is not taken for a failure.

§in_flight: Vec<(&'a str, bool)>

The blocks that are running while they have effects, and whether each was forced: the ones a restart must not run again on its own.

§running_ro: Vec<(&'a str, bool)>

The blocks of the batch that is running and have no effects: a restart runs them again.

§waiting: Option<(&'a str, bool)>

The Wait block the run is stopped at, and whether it was forced, and what it waits for: a time, as milliseconds since 1970, or the key of an event.

§deadlines: BTreeMap<String, i64>§resume_on: BTreeMap<String, String>§wait_timeouts: BTreeMap<String, i64>

When the Wait block runs out of its own timeout_seconds.

§chain: Vec<String>

The drones above this one (a Drone block called it), and where to find a drone to call.

§lookup: Option<Arc<dyn DroneLookup>>§late_spend: Arc<LateSpend>

What callees spent that nobody was waiting for any more, by child run: counted at the next block.

§replay: Option<Arc<Replay>>§recorder: Option<(Recorder, GraphRef)>

Writes the run’s checkpoints, with the graph version they say the run is on.

§started: Instant§elapsed_before_ms: u64

How long the run had already run before this process took it up, when it is resumed.

§tx: &'a UnboundedSender<RunEvent>§states: &'a Arc<Mutex<HashMap<String, BlockState>>>

Implementations§

Source§

impl<'a> Scheduler<'a>

Source

pub(super) async fn settle_in_flight( &mut self, id: &'a str, forced: bool, ) -> Result<(), String>

Wait for the answer about the in-flight block id, then do it: the block is ready to run again, or it is taken as finished with the output given.

Source

async fn skip_in_flight( &mut self, id: &'a str, output: Value, ) -> Result<(), String>

The in-flight block is taken as finished with output, which came from outside the graph and so is tainted, and the run goes on from there.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) fn run_call<'s>( &'s mut self, node: &'a FlowNode, ) -> Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 's>>
where 'a: 's,

Call the drone node names and give what it came to. It is boxed, because a callee can call too: a future that runs a run that can run it cannot say it is Send without help.

Source

async fn call(&mut self, node: &'a FlowNode) -> Result<Value, String>

Source§

impl Scheduler<'_>

Source

pub(super) async fn settle_late_spend(&mut self)

Before more work starts: wait for the callees that were stopped when their call was given up on, and count what they spent, so the cap and the next callee’s allowance see it. The spend is also put on the calling block’s state, which is what the ledger sums.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) fn checkpoint(&mut self, after: Option<&str>) -> Result<(), String>

Keep the run as it stands as its next checkpoint, after the block that just finished (none for the first, before any block). A run that cannot keep a checkpoint goes on, and the next one is a diff from the last kept; a run that has used up its steps (§3.3: at most 1,000) ends, saying so.

Source

pub(super) fn checkpoint_required(&mut self, id: &str) -> Result<(), String>

The checkpoint a run keeps before it stops at id: without it a restart could not take the wait up again, so a run that cannot keep it ends.

Source

pub(super) fn effect_of_node(&self, node: &FlowNode, kind: BlockKind) -> Effect

What node does to the world. A block a replay stubs does nothing to it.

Source

pub(super) fn real_effect_of_node( &self, node: &FlowNode, kind: BlockKind, ) -> Effect

What node does to the world, which a for-each takes from its body.

Source

pub(super) fn mark_in_flight( &mut self, node: &'a FlowNode, forced: bool, ) -> Result<(), String>

Before a block with effects starts, keep a checkpoint that says it is running. A restart that finds it as the newest knows the block may have done its work already. When the run cannot keep it, the block does not start: it would be a step no restart could account for.

Source

pub(super) fn mark_batch_in_flight( &mut self, batch: &[(&'a str, bool)], ) -> Result<(), String>

mark_in_flight for a batch of blocks that start together: the ones with effects are listed as running in one checkpoint, kept before any starts, and the others are listed as ready until they finish.

Source

fn keep(&mut self, after: Option<&str>, required: bool) -> Result<(), String>

checkpoint, and with required a checkpoint that could not be kept ends the run.

Source

fn snapshot(&self, step: u32) -> Checkpoint

The run as it stands, as checkpoint step.

Source

pub(super) fn restore(&mut self, c: &Checkpoint) -> Result<(), String>

Set this scheduler (new, for the graph the checkpoint was written on) to where c left the run. A checkpoint that names a block or an edge the graph does not have was written on another graph, and is refused.

Source

pub(super) fn restore_state(&mut self, c: &Checkpoint) -> Result<(), String>

restore but for the run’s own place only: its checkpoints go on as they are, which a run that starts from c (a replay) does not have yet.

Source

fn legacy_failed( &self, c: &Checkpoint, finished: &HashSet<&'a str>, decided: &HashMap<&'a str, bool>, ) -> HashSet<&'a str>

The blocks that failed in this pass, for a checkpoint written before the set was kept. A block that finished with a handled failure said so as its output (failed: true and the error), but a block that failed in one pass of a loop and was skipped in the next keeps that output too. So the output counts only for a block that ran this pass: a root, or one an edge into it was taken for, or a Join that a branch (found the same way) failed into.

Source

pub(super) async fn show_restored(&self)

Show what the restored blocks did, as the run’s own block states, so what a person sees of a resumed run is not blank where blocks already ran.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) async fn run_foreach( &mut self, node: &'a FlowNode, ) -> Result<Value, String>

Source

fn item_limit( &self, cfg: &ForEachConfig, id: &str, (index, total): (usize, usize), (started, spent_before): (Instant, f64), ) -> Option<String>

Why the next item must not run, in plain words, or None.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) fn run_join(&self, node: &'a FlowNode) -> Result<Value, String>

Source

fn branches_of(&self, id: &str) -> Branches

How each branch into the join id ended, by the block it came from.

Source

pub(super) fn join_bits(&self, id: &str) -> (bool, bool)

What a join’s output is made of: tainted when a branch that arrived was, and when one failed (what it said is outside text), derived when one was.

Source

pub(super) fn join_has_failed_branch(&self, id: &str) -> bool

Whether id is a Join that a branch failed into: it runs then even when no branch arrived, so the failures are said and not hidden by a join that was skipped.

Source

pub(super) fn handles_failure(&self, id: &str) -> bool

Whether a failure of block id is the graph’s to handle: it has an error edge, or every way out of it is into a Join that leaves failed branches out.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) fn next_batch(&self) -> Vec<(&'a str, bool)>

The blocks at the front of the ready list that can run together, in order: none when the first cannot, one when only it can.

Source

pub(super) async fn step_batch( &mut self, batch: Vec<(&'a str, bool)>, ) -> Result<(), String>

Run batch, which next_batch gave, together. Every block’s outcome is taken up even when one fails; the first failure the graph does not handle is the run’s.

Source§

impl Scheduler<'_>

Source

pub(super) fn stub_of( &self, node: &FlowNode, kind: BlockKind, ) -> Option<Result<Value, String>>

What node says instead of running, when this run replays an earlier one and the block would do something to the world (it sends, files, starts, writes or calls a drone that may). A block that only reads runs as it always does, and so does every block of a run that was asked to do it for real.

Source

pub(super) fn keep_stub_bits(&mut self, id: &str)

A stubbed block’s output is as tainted as it was in the run replayed.

Source§

impl<'a> Scheduler<'a>

Source

pub(super) async fn run_wait( &mut self, node: &'a FlowNode, ) -> Result<Value, String>

Wait as node says, keeping the checkpoint first, and give what the wait came to: when it ended and whether it was late, or the event’s payload.

Source

pub(super) async fn run_approval( &mut self, node: &'a FlowNode, ) -> Result<Value, String>

An Approval block: wait for the person’s answer on a key that stays inside AgentMux, showing card. A yes is the block’s output; a no and silence fail it.

Source

async fn wait_for( &mut self, node: &'a FlowNode, wait: Wait, approval: Option<(Card, u64)>, ) -> Result<Value, String>

Source

pub(super) fn end_wait(&mut self, id: &str, late: bool)

The wait is over, however it ended: the run is no longer waiting.

Source§

impl<'a> Scheduler<'a>

Source

fn new( run_id: &'a str, graph: &'a DroneGraph, plan: Plan, scope: ExecutionScope, limits: Limits, tx: &'a UnboundedSender<RunEvent>, states: &'a Arc<Mutex<HashMap<String, BlockState>>>, ) -> Self

Source

fn seed_roots(&mut self)

The blocks nothing leads to are ready first.

Source

async fn drive(&mut self) -> Result<(), String>

Run blocks until none is ready and no edge is left to decide.

Source

fn enqueue(&mut self, id: &'a str, forced: bool)

Source

fn decide(&mut self, edge: &'a FlowEdge, carries: bool)

Record an edge’s outcome, and ready its target if that was the last one.

Source

fn leave(&mut self, edge: &'a FlowEdge, carries: bool)

An edge whose source has finished. A edge out of a loop that is not taken waits, because another iteration may still take it.

Source

async fn step(&mut self, id: &'a str, forced: bool) -> Result<(), String>

Source

fn finish_step( &mut self, node: &'a FlowNode, ran: Result<Value, String>, ) -> Result<(), String>

What a block came to is taken up: a failure its graph handles becomes its output, the block is finished and the run goes on from it.

Source

fn will_run(&self, id: &str, forced: bool) -> bool

Whether a ready block runs: it is a root, or was forced, or an edge into it was taken, or it is a Join that a branch failed into. Otherwise it is skipped.

Source

fn has_error_edge(&self, id: &str) -> bool

Source

fn cap_reached(&self, block_id: &str, reason: &str)

Source

async fn guarded( &mut self, node: &'a FlowNode, kind: BlockKind, ) -> Result<Value, String>

A block’s code, ended when the run is cancelled (an Agent block’s process goes with it) or the block passes its timeout.

Source

async fn attempt( &mut self, node: &'a FlowNode, kind: BlockKind, ) -> Result<Value, String>

One run of a block’s code, within its time limit.

Source

async fn dispatch( &mut self, node: &'a FlowNode, kind: BlockKind, ) -> Result<Value, String>

Hand a block to the code for its kind. A for-each runs its body block through run_block, so it is handled here, not in blocks.

Source

async fn run_block(&mut self, node: &'a FlowNode) -> Result<Value, String>

Run one block with its events and its recorded state.

Source

async fn begin_block(&mut self, node: &'a FlowNode) -> i64

A block starts: its event and its running state. Gives when it started, which the states it ends with carry too.

Source

async fn end_block( &mut self, node: &'a FlowNode, kind: BlockKind, result: Result<Value, String>, __arg4: (i64, f64), ) -> Result<Value, String>

A block ends with result: its output is kept, its cost counted, its event and its state.

Source

fn mark_bits(&mut self, node: &FlowNode, kind: BlockKind)

What a block’s output is made of, for the taint bits: an Agent’s answer, an API response and a message reply are outside text; a Condition’s result is a boolean made from what it read (derived when that was tainted); a Response is its template filled in. A Variables block sets its own.

Source

fn keep_history(&mut self, id: &'a str, output: &mut Value)

A block that runs again carries its earlier outputs, newest last, as {{block.history}}.

Source

fn route( &mut self, node: &'a FlowNode, output: &Value, failed: bool, ) -> Result<(), String>

Send the run along the edges out of a block that ran, and count a loop’s iteration when a guard takes it round.

Source

fn loop_cap(&self, id: &str, guard: &Guard) -> Option<String>

Why a loop may not go round again, in plain words, or None.

Source

fn go_round(&mut self, back: &'a FlowEdge)

A back-edge carried the run on: the loop’s blocks run again, from its head.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Scheduler<'a>

§

impl<'a> !UnwindSafe for Scheduler<'a>

§

impl<'a> Freeze for Scheduler<'a>

§

impl<'a> Send for Scheduler<'a>

§

impl<'a> Sync for Scheduler<'a>

§

impl<'a> Unpin for Scheduler<'a>

§

impl<'a> UnsafeUnpin for Scheduler<'a>

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