use serde::{de::DeserializeOwned, Serialize};
use std::future::Future;
use std::pin::Pin;
use crate::error::CoreError;
use crate::ids::StepId;
pub trait ActivityDefinition: Send + Sync {
type Input: Serialize + DeserializeOwned + Send + Sync;
type Output: Serialize + DeserializeOwned + Send + Sync;
fn activity_type() -> &'static str;
fn execute(
ctx: ActivityContext,
input: Self::Input,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, CoreError>> + Send>>;
}
#[derive(Debug, Clone)]
pub struct ActivityContext {
pub step_id: StepId,
pub attempt: u32,
pub scheduled_time: chrono::DateTime<chrono::Utc>,
}
impl ActivityContext {
#[must_use]
pub fn new(step_id: StepId) -> Self {
Self {
step_id,
attempt: 1,
scheduled_time: chrono::Utc::now(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_activity_context_creation() {
let ctx = ActivityContext::new(StepId::generate());
assert_eq!(ctx.attempt, 1);
}
}