Skip to main content

liminal/aion/
types.rs

1use std::time::{Duration, SystemTime};
2
3use super::error::AionSurfaceError;
4
5/// Type-erased data exchanged across Aion activity, signal, and history surfaces.
6#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub struct Payload {
8    /// Opaque payload bytes.
9    pub data: Vec<u8>,
10    /// Content type tag describing the encoded payload.
11    pub content_type: String,
12}
13
14/// Activity dispatch request sent through an Aion dispatch channel.
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct ActivityRequest {
17    /// Activity type name requested by the workflow.
18    pub activity_type: String,
19    /// Type-erased activity input payload.
20    pub input: Payload,
21    /// Task queue that should receive the activity request.
22    pub task_queue: String,
23    /// Maximum time from scheduling to completion.
24    pub schedule_to_close_timeout: Option<Duration>,
25    /// Maximum time from worker start to completion.
26    pub start_to_close_timeout: Option<Duration>,
27}
28
29/// Activity dispatch result returned by an Aion dispatch conversation.
30#[derive(Clone, Debug, PartialEq, Eq)]
31pub enum ActivityResult {
32    /// Activity completed with a type-erased output payload.
33    Completed { output: Payload },
34    /// Activity failed with integration-surface diagnostic context.
35    Failed { error: AionSurfaceError },
36}
37
38/// Signal payload delivered through a workflow signal channel.
39#[derive(Clone, Debug, PartialEq, Eq)]
40pub struct SignalPayload {
41    /// Workflow-declared signal name.
42    pub signal_name: String,
43    /// Type-erased signal bytes and content type.
44    pub payload: Payload,
45}
46
47/// Worker capacity declaration used by later dispatch routing briefs.
48#[derive(Clone, Debug, PartialEq, Eq)]
49pub struct WorkerCapacity {
50    /// Maximum number of activities the worker can run concurrently.
51    pub max_concurrent: usize,
52    /// Activity types accepted by this worker.
53    pub activity_types: Vec<String>,
54}
55
56/// Workflow history event envelope published to a history channel.
57#[derive(Clone, Debug, PartialEq, Eq)]
58pub struct HistoryEvent {
59    /// Monotonic workflow-history sequence number.
60    pub sequence: u64,
61    /// Workflow event type name.
62    pub event_type: String,
63    /// Timestamp assigned to the history event.
64    pub timestamp: SystemTime,
65    /// Type-erased event payload.
66    pub payload: Payload,
67}
68
69#[cfg(test)]
70mod tests {
71    use super::Payload;
72
73    #[test]
74    fn payload_default_is_empty() {
75        let payload = Payload::default();
76
77        assert!(payload.data.is_empty());
78        assert!(payload.content_type.is_empty());
79    }
80}