pub struct Scheduler<T>where
T: From<i8> + Clone + Copy + Sub<Output = T> + Add<Output = T> + Display + Debug + PartialOrd + AddAssign,{ /* private fields */ }
Expand description
The scheduler implements the basic functionality to calculate critical paths plus the number of maximum parallel jobs at a time.
Implementations§
Source§impl<T> Scheduler<T>
impl<T> Scheduler<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
8fn main() {
9 let mut scheduler = scheduler::Scheduler::new();
10 let args: Vec<String> = env::args().collect();
11 if args.len() < 2 {
12 eprintln!("Please provide an input file path!");
13 exit(1);
14 }
15 match input_parser::parse_input_file(&args[1]) {
16 Ok(task_list) => {
17 match scheduler.fill_tasklist(task_list) {
18 Ok(()) => {},
19 Err(e) => {eprintln!("Error: {}", e); exit(1);},
20 }
21 match scheduler.schedule() {
22 Ok(()) => {},
23 Err(e) => {eprintln!("Error: {}", e); exit(1);},
24 }
25 },
26 Err(e) => {eprintln!("Error: {}", e); exit(1);},
27 }
28
29}
More examples
9fn main() {
10 let mut scheduler = Scheduler::<i32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
9fn main() {
10 let mut scheduler = Scheduler::<f32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1.52
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3.25
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2.0
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1.25
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
Sourcepub fn schedule(&mut self) -> Result<(), String>
pub fn schedule(&mut self) -> Result<(), String>
Ignites all the calculations.
Examples found in repository?
8fn main() {
9 let mut scheduler = scheduler::Scheduler::new();
10 let args: Vec<String> = env::args().collect();
11 if args.len() < 2 {
12 eprintln!("Please provide an input file path!");
13 exit(1);
14 }
15 match input_parser::parse_input_file(&args[1]) {
16 Ok(task_list) => {
17 match scheduler.fill_tasklist(task_list) {
18 Ok(()) => {},
19 Err(e) => {eprintln!("Error: {}", e); exit(1);},
20 }
21 match scheduler.schedule() {
22 Ok(()) => {},
23 Err(e) => {eprintln!("Error: {}", e); exit(1);},
24 }
25 },
26 Err(e) => {eprintln!("Error: {}", e); exit(1);},
27 }
28
29}
More examples
9fn main() {
10 let mut scheduler = Scheduler::<i32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
9fn main() {
10 let mut scheduler = Scheduler::<f32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1.52
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3.25
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2.0
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1.25
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
Sourcepub fn calculate(&mut self) -> Result<(), String>
pub fn calculate(&mut self) -> Result<(), String>
Recalculate all parameters without providing new tasks.
Sourcepub fn add_task(&mut self, task: CustomTask<T>) -> Result<(), String>
pub fn add_task(&mut self, task: CustomTask<T>) -> Result<(), String>
Examples found in repository?
9fn main() {
10 let mut scheduler = Scheduler::<i32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
More examples
9fn main() {
10 let mut scheduler = Scheduler::<f32>::new();
11 scheduler.add_task(CustomTask::new(
12 "Task_A".to_string()
13 , 1.52
14 , vec!{}
15 ));
16 scheduler.add_task(CustomTask::new(
17 "Sidetask_B".to_string()
18 , 3.25
19 , vec!{"Task_A".to_string()}
20 ));
21 scheduler.add_task(CustomTask::new(
22 "Sidetask_C".to_string()
23 , 2.0
24 , vec!{"Task_B".to_string()}
25 ));
26 scheduler.add_task(CustomTask::new(
27 "Finish".to_string()
28 , 1.25
29 , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
30 ));
31 match scheduler.schedule() {
32 Ok(()) => {},
33 Err(e) => {eprintln!("Error: {}", e); exit(1);},
34 }
35
36}
Sourcepub fn fill_tasklist(
&mut self,
task_list: Vec<CustomTask<T>>,
) -> Result<(), String>
pub fn fill_tasklist( &mut self, task_list: Vec<CustomTask<T>>, ) -> Result<(), String>
Sets up a list of tasks, overwriting the already listed ones.
Examples found in repository?
8fn main() {
9 let mut scheduler = scheduler::Scheduler::new();
10 let args: Vec<String> = env::args().collect();
11 if args.len() < 2 {
12 eprintln!("Please provide an input file path!");
13 exit(1);
14 }
15 match input_parser::parse_input_file(&args[1]) {
16 Ok(task_list) => {
17 match scheduler.fill_tasklist(task_list) {
18 Ok(()) => {},
19 Err(e) => {eprintln!("Error: {}", e); exit(1);},
20 }
21 match scheduler.schedule() {
22 Ok(()) => {},
23 Err(e) => {eprintln!("Error: {}", e); exit(1);},
24 }
25 },
26 Err(e) => {eprintln!("Error: {}", e); exit(1);},
27 }
28
29}
Sourcepub fn get_task_by_name(&self, task_name: &String) -> Option<&CustomTask<T>>
pub fn get_task_by_name(&self, task_name: &String) -> Option<&CustomTask<T>>
Gets a task by it’s name.
Sourcepub fn get_mut_task_by_name(
&mut self,
task_name: &String,
) -> Option<&mut CustomTask<T>>
pub fn get_mut_task_by_name( &mut self, task_name: &String, ) -> Option<&mut CustomTask<T>>
This one makes the scheduler get the Edited state if the task is found.
Sourcepub fn get_task_dependencies(
&self,
task_ref: &CustomTask<T>,
) -> Vec<&CustomTask<T>>
pub fn get_task_dependencies( &self, task_ref: &CustomTask<T>, ) -> Vec<&CustomTask<T>>
Gets dependencies of a task.
Sourcepub fn get_task_successors(
&self,
task_ref: &CustomTask<T>,
) -> Vec<&CustomTask<T>>
pub fn get_task_successors( &self, task_ref: &CustomTask<T>, ) -> Vec<&CustomTask<T>>
Gets successors of a task.
Sourcepub fn get_startpoints(&self) -> Vec<&CustomTask<T>>
pub fn get_startpoints(&self) -> Vec<&CustomTask<T>>
Get all the entry points of the graph.
Sourcepub fn get_endpoints(&self) -> Vec<&CustomTask<T>>
pub fn get_endpoints(&self) -> Vec<&CustomTask<T>>
Get all the end points of the graph.
Sourcepub fn get_paths_from_task(
&self,
start_point: &CustomTask<T>,
level: u32,
) -> Vec<Path<T>>
pub fn get_paths_from_task( &self, start_point: &CustomTask<T>, level: u32, ) -> Vec<Path<T>>
Returns all paths that are able to trace from the given task.
Sourcepub fn get_all_paths(&self) -> Vec<Path<T>>
pub fn get_all_paths(&self) -> Vec<Path<T>>
Gets all the paths in the graph. Attention! Does not check the possible cycles in dependencies! TODO: make it parallel.
pub fn get_critical_paths(&self) -> Vec<Path<T>>
Sourcepub fn get_parallelism(&self) -> Result<u32, String>
pub fn get_parallelism(&self) -> Result<u32, String>
Calculates the maximum number of parallel jobs at a time. Scheduler has to be in ready state.