Skip to main content

aion_client/transport/
contract.rs

1//! The transport seam: the trait every adapter implements and the
2//! per-attempt subscription stream it returns.
3
4use aion_core::Event;
5use async_trait::async_trait;
6use futures::stream::BoxStream;
7
8use crate::error::ClientError;
9
10/// Transport abstraction over the six unary workflow-management RPCs plus
11/// event subscription.
12#[async_trait]
13pub trait WorkflowTransport: Send + Sync {
14    /// Sends `StartWorkflow` over the transport.
15    async fn start_workflow(
16        &self,
17        request: aion_proto::ProtoStartWorkflowRequest,
18    ) -> Result<aion_proto::ProtoStartWorkflowResponse, ClientError>;
19
20    /// Sends `Signal` over the transport.
21    async fn signal(
22        &self,
23        request: aion_proto::ProtoSignalRequest,
24    ) -> Result<aion_proto::ProtoSignalResponse, ClientError>;
25
26    /// Sends `Query` over the transport.
27    async fn query(
28        &self,
29        request: aion_proto::ProtoQueryRequest,
30    ) -> Result<aion_proto::ProtoQueryResponse, ClientError>;
31
32    /// Sends `Cancel` over the transport.
33    async fn cancel(
34        &self,
35        request: aion_proto::ProtoCancelRequest,
36    ) -> Result<aion_proto::ProtoCancelResponse, ClientError>;
37
38    /// Sends `ListWorkflows` over the transport.
39    async fn list_workflows(
40        &self,
41        request: aion_proto::ProtoListWorkflowsRequest,
42    ) -> Result<aion_proto::ProtoListWorkflowsResponse, ClientError>;
43
44    /// Sends `DescribeWorkflow` over the transport.
45    async fn describe_workflow(
46        &self,
47        request: aion_proto::ProtoDescribeWorkflowRequest,
48    ) -> Result<aion_proto::ProtoDescribeWorkflowResponse, ClientError>;
49
50    /// Opens an event subscription attempt.
51    ///
52    /// `resume_from_sequence` is the wire resume cursor (`resume_from_seq`,
53    /// the FIRST per-workflow sequence number wanted — `last delivered + 1`).
54    /// It is only ever supplied for per-workflow subscriptions; filtered and
55    /// firehose streams are live-only by design and must reject a cursor.
56    async fn subscribe(
57        &self,
58        request: aion_proto::SubscriptionRequest,
59        resume_from_sequence: Option<u64>,
60    ) -> Result<SubscriptionAttempt, ClientError>;
61}
62
63/// One transport-level event subscription attempt.
64pub struct SubscriptionAttempt {
65    /// Decoded events for this attempt. A transient disconnect is represented
66    /// by an `Err(ClientError::Unavailable)` item; any other error item is
67    /// terminal for the surrounding resume loop.
68    pub events: BoxStream<'static, Result<Event, ClientError>>,
69}
70
71impl SubscriptionAttempt {
72    /// Creates a subscription attempt from an event stream.
73    #[must_use]
74    pub fn new(events: BoxStream<'static, Result<Event, ClientError>>) -> Self {
75        Self { events }
76    }
77}