Skip to main content

ControllerSpec

Struct ControllerSpec 

Source
pub struct ControllerSpec {
    pub admission: AdmissionPolicy,
    pub task_spec: TaskSpec,
}
Expand description

Request to submit a task to the controller.

Combines a slot name, admission policy, and the actual task specification.

Fields§

§admission: AdmissionPolicy

Admission policy.

§task_spec: TaskSpec

Task specification to run.

Implementations§

Source§

impl ControllerSpec

Source

pub fn new(admission: AdmissionPolicy, task_spec: TaskSpec) -> Self

Creates a new controller submission specification.

§Parameters
  • admission: How to handle concurrent submissions
  • task_spec: The task to execute
Source

pub fn slot_name(&self) -> &str

Returns the slot name.

Source

pub fn queue(task_spec: TaskSpec) -> Self

Convenience: Queue admission.

Examples found in repository?
examples/controller.rs (line 65)
46async fn main() -> anyhow::Result<()> {
47    let sup = taskvisor::Supervisor::builder(taskvisor::SupervisorConfig::default())
48        .with_controller(taskvisor::ControllerConfig::default())
49        .build();
50
51    let runner = Arc::clone(&sup);
52    tokio::spawn(async move {
53        let _ = runner.run(vec![]).await;
54    });
55    sup.wait_ready().await;
56
57    // ============================================================
58    // Demo -> Queue: Tasks execute one after another
59    // ============================================================
60    println!("Demo 1: Queue Policy");
61    println!(" └► Submit 3 tasks with same name: they run sequentially");
62
63    for _ in 1..=3 {
64        let spec = make_spec("job-in-queue", 800);
65        sup.submit(taskvisor::ControllerSpec::queue(spec)).await?;
66    }
67
68    tokio::time::sleep(Duration::from_secs(4)).await;
69    println!();
70
71    // ============================================================
72    // Demo -> Replace: New task cancels running one
73    // ============================================================
74    println!("Demo 2: Replace Policy");
75    println!(" └► Submit task, wait 500ms, submit another: first gets cancelled");
76
77    let task_1 = make_spec("job-replace", 6000);
78    let task_2 = make_spec("job-replace", 500);
79
80    sup.submit(taskvisor::ControllerSpec::replace(task_1))
81        .await?;
82    tokio::time::sleep(Duration::from_secs(1)).await;
83    sup.submit(taskvisor::ControllerSpec::replace(task_2))
84        .await?;
85
86    tokio::time::sleep(Duration::from_secs(2)).await;
87    println!();
88
89    // ============================================================
90    // Demo -> DropIfRunning: Ignores(skip) new tasks while busy
91    // ============================================================
92    println!("Demo 3: DropIfRunning Policy");
93    println!(" └► Submit task & submit another while first is running: second is ignored");
94
95    let task_1 = make_spec("job-drop-if-running", 1000);
96    let task_2 = make_spec("job-drop-if-running", 10000);
97
98    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_1))
99        .await?;
100    tokio::time::sleep(Duration::from_millis(250)).await;
101    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_2))
102        .await?;
103
104    tokio::time::sleep(Duration::from_secs(2)).await;
105    println!();
106
107    println!("Done");
108    Ok(())
109}
Source

pub fn replace(task_spec: TaskSpec) -> Self

