|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{distro::OSConfig, error::AppResult};
|
|
|
|
use crate::{distro::OSConfig, error::AppResult};
|
|
|
|
|
|
|
|
|
|
|
|
use self::{base_task::BaseTask, custom_task::CustomTask, exec_builder::ExecBuilder};
|
|
|
|
use self::{base_task::BaseTask, custom_task::CustomTask, exec_builder::ExecBuilder};
|
|
|
@ -9,6 +11,9 @@ pub mod task_executor;
|
|
|
|
pub trait TaskTrait {
|
|
|
|
pub trait TaskTrait {
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>>;
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>>;
|
|
|
|
fn down(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>>;
|
|
|
|
fn down(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>>;
|
|
|
|
|
|
|
|
/// Used to decide the execution order
|
|
|
|
|
|
|
|
/// smaller values mean the task get's executed earlier
|
|
|
|
|
|
|
|
fn order(&self) -> usize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
@ -17,6 +22,35 @@ pub enum Task {
|
|
|
|
Custom(CustomTask),
|
|
|
|
Custom(CustomTask),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Task {
|
|
|
|
|
|
|
|
pub fn is_custom(&self) -> bool {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Task::Base(_) => false,
|
|
|
|
|
|
|
|
Task::Custom(_) => true,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn is_base(&self) -> bool {
|
|
|
|
|
|
|
|
!self.is_custom()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn compare(&self, other: &Self) -> Ordering {
|
|
|
|
|
|
|
|
if self.is_base() && other.is_custom() {
|
|
|
|
|
|
|
|
Ordering::Less
|
|
|
|
|
|
|
|
} else if self.is_custom() && other.is_base() {
|
|
|
|
|
|
|
|
Ordering::Greater
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if self.order() > other.order() {
|
|
|
|
|
|
|
|
Ordering::Greater
|
|
|
|
|
|
|
|
} else if self.order() < other.order() {
|
|
|
|
|
|
|
|
Ordering::Less
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Ordering::Equal
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TaskTrait for Task {
|
|
|
|
impl TaskTrait for Task {
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
|
fn up(&self, config: &OSConfig) -> AppResult<Option<ExecBuilder>> {
|
|
|
@ -33,4 +67,11 @@ impl TaskTrait for Task {
|
|
|
|
Task::Custom(c) => c.down(config),
|
|
|
|
Task::Custom(c) => c.down(config),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn order(&self) -> usize {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Task::Base(b) => b.order(),
|
|
|
|
|
|
|
|
Task::Custom(c) => c.order(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|