Skip to main content

actionqueue_runtime/
worker.rs

1//! Worker communication types for the async dispatch loop.
2//!
3//! Defines the request/result messages exchanged between the dispatch loop
4//! and spawned worker tasks via tokio channels.
5
6use actionqueue_core::budget::BudgetConsumption;
7use actionqueue_core::ids::{AttemptId, RunId, TaskId};
8#[cfg(feature = "budget")]
9use actionqueue_executor_local::handler::CancellationContext;
10use actionqueue_executor_local::types::ExecutorResponse;
11
12/// The result sent back from a worker task after attempt completion.
13#[derive(Debug)]
14pub(crate) struct WorkerResult {
15    /// The unique identifier for the run instance.
16    pub run_id: RunId,
17    /// The unique identifier for the attempt.
18    pub attempt_id: AttemptId,
19    /// The executor response classifying the attempt outcome.
20    pub response: ExecutorResponse,
21    /// Maximum attempts allowed for this run.
22    pub max_attempts: u32,
23    /// The attempt number that completed (1-indexed).
24    pub attempt_number: u32,
25    /// Resource consumption reported by the handler for this attempt.
26    ///
27    /// Populated by the executor for budget tracking. Processed by the budget integration
28    /// in the dispatch loop under the `budget` feature flag.
29    #[cfg_attr(not(feature = "budget"), allow(dead_code))]
30    pub consumption: Vec<BudgetConsumption>,
31}
32
33/// Tracks an in-flight run being executed by a worker.
34#[derive(Debug)]
35pub(crate) struct InFlightRun {
36    /// The run identifier.
37    pub run_id: RunId,
38    /// The attempt identifier for diagnostic/tracing use.
39    pub attempt_id: AttemptId,
40    /// The task identifier for concurrency key release.
41    pub task_id: TaskId,
42    /// Lease expiry timestamp.
43    pub lease_expiry: u64,
44    /// The attempt number (1-indexed) for diagnostic/tracing use.
45    pub attempt_number: u32,
46    /// Maximum attempts allowed for diagnostic/tracing use.
47    pub max_attempts: u32,
48    /// Cancellation context clone retained by the dispatch loop.
49    ///
50    /// Used to signal cooperative suspension (e.g. budget exhaustion)
51    /// to a running handler via [`CancellationContext::cancel()`].
52    #[cfg(feature = "budget")]
53    pub cancellation_context: Option<CancellationContext>,
54}