sidebyside-core 0.1.0

Core domain types for Sidebyside SDK
Documentation
//! Activity definition traits
//!
//! This module defines the traits for activity definitions.

use serde::{de::DeserializeOwned, Serialize};
use std::future::Future;
use std::pin::Pin;

use crate::error::CoreError;
use crate::ids::StepId;

/// A trait for defining activity types
///
/// Activities are the individual units of work that execute within a workflow.
/// They represent operations like API calls, database queries, or Claude decisions.
pub trait ActivityDefinition: Send + Sync {
    /// The input type for this activity
    type Input: Serialize + DeserializeOwned + Send + Sync;
    /// The output type for this activity
    type Output: Serialize + DeserializeOwned + Send + Sync;

    /// Get the activity type name
    fn activity_type() -> &'static str;

    /// Execute the activity with the given context and input
    fn execute(
        ctx: ActivityContext,
        input: Self::Input,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, CoreError>> + Send>>;
}

/// Context provided to activities during execution
#[derive(Debug, Clone)]
pub struct ActivityContext {
    /// The step ID this activity is executing for
    pub step_id: StepId,
    /// Current attempt number
    pub attempt: u32,
    /// Scheduled time of this activity
    pub scheduled_time: chrono::DateTime<chrono::Utc>,
}

impl ActivityContext {
    /// Create a new activity context
    #[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);
    }
}