cloacina-workflow::trigger
Rust
Trigger types for workflow authoring.
T-0552 (I-0102 follow-up) relocated the Trigger trait from cloacina
(engine-only) into this leaf crate so packaged cdylibs can collect
TriggerEntry inventory entries (which hold Arc<dyn Trigger>) at
link time, and the unified cloacina::package!() shell macro can walk
them at FFI call time. Engine paths re-export cloacina_workflow::Trigger.
enum TriggerResult
Section titled “enum TriggerResult”pub
Result of a trigger poll operation.
Variants
Section titled “Variants”Skip- Do not fire the workflow, continue polling on the next interval.Fire- Fire the workflow with an optional context.
Methods
Section titled “Methods”should_fire
Section titled “should_fire”pub
fn should_fire(&self) -> boolReturns true if this result indicates the workflow should fire.
Source
pub fn should_fire(&self) -> bool { matches!(self, TriggerResult::Fire(_)) }into_context
Section titled “into_context”pub
fn into_context(self) -> Option<Context<serde_json::Value>>Extracts the context if this is a Fire result.
Source
pub fn into_context(self) -> Option<Context<serde_json::Value>> { match self { TriggerResult::Fire(ctx) => ctx, TriggerResult::Skip => None, } }context_hash
Section titled “context_hash”pub
fn context_hash(&self) -> StringComputes a hash of the context for deduplication purposes.
If no context is provided, returns a constant hash. This allows deduplication based on the specific trigger conditions.
Source
pub fn context_hash(&self) -> String { match self { TriggerResult::Skip => "skip".to_string(), TriggerResult::Fire(None) => "fire_no_context".to_string(), TriggerResult::Fire(Some(ctx)) => { let mut hasher = DefaultHasher::new(); if let Ok(serialized) = serde_json::to_string(ctx.data()) { serialized.hash(&mut hasher); } format!("{:016x}", hasher.finish()) } } }enum TriggerError
Section titled “enum TriggerError”pub
Errors that can occur during trigger polling.
Variants
Section titled “Variants”PollError- Error during trigger pollingContextError- Context creation error
Traits
Section titled “Traits”trait Trigger
Section titled “trait Trigger”pub
Supertraits: Send + Sync + fmt::Debug
Core trait for user-defined triggers.
Triggers are polling functions that determine when a workflow should
execute. Each trigger has a name, poll interval, and a poll() method
that returns whether the workflow should fire.
Methods
Section titled “Methods”fn name(&self) -> &strReturns the unique name of this trigger.
Source
fn name(&self) -> &str;poll_interval
Section titled “poll_interval”fn poll_interval(&self) -> DurationReturns how often this trigger should be polled.
Source
fn poll_interval(&self) -> Duration;allow_concurrent
Section titled “allow_concurrent”fn allow_concurrent(&self) -> boolReturns whether concurrent executions with the same context are allowed. When false, if a workflow execution with the same context hash is already running, the trigger will not fire again until it completes.
Source
fn allow_concurrent(&self) -> bool;async
async fn poll(&self) -> Result<TriggerResult, TriggerError>Polls the trigger condition and returns whether to fire the workflow.
Called at the configured poll_interval. Returns TriggerResult::Skip
to continue polling, TriggerResult::Fire(ctx) to fire the workflow.
Errors are logged and polling continues on the next interval.
Source
async fn poll(&self) -> Result<TriggerResult, TriggerError>;cron_expression
Section titled “cron_expression”fn cron_expression(&self) -> Option<String>Returns this trigger’s cron expression, if any. Cron-shaped triggers override this to return Some(expr); their poll_interval is ignored and the reconciler routes them to the cron scheduler instead of the runtime trigger registry. Default None covers all custom-poll triggers.
Source
fn cron_expression(&self) -> Option<String> { None }workflow_name
Section titled “workflow_name”fn workflow_name(&self) -> &strThe target workflow this trigger fires — the #[trigger(on = "...")] binding. For cron triggers the reconciler registers the schedule against this workflow (not the trigger’s own name). Default empty for manual impls that don’t bind a workflow; macro-generated triggers always override it (CLOACI-T-0669).
Source
fn workflow_name(&self) -> &str { "" }