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
sourceimpl Runtime
impl Runtime
sourcepub fn log_monitor_map(self, p: HashMap<String, LogMonitor>) -> Self
pub fn log_monitor_map(self, p: HashMap<String, LogMonitor>) -> Self
Builds Runtime
with the specified log monitors.
sourcepub fn process_map(self, p: HashMap<String, Process>) -> Self
pub fn process_map(self, p: HashMap<String, Process>) -> Self
Builds Runtime
with the specified processes.
sourcepub fn bin_command(self, c: BinCommand) -> Self
pub fn bin_command(self, c: BinCommand) -> Self
Builds Runtime
with the specified binary command.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnwindSafe for Runtime
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> CloneAny for T where
T: Any + Clone,
impl<T> CloneAny for T where
T: Any + Clone,
fn clone_any(&self) -> Box<dyn CloneAny + 'static, Global>
fn clone_any_send(&self) -> Box<dyn CloneAny + Send + 'static, Global> where
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync + 'static, Global> where
T: Sync,
fn clone_any_send_sync(
&self
) -> Box<dyn CloneAny + Sync + Send + 'static, Global> where
T: Send + Sync,
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more