use crate::workflow;
use async_trait::async_trait;
use std::fmt::Debug;
use thiserror::Error;
use super::workflow::WorkflowNodeType;
pub mod types;
#[derive(Error, Debug)]
pub enum NodeError {
#[error("Failed - {0}")]
Failed(String),
#[error("Communications")]
Communication,
}
#[async_trait]
pub trait Node: Debug + Send + Sync {
fn kind(&self) -> WorkflowNodeType;
fn id(&self) -> &str;
fn position(&self) -> usize;
async fn execute(&self) -> Result<Vec<workflow::Parameter>, NodeError> {
Ok(vec![])
}
async fn create_msg(&self) -> workflow::Message {
match self.execute().await {
Ok(context) => workflow::Message {
pointer: self.position(),
status: workflow::NodeStatus::Success,
context,
},
Err(e) => workflow::Message {
pointer: self.position(),
status: workflow::NodeStatus::Failed,
context: vec![],
},
}
}
async fn run(&self) -> Result<(), NodeError>;
}