Skip to main content

aion_server/worker/
outbox_delivery.rs

1//! Server-side outbox completion delivery callback.
2//!
3//! Bridges an unmatched durable-outbox completion arriving at the worker sink
4//! ([`PendingActivities`](super::bridge::PendingActivities)) to the engine: it
5//! resolves the workflow to its live process through the engine's active
6//! registry and delivers the terminal into that workflow's mailbox, where the
7//! engine's `take_and_record` records it. Installed only when the outbox is
8//! enabled, so flag-off the unmatched branch stays a silent drop.
9
10use std::sync::Arc;
11
12use aion::Engine;
13use aion_core::{ActivityId, RunId, WorkflowId};
14
15use super::bridge::OutboxDeliveryCallback;
16use crate::error::ServerError;
17
18/// [`OutboxDeliveryCallback`] backed by the embedded engine.
19pub struct ServerOutboxDeliveryCallback {
20    engine: Arc<Engine>,
21}
22
23impl ServerOutboxDeliveryCallback {
24    /// Build a callback over the shared engine handle.
25    #[must_use]
26    pub fn new(engine: Arc<Engine>) -> Self {
27        Self { engine }
28    }
29}
30
31impl OutboxDeliveryCallback for ServerOutboxDeliveryCallback {
32    fn deliver_completion(
33        &self,
34        workflow_id: &WorkflowId,
35        activity_id: &ActivityId,
36        run_id: Option<&RunId>,
37        result: String,
38    ) -> Result<bool, ServerError> {
39        self.engine
40            .runtime()
41            .deliver_outbox_completion(
42                self.engine.registry(),
43                workflow_id,
44                activity_id,
45                run_id,
46                result,
47            )
48            .map_err(ServerError::from)
49    }
50
51    fn deliver_failure(
52        &self,
53        workflow_id: &WorkflowId,
54        activity_id: &ActivityId,
55        run_id: Option<&RunId>,
56        reason: String,
57    ) -> Result<bool, ServerError> {
58        self.engine
59            .runtime()
60            .deliver_outbox_failure(
61                self.engine.registry(),
62                workflow_id,
63                activity_id,
64                run_id,
65                reason,
66            )
67            .map_err(ServerError::from)
68    }
69}