footing 0.1.3

Feature-gated foundations for Rust backend services
Documentation
//! Small worker runtime primitives.
//!
//! Applications provide job acquisition and processing through [`Worker`].
//! Configuration, outbox processing, leasing, and loop orchestration live in
//! focused private modules and are re-exported as one feature-gated API.
//!
//! ```rust
//! use std::time::Duration;
//! use footing::worker::{BackoffConfig, RetryBackoff};
//!
//! let mut backoff = RetryBackoff::new(BackoffConfig::default());
//! assert_eq!(backoff.record_failure(), Duration::from_secs(1));
//! backoff.reset();
//! ```

use std::error::Error;

use async_trait::async_trait;

mod config;
mod lease;
mod outbox;
mod runner;

pub use config::{BackoffConfig, RetryBackoff, WorkerConfig, WorkerConfigError, WorkerLeaseConfig};
#[cfg(feature = "settings")]
pub use config::{BackoffSettings, WorkerLeaseSettings, WorkerSettings};
pub use lease::{
    LocalWorkerLeaseStore, WorkerLease, WorkerLeaseDecision, WorkerLeaseError, WorkerLeaseStore,
};
#[cfg(feature = "settings")]
pub use outbox::OutboxWorkerSettings;
pub use outbox::{
    BatchRunSummary, BatchWorker, BatchWorkerJob, OutboxClaim, OutboxFailureClass, OutboxHandler,
    OutboxItem, OutboxItemState, OutboxJob, OutboxRetryPolicy, OutboxStore, OutboxWorkerConfig,
};
pub use runner::{
    ShutdownToken, ShutdownTrigger, WorkerRunError, WorkerRunOptions, WorkerRunState,
    WorkerRunSummary, WorkerTick, WorkerTickOutcome, run_worker_until_shutdown,
    run_worker_until_shutdown_with_metrics, run_worker_until_shutdown_with_options,
    shutdown_channel,
};

/// Boxed worker errors used by the generic worker trait.
pub type BoxWorkerError = Box<dyn Error + Send + Sync + 'static>;

/// Maximum supported worker name length.
pub const MAX_WORKER_NAME_LENGTH: usize = 128;
/// Maximum supported worker lease owner length.
pub const MAX_WORKER_LEASE_OWNER_LENGTH: usize = 128;

/// One unit of repeatable background work.
#[async_trait]
pub trait Worker: Send + Sync + 'static {
    /// Human-readable worker name used in logs and metrics.
    fn name(&self) -> &str;

    /// Runs one worker tick.
    async fn run_once(&self) -> Result<WorkerTick, BoxWorkerError>;
}

#[cfg(test)]
use runner::ensure_worker_lease;
#[cfg(test)]
mod tests;