Scheduler

Struct Scheduler 

Source
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>
where T: From<i8> + Clone + Copy + Sub<Output = T> + Add<Output = T> + Display + Debug + PartialOrd + AddAssign,

Source

pub fn new() -> Self

Examples found in repository?
examples/read_from_file.rs (line 9)
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
Hide additional examples
examples/simple_example.rs (line 10)
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}
examples/simple_example_float.rs (line 10)
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}
Source

pub fn schedule(&mut self) -> Result<(), String>

Ignites all the calculations.

Examples found in repository?
examples/read_from_file.rs (line 21)
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
Hide additional examples
examples/simple_example.rs (line 31)
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}
examples/simple_example_float.rs (line 31)
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}
Source

pub fn calculate(&mut self) -> Result<(), String>

Recalculate all parameters without providing new tasks.

Source

pub fn add_task(&mut self, task: CustomTask<T>) -> Result<(), String>

Examples found in repository?
examples/simple_example.rs (lines 11-15)
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
Hide additional examples
examples/simple_example_float.rs (lines 11-15)
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}
Source

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?
examples/read_from_file.rs (line 17)
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}
Source

pub fn get_task_by_name(&self, task_name: &String) -> Option<&CustomTask<T>>

Gets a task by it’s name.

Source

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.

Source

pub fn get_task_dependencies( &self, task_ref: &CustomTask<T>, ) -> Vec<&CustomTask<T>>

Gets dependencies of a task.

Source

pub fn get_task_successors( &self, task_ref: &CustomTask<T>, ) -> Vec<&CustomTask<T>>

Gets successors of a task.

Source

pub fn get_startpoints(&self) -> Vec<&CustomTask<T>>

Get all the entry points of the graph.

Source

pub fn get_endpoints(&self) -> Vec<&CustomTask<T>>

Get all the end points of the graph.

Source

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.

Source

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.

Source

pub fn get_critical_paths(&self) -> Vec<Path<T>>

Source

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.

Trait Implementations§

Source§

impl<T> Debug for Scheduler<T>
where T: From<i8> + Clone + Copy + Sub<Output = T> + Add<Output = T> + Display + Debug + PartialOrd + AddAssign + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Scheduler<T>

§

impl<T> RefUnwindSafe for Scheduler<T>
where T: RefUnwindSafe,

§

impl<T> Send for Scheduler<T>
where T: Send,

§

impl<T> Sync for Scheduler<T>
where T: Sync,

§

impl<T> Unpin for Scheduler<T>
where T: Unpin,

§

impl<T> UnwindSafe for Scheduler<T>
where T: UnwindSafe,

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