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