sidebyside_core/
activity.rs1use serde::{de::DeserializeOwned, Serialize};
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::error::CoreError;
10use crate::ids::StepId;
11
12pub trait ActivityDefinition: Send + Sync {
17 type Input: Serialize + DeserializeOwned + Send + Sync;
19 type Output: Serialize + DeserializeOwned + Send + Sync;
21
22 fn activity_type() -> &'static str;
24
25 fn execute(
27 ctx: ActivityContext,
28 input: Self::Input,
29 ) -> Pin<Box<dyn Future<Output = Result<Self::Output, CoreError>> + Send>>;
30}
31
32#[derive(Debug, Clone)]
34pub struct ActivityContext {
35 pub step_id: StepId,
37 pub attempt: u32,
39 pub scheduled_time: chrono::DateTime<chrono::Utc>,
41}
42
43impl ActivityContext {
44 #[must_use]
46 pub fn new(step_id: StepId) -> Self {
47 Self {
48 step_id,
49 attempt: 1,
50 scheduled_time: chrono::Utc::now(),
51 }
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_activity_context_creation() {
61 let ctx = ActivityContext::new(StepId::generate());
62 assert_eq!(ctx.attempt, 1);
63 }
64}