Examples found in repository?
examples/controller.rs (line 80)
46async fn main() -> anyhow::Result<()> {
47    let sup = taskvisor::Supervisor::builder(taskvisor::SupervisorConfig::default())
48        .with_controller(taskvisor::ControllerConfig::default())
49        .build();
50
51    let runner = Arc::clone(&sup);
52    tokio::spawn(async move {
53        let _ = runner.run(vec![]).await;
54    });
55    sup.wait_ready().await;
56
57    // ============================================================
58    // Demo -> Queue: Tasks execute one after another
59    // ============================================================
60    println!("Demo 1: Queue Policy");
61    println!(" └► Submit 3 tasks with same name: they run sequentially");
62
63    for _ in 1..=3 {
64        let spec = make_spec("job-in-queue", 800);
65        sup.submit(taskvisor::ControllerSpec::queue(spec)).await?;
66    }
67
68    tokio::time::sleep(Duration::from_secs(4)).await;
69    println!();
70
71    // ============================================================
72    // Demo -> Replace: New task cancels running one
73    // ============================================================
74    println!("Demo 2: Replace Policy");
75    println!(" └► Submit task, wait 500ms, submit another: first gets cancelled");
76
77    let task_1 = make_spec("job-replace", 6000);
78    let task_2 = make_spec("job-replace", 500);
79
80    sup.submit(taskvisor::ControllerSpec::replace(task_1))
81        .await?;
82    tokio::time::sleep(Duration::from_secs(1)).await;
83    sup.submit(taskvisor::ControllerSpec::replace(task_2))
84        .await?;
85
86    tokio::time::sleep(Duration::from_secs(2)).await;
87    println!();
88
89    // ============================================================
90    // Demo -> DropIfRunning: Ignores(skip) new tasks while busy
91    // ============================================================
92    println!("Demo 3: DropIfRunning Policy");
93    println!(" └► Submit task & submit another while first is running: second is ignored");
94
95    let task_1 = make_spec("job-drop-if-running", 1000);
96    let task_2 = make_spec("job-drop-if-running", 10000);
97
98    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_1))
99        .await?;
100    tokio::time::sleep(Duration::from_millis(250)).await;
101    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_2))
102        .await?;
103
104    tokio::time::sleep(Duration::from_secs(2)).await;
105    println!();
106
107    println!("Done");
108    Ok(())
109}
Source

pub fn drop_if_running(task_spec: TaskSpec) -> Self

Examples found in repository?
examples/controller.rs (line 98)
46async fn main() -> anyhow::Result<()> {
47    let sup = taskvisor::Supervisor::builder(taskvisor::SupervisorConfig::default())
48        .with_controller(taskvisor::ControllerConfig::default())
49        .build();
50
51    let runner = Arc::clone(&sup);
52    tokio::spawn(async move {
53        let _ = runner.run(vec![]).await;
54    });
55    sup.wait_ready().await;
56
57    // ============================================================
58    // Demo -> Queue: Tasks execute one after another
59    // ============================================================
60    println!("Demo 1: Queue Policy");
61    println!(" └► Submit 3 tasks with same name: they run sequentially");
62
63    for _ in 1..=3 {
64        let spec = make_spec("job-in-queue", 800);
65        sup.submit(taskvisor::ControllerSpec::queue(spec)).await?;
66    }
67
68    tokio::time::sleep(Duration::from_secs(4)).await;
69    println!();
70
71    // ============================================================
72    // Demo -> Replace: New task cancels running one
73    // ============================================================
74    println!("Demo 2: Replace Policy");
75    println!(" └► Submit task, wait 500ms, submit another: first gets cancelled");
76
77    let task_1 = make_spec("job-replace", 6000);
78    let task_2 = make_spec("job-replace", 500);
79
80    sup.submit(taskvisor::ControllerSpec::replace(task_1))
81        .await?;
82    tokio::time::sleep(Duration::from_secs(1)).await;
83    sup.submit(taskvisor::ControllerSpec::replace(task_2))
84        .await?;
85
86    tokio::time::sleep(Duration::from_secs(2)).await;
87    println!();
88
89    // ============================================================
90    // Demo -> DropIfRunning: Ignores(skip) new tasks while busy
91    // ============================================================
92    println!("Demo 3: DropIfRunning Policy");
93    println!(" └► Submit task & submit another while first is running: second is ignored");
94
95    let task_1 = make_spec("job-drop-if-running", 1000);
96    let task_2 = make_spec("job-drop-if-running", 10000);
97
98    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_1))
99        .await?;
100    tokio::time::sleep(Duration::from_millis(250)).await;
101    sup.submit(taskvisor::ControllerSpec::drop_if_running(task_2))
102        .await?;
103
104    tokio::time::sleep(Duration::from_secs(2)).await;
105    println!();
106
107    println!("Done");
108    Ok(())
109}

Trait Implementations§

Source§

impl Clone for ControllerSpec

Source§

fn clone(&self) -> ControllerSpec

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

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