sidebyside_core/
workflow.rs1use serde::{de::DeserializeOwned, Serialize};
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::error::CoreError;
10use crate::ids::WorkflowId;
11
12pub trait WorkflowDefinition: Send + Sync {
17 type Input: Serialize + DeserializeOwned + Send + Sync;
19 type Output: Serialize + DeserializeOwned + Send + Sync;
21
22 fn workflow_type() -> &'static str;
24
25 fn run(
27 &self,
28 ctx: WorkflowContext,
29 input: Self::Input,
30 ) -> Pin<Box<dyn Future<Output = Result<Self::Output, CoreError>> + Send + '_>>;
31}
32
33#[derive(Debug, Clone)]
35pub struct WorkflowContext {
36 pub workflow_id: WorkflowId,
38 pub is_replaying: bool,
40 pub attempt: u32,
42}
43
44impl WorkflowContext {
45 #[must_use]
47 pub fn new(workflow_id: WorkflowId) -> Self {
48 Self {
49 workflow_id,
50 is_replaying: false,
51 attempt: 1,
52 }
53 }
54
55 #[must_use]
57 pub fn is_replaying(&self) -> bool {
58 self.is_replaying
59 }
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_workflow_context_creation() {
68 let ctx = WorkflowContext::new(WorkflowId::generate());
69 assert!(!ctx.is_replaying());
70 assert_eq!(ctx.attempt, 1);
71 }
72}