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        let handle = self
19            .registry()
20            .list()
21            .map_err(|error| EngineSeamError::Delivery {
22                reason: error.to_string(),
23            })?
24            .into_iter()
25            .find(|handle| handle.workflow_id() == workflow_id);
26        match handle {
27            Some(handle) if handle.residency() == crate::HandleResidency::Resident => Ok(
28                WorkflowResidency::Resident(WorkflowProcessHandle::new(handle.pid())),
29            ),
30            Some(_) => Ok(WorkflowResidency::NonResident),
31            None => Ok(WorkflowResidency::Unknown),
32        }
33    }
34
35    fn deliver_workflow_message(
36        &self,
37        process: WorkflowProcessHandle,
38        message: WorkflowMailboxMessage,
39    ) -> Result<(), EngineSeamError> {
40        match message {
41            WorkflowMailboxMessage::SignalReceived { .. } => self
42                .runtime()
43                .deliver_signal_received(process.pid())
44                .map_err(|error| EngineSeamError::Delivery {
45                    reason: error.to_string(),
46                }),
47            other => Err(EngineSeamError::Delivery {
48                reason: format!("unsupported workflow mailbox message: {other:?}"),
49            }),
50        }
51    }
52
53    fn spawn_child_workflow(
54        &self,
55        request: crate::engine_seam::ChildWorkflowSpawnRequest,
56    ) -> Result<crate::engine_seam::ChildWorkflowSpawnResult, EngineSeamError> {
57        let _ = request;
58        Err(EngineSeamError::ChildSpawn {
59            reason: "engine handle child spawning is not wired here".to_owned(),
60        })
61    }
62
63    fn terminate_linked_child_workflow(
64        &self,
65        parent_workflow_id: &WorkflowId,
66        child_process: WorkflowProcessHandle,
67        correlation: u64,
68    ) -> Result<(), EngineSeamError> {
69        let _ = (parent_workflow_id, child_process, correlation);
70        Err(EngineSeamError::ChildTermination {
71            reason: "engine handle child termination is not wired here".to_owned(),
72        })
73    }
74
75    fn terminate_linked_activity(
76        &self,
77        parent_workflow_id: &WorkflowId,
78        activity_process: crate::Pid,
79        correlation: u64,
80    ) -> Result<(), EngineSeamError> {
81        let _ = (parent_workflow_id, activity_process, correlation);
82        Err(EngineSeamError::ChildTermination {
83            reason: "engine handle activity termination is not wired here".to_owned(),
84        })
85    }
86
87    fn arm_timer(&self, entry: crate::engine_seam::TimerWheelEntry) -> Result<(), EngineSeamError> {
88        let _ = entry;
89        Err(EngineSeamError::TimerWheel {
90            reason: "engine handle timer arming is not wired here".to_owned(),
91        })
92    }
93
94    fn disarm_timer(
95        &self,
96        process: WorkflowProcessHandle,
97        timer_id: &aion_core::TimerId,
98    ) -> Result<(), EngineSeamError> {
99        let _ = (process, timer_id);
100        Err(EngineSeamError::TimerWheel {
101            reason: "engine handle timer disarming is not wired here".to_owned(),
102        })
103    }
104
105    fn record_workflow_event(
106        &self,
107        workflow_id: &WorkflowId,
108        event: Event,
109    ) -> Result<crate::engine_seam::RecordOutcome, EngineSeamError> {
110        let _ = (workflow_id, event);
111        Err(EngineSeamError::Recorder {
112            reason: "engine handle event recording is not wired here".to_owned(),
113        })
114    }
115}