Struct Runtime

Source
pub struct Runtime {
    pub ctx: Ctx,
    pub jobs: Vec<Job>,
}
Expand description

Represents and contains a given runtime.

This object contains an ordered list of jobs, each job containing an ordered list of tasks, each task containing one or more concurrent processes. This object also contains a ctx object which contains the binary command and args for the current runtime as well as hashmap indexes for processes and log monitors which are copied to each child job, task, and process so that the runtime can instantiate new processes and log monitors on the fly.

A visual representation:

    Runtime
T       |
I       > [ Job1, Job2, ... ]
M             |
E             > [ Task1, Task2, ... ]
                    |
|                   > Process1 -> `echo foo`
|                   |     |
|                   |     > OnSucceed: Process2 -> `echo bar`
v                   |
                    > Process2 -> `echo bar`

    ...

    Runtime
        |
        > [ Job1, Job2, ... ]
              |
              > [ Task1, Task2, ... ]
                           |
                           > Process3 -> `echo baz`

    ...

    Runtime
        |
        > [ Job1, Job2, ... ]
                    |
                    > [ Task1, ... ]
                          |
                          > Process4 -> `echo qux`

Processes in a given task run concurrently.

Once all processes in the task have exited, including actions (onsucceed, onfail, and log monitor ontrigger actions spawned on their parent process threads), the task is complete and the next task in the job will execute.

Once all tasks in a given job have completed their execution, the runtime moves on to the next job in the queue. Once all jobs have completed their execution, the runtime is finished.

§Examples:

Basic usage:

use arpx::{Job, Process, Runtime, Task};
use std::collections::HashMap;

let processes = vec![
    Process::new("p_foo".to_string())
        .command("echo foo".to_string())
        .onsucceed(Some("p_baz".to_string())),
    Process::new("p_bar".to_string()).command("echo bar".to_string()),
];

let mut process_map = processes
    .clone()
    .into_iter()
    .map(|process| (process.name.clone(), process))
    .collect::<HashMap<String, Process>>();

process_map.insert(
    "p_baz".to_string(),
    Process::new("p_baz".to_string()).command("echo baz".to_string()),
);

let jobs = vec![Job::new(
    "my_job".to_string(),
    vec![Task::new(processes)],
)];

Runtime::new()
    .jobs(jobs)
    .process_map(process_map)
    .run();

// Output:
//
// [p_foo] "p_foo" (1) spawned
// [p_bar] "p_bar" (2) spawned
// [p_foo] foo
// [p_bar] bar
// [p_foo] "p_foo" (1) succeeded
// [p_bar] "p_bar" (2) succeeded
// [p_foo] "p_baz" (3) spawned
// [p_foo] baz
// [p_foo] "p_baz" (3) succeeded

Note that p_baz runs on the p_foo thread, since p_foo executes it onsucceed.

Fields§

§ctx: Ctx§jobs: Vec<Job>

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Self

Constructs a new, empty Runtime.

Source

pub fn jobs(self, j: Vec<Job>) -> Self

Builds Runtime with the specified jobs.

Source

pub fn log_monitor_map(self, p: HashMap<String, LogMonitor>) -> Self

Builds Runtime with the specified log monitors.

Source

pub fn process_map(self, p: HashMap<String, Process>) -> Self

Builds Runtime with the specified processes.

Source

pub fn bin_command(self, c: BinCommand) -> Self

Builds Runtime with the specified binary command.

Source

pub fn from_profile(path: &str, job_names: &[String]) -> Result<Self>

Constructs a new Runtime from a profile at the specified path, using the specified jobs.

Source

pub fn run(&self) -> Result<()>

Executes the runtime.

Trait Implementations§

Source§

impl Clone for Runtime

Source§

fn clone(&self) -> Runtime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Runtime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

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