mod context;
pub(crate) mod cron;
mod process;
mod queue;
mod runtime;
mod state;
mod tree;
#[cfg(test)]
mod tests;
use bitflags::bitflags;
use core::fmt;
use serde::{Deserialize, Serialize};
pub use crate::Result;
pub use context::Context;
pub use process::{Process, Task};
pub use runtime::Runtime;
pub use state::TaskState;
#[allow(unused_imports)]
pub use tree::{Node, NodeContent, NodeData, NodeKind, NodeTree};
pub enum NextAction {
Continue,
Parent,
Stop,
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Sign: u32 {
const ERROR = 0b0000_0000_0000_0001;
const CATCH = 0b0000_0000_0000_0010;
const TIMEOUT = 0b0000_0000_0000_0100;
const NO_EMIT = 0b0000_0000_0000_1000;
const IN_CHILDREN = 0b0000_0000_0001_0000;
const NO_AUTO_COMPLETE = 0b0000_0000_0010_0000;
const USES_COMPLETE = 0b0000_0000_0100_0000;
const NEXT_COMPLETE = 0b0000_0000_1000_0000;
}
}
pub trait ActTask: Clone + Send {
async fn init(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
async fn run(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
async fn next(&self, _ctx: &Context) -> Result<NextAction> {
Ok(NextAction::Parent)
}
async fn on_error(&self, ctx: &Context) -> Result<()> {
ctx.emit_error().await
}
async fn on_timeout(&self, _ctx: &Context) -> Result<()> {
Ok(())
}
}
impl fmt::Display for NextAction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
NextAction::Continue => write!(f, "continue"),
NextAction::Parent => write!(f, "parent"),
NextAction::Stop => write!(f, "stop"),
}
}
}
impl NextAction {
#[allow(dead_code)]
pub fn is_continue(&self) -> bool {
matches!(self, NextAction::Continue)
}
pub fn is_parent(&self) -> bool {
matches!(self, NextAction::Parent)
}
}