Skip to main content

aion/engine/
seam_handle.rs

1//! `EngineHandle` seam implementation for [`Engine`]: workflow residency
2//! resolution and mailbox delivery, with the remaining seam operations
3//! routed through dedicated bridges rather than this handle.
4
5use aion_core::{Event, WorkflowId};
6
7use crate::engine_seam::{
8    EngineHandle, EngineSeamError, WorkflowMailboxMessage, WorkflowProcessHandle, WorkflowResidency,
9};
10
11use super::api::Engine;
12
13impl EngineHandle for Engine {
14    fn resolve_workflow(
15        &self,
16        workflow_id: &WorkflowId,
17    ) -> Result<WorkflowResidency, EngineSeamError> {
18        // aion#213: the workflow's ONE handle, never whichever one a map scan
19        // yielded first. `sole_handle` reports two as the invariant-3 breach it
20        // is; a resolver that picked one would answer a residency question with
21        // a coin toss, and route the caller's delivery to an arbitrary run.
22        let handle = self.registry().sole_handle(workflow_id).map_err(|error| {
23            EngineSeamError::Delivery {
24                reason: error.to_string(),
25            }
26        })?;
27        match handle {
28            Some(handle) if handle.residency() == crate::HandleResidency::Resident => Ok(
29                WorkflowResidency::Resident(WorkflowProcessHandle::new(handle.pid())),
30            ),
31            Some(_) => Ok(WorkflowResidency::NonResident),
32            None => Ok(WorkflowResidency::Unknown),
33        }
34    }
35
36    fn deliver_workflow_message(
37        &self,
38        process: WorkflowProcessHandle,
39        message: WorkflowMailboxMessage,
40    ) -> Result<(), EngineSeamError> {
41        match message {
42            WorkflowMailboxMessage::SignalReceived { .. } => self
43                .runtime()
44                .deliver_signal_received(process.pid())
45                .map_err(|error| EngineSeamError::Delivery {
46                    reason: error.to_string(),
47                }),
48            other => Err(EngineSeamError::Delivery {
49                reason: format!("unsupported workflow mailbox message: {other:?}"),
50            }),
51        }
52    }
53
54    fn spawn_child_workflow(
55        &self,
56        request: crate::engine_seam::ChildWorkflowSpawnRequest,
57    ) -> Result<crate::engine_seam::ChildWorkflowSpawnResult, EngineSeamError> {
58        let _ = request;
59        Err(EngineSeamError::ChildSpawn {
60            reason: "engine handle child spawning is not wired here".to_owned(),
61        })
62    }
63
64    fn terminate_linked_child_workflow(
65        &self,
66        parent_workflow_id: &WorkflowId,
67        child_process: WorkflowProcessHandle,
68        correlation: u64,
69    ) -> Result<(), EngineSeamError> {
70        let _ = (parent_workflow_id, child_process, correlation);
71        Err(EngineSeamError::ChildTermination {
72            reason: "engine handle child termination is not wired here".to_owned(),
73        })
74    }
75
76    fn terminate_linked_activity(
77        &self,
78        parent_workflow_id: &WorkflowId,
79        activity_process: crate::Pid,
80        correlation: u64,
81    ) -> Result<(), EngineSeamError> {
82        let _ = (parent_workflow_id, activity_process, correlation);
83        Err(EngineSeamError::ChildTermination {
84            reason: "engine handle activity termination is not wired here".to_owned(),
85        })
86    }
87
88    fn arm_timer(&self, entry: crate::engine_seam::TimerWheelEntry) -> Result<(), EngineSeamError> {
89        let _ = entry;
90        Err(EngineSeamError::TimerWheel {
91            reason: "engine handle timer arming is not wired here".to_owned(),
92        })
93    }
94
95    fn disarm_timer(
96        &self,
97        process: WorkflowProcessHandle,
98        timer_id: &aion_core::TimerId,
99    ) -> Result<(), EngineSeamError> {
100        let _ = (process, timer_id);
101        Err(EngineSeamError::TimerWheel {
102            reason: "engine handle timer disarming is not wired here".to_owned(),
103        })
104    }
105
106    fn record_workflow_event(
107        &self,
108        workflow_id: &WorkflowId,
109        event: Event,
110    ) -> Result<crate::engine_seam::RecordOutcome, EngineSeamError> {
111        let _ = (workflow_id, event);
112        Err(EngineSeamError::Recorder {
113            reason: "engine handle event recording is not wired here".to_owned(),
114        })
115    }
116
117    fn record_redelivered_timer_fire(
118        &self,
119        workflow_id: &WorkflowId,
120        timer_id: &aion_core::TimerId,
121    ) -> Result<crate::engine_seam::RedeliveredFire, EngineSeamError> {
122        let _ = (workflow_id, timer_id);
123        Err(EngineSeamError::Recorder {
124            reason: "engine handle timer redelivery is not wired here".to_owned(),
125        })
126    }
127}