shepherd-rs 0.2.0

Shepherd is a resilient, non-blocking orchestrator that persistently transforms and delivers data—built for remote, compute-heavy workloads.
Documentation
//! # Consume Attempt Creator Trait
//!
//! This trait defines the behavior for creating consumption attempts in the
//! shepherd framework.
//!
//! ## Overview
//! - **ConsumeAttemptCreator**: Converts transformation attempts into
//!   consumption attempts.
//! - **Error Handling**: Provides mechanisms for handling errors during attempt
//!   creation.
//!
//! ## Example
//! ```rust
//! struct MyAttemptCreator;
//!
//! impl ConsumeAttemptCreator for MyAttemptCreator {
//!     // Implementation details...
//! }
//! ```

use std::error::Error;

use async_trait::async_trait;

use crate::config::Config;
use crate::consumer::ConsumeAttempt;
use crate::transform::TransformAttempt;

#[async_trait]
pub trait ConsumeAttemptCreator: Send {
    type Output: Send;
    type TransformAttempt: TransformAttempt<ReturnType = Self::Output>;
    type ConsumeAttempt: ConsumeAttempt<ConsumeVal = Self::Output>;
    type ConsumeAttemptCreationError: Send + Error;

    async fn new(config: std::sync::Arc<tokio::sync::Mutex<impl Config>>) -> Self
    where
        Self: Sized;

    /// Converts a `TransformAttempt` into a `ConsumeAttempt`.
    async fn create_new_attempt(
        &mut self,
        request: &Self::TransformAttempt,
    ) -> Result<Self::ConsumeAttempt, Self::ConsumeAttemptCreationError>;

    async fn create_new_reattempt(
        &mut self,
        attempt_id: <Self::ConsumeAttempt as ConsumeAttempt>::Identifier,
        error: <Self::ConsumeAttempt as ConsumeAttempt>::ReturnCtx,
    ) -> Result<Self::ConsumeAttempt, Self::ConsumeAttemptCreationError>;
}