hyprstream_workers/workflow/adapter.rs
1//! Subscriber adapter pattern for bridging events to workflow dispatch.
2//!
3//! A `SubscriberAdapter` watches events and dispatches workflows. The
4//! `WorkflowService` is a pure execution engine; adapters provide the
5//! event-to-workflow routing logic.
6//!
7//! GitHub Actions is one adapter. Others (Tekton, Argo, raw capnp RPC)
8//! could follow the same pattern.
9
10use std::sync::Arc;
11
12use async_trait::async_trait;
13use tokio_util::sync::CancellationToken;
14
15use super::service::WorkflowService;
16use crate::error::Result;
17
18/// A subscriber adapter watches events and dispatches workflows.
19///
20/// Each adapter owns its event subscription and handler logic.
21/// The `WorkflowService` provides only execution — adapters decide
22/// which workflows to dispatch in response to which events.
23#[async_trait]
24pub trait SubscriberAdapter: Send + Sync {
25 /// Human-readable name for logging.
26 fn name(&self) -> &str;
27
28 /// Start watching events. Runs until cancelled.
29 ///
30 /// The adapter should:
31 /// 1. Subscribe to relevant event topics
32 /// 2. Loop: receive event → match handlers → dispatch workflows
33 /// 3. Exit cleanly when `cancel` is triggered
34 async fn run(&self, service: Arc<WorkflowService>, cancel: CancellationToken) -> Result<()>;
35}