use chrono::Local;
use std::path::PathBuf;
use std::sync::Arc;
use wrkflw_executor::{JobStatus, StepStatus};
use wrkflw_logging::symbols;
use wrkflw_parser::workflow::WorkflowDefinition;
pub type ExecutionResultMsg = (usize, Result<(Vec<wrkflw_executor::JobResult>, ()), String>);
#[derive(Debug, Clone)]
pub enum TriggerMatchStatus {
Matched(String),
Skipped(String),
}
pub struct Workflow {
pub name: String,
pub path: PathBuf,
pub selected: bool,
pub status: WorkflowStatus,
pub execution_details: Option<WorkflowExecution>,
pub job_names: Vec<String>,
pub trigger_match: Option<TriggerMatchStatus>,
pub definition: Option<Arc<WorkflowDefinition>>,
}
pub struct QueuedExecution {
pub workflow_idx: usize,
pub target_job: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WorkflowStatus {
NotStarted,
Running,
Success,
Failed,
Skipped,
}
pub struct WorkflowExecution {
pub jobs: Vec<JobExecution>,
pub start_time: chrono::DateTime<Local>,
pub end_time: Option<chrono::DateTime<Local>>,
pub logs: Vec<String>,
pub progress: f64, }
pub struct JobExecution {
pub name: String,
pub status: JobStatus,
pub steps: Vec<StepExecution>,
pub logs: Vec<String>,
}
pub struct StepExecution {
pub name: String,
pub status: StepStatus,
pub output: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum StatusSeverity {
Success,
Info,
Warning,
#[default]
Error,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LogFilterLevel {
Info,
Warning,
Error,
Success,
Trigger,
All,
}
impl LogFilterLevel {
pub fn matches(&self, log: &str) -> bool {
match self {
LogFilterLevel::Info => {
log.contains(symbols::INFO) || (log.contains("INFO") && !log.contains("SUCCESS"))
}
LogFilterLevel::Warning => log.contains(symbols::WARNING) || log.contains("WARN"),
LogFilterLevel::Error => log.contains(symbols::FAILURE) || log.contains("ERROR"),
LogFilterLevel::Success => {
log.contains(symbols::SUCCESS) || log.contains("SUCCESS") || log.contains("success")
}
LogFilterLevel::Trigger => {
log.contains("Triggering") || log.contains("triggered") || log.contains("TRIG")
}
LogFilterLevel::All => true,
}
}
pub fn next(&self) -> Self {
match self {
LogFilterLevel::All => LogFilterLevel::Info,
LogFilterLevel::Info => LogFilterLevel::Warning,
LogFilterLevel::Warning => LogFilterLevel::Error,
LogFilterLevel::Error => LogFilterLevel::Success,
LogFilterLevel::Success => LogFilterLevel::Trigger,
LogFilterLevel::Trigger => LogFilterLevel::All,
}
}
pub fn as_str(&self) -> &str {
match self {
LogFilterLevel::All => "ALL",
LogFilterLevel::Info => "INFO",
LogFilterLevel::Warning => "WARNING",
LogFilterLevel::Error => "ERROR",
LogFilterLevel::Success => "SUCCESS",
LogFilterLevel::Trigger => "TRIGGER",
}
}
}