Skip to content

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.

pub

Result of a trigger poll operation.

  • Skip - Do not fire the workflow, continue polling on the next interval.
  • Fire - Fire the workflow with an optional context.

pub

fn should_fire(&self) -> bool

Returns true if this result indicates the workflow should fire.

Source
pub fn should_fire(&self) -> bool {
matches!(self, TriggerResult::Fire(_))
}

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,
}
}

pub

fn context_hash(&self) -> String

Computes 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())
}
}
}

pub

Errors that can occur during trigger polling.

  • PollError - Error during trigger polling
  • ContextError - Context creation error

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.

fn name(&self) -> &str

Returns the unique name of this trigger.

Source
fn name(&self) -> &str;
fn poll_interval(&self) -> Duration

Returns how often this trigger should be polled.

Source
fn poll_interval(&self) -> Duration;
fn allow_concurrent(&self) -> bool

Returns 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>;
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
}
fn workflow_name(&self) -> &str

The 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 {
""
}