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: AdmissionPolicyAdmission policy.
task_spec: TaskSpecTask specification to run.
Implementations§
Source§impl ControllerSpec
impl ControllerSpec
Sourcepub fn new(admission: AdmissionPolicy, task_spec: TaskSpec) -> Self
pub fn new(admission: AdmissionPolicy, task_spec: TaskSpec) -> Self
Creates a new controller submission specification.
§Parameters
admission: How to handle concurrent submissionstask_spec: The task to execute
Sourcepub fn queue(task_spec: TaskSpec) -> Self
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}Sourcepub fn replace(task_spec: TaskSpec) -> Self
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}Sourcepub fn drop_if_running(task_spec: TaskSpec) -> Self
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
impl Clone for ControllerSpec
Source§fn clone(&self) -> ControllerSpec
fn clone(&self) -> ControllerSpec
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ControllerSpec
impl !RefUnwindSafe for ControllerSpec
impl Send for ControllerSpec
impl Sync for ControllerSpec
impl Unpin for ControllerSpec
impl UnsafeUnpin for ControllerSpec
impl !UnwindSafe for ControllerSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more