Skip to main content

Operation

Trait Operation 

Source
pub trait Operation: Send + Sync {
    // Required methods
    fn kind(&self) -> &str;
    fn execute(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<Value, EngineError>> + Send + '_>>;

    // Provided method
    fn input(&self) -> Option<Value> { ... }
}
Expand description

A user-defined operation that integrates into the workflow step lifecycle.

Implement this trait for custom integrations (GitLab, Gmail, Slack, etc.) that need full step tracking when executed via WorkflowContext::operation().

§Contract

  • kind() returns a short, lowercase identifier stored as StepKind::Custom in the database (e.g. "gitlab", "gmail", "slack").
  • execute() performs the operation and returns a JSON Value on success. The engine persists this as the step output.

§Examples

use ironflow_engine::operation::Operation;
use ironflow_engine::error::EngineError;
use serde_json::{Value, json};
use std::future::Future;
use std::pin::Pin;

struct SendSlackMessage {
    channel: String,
    text: String,
}

impl Operation for SendSlackMessage {
    fn kind(&self) -> &str { "slack" }

    fn execute(&self) -> Pin<Box<dyn Future<Output = Result<Value, EngineError>> + Send + '_>> {
        Box::pin(async move {
            // Post to Slack API ...
            Ok(json!({"ok": true, "ts": "1234567890.123456"}))
        })
    }
}

Required Methods§

Source

fn kind(&self) -> &str

A short, lowercase identifier for this operation type.

Stored as StepKind::Custom(kind) in the database. Examples: "gitlab", "gmail", "slack".

Source

fn execute( &self, ) -> Pin<Box<dyn Future<Output = Result<Value, EngineError>> + Send + '_>>

Execute the operation and return the result as JSON.

The returned Value is persisted as the step output. On error, the engine marks the step as Failed and records the error message.

§Errors

Return EngineError if the operation fails.

Provided Methods§

Source

fn input(&self) -> Option<Value>

Optional JSON representation of the operation input, stored in the step’s input column for observability.

Defaults to None. Override to provide structured input logging.

§Examples
fn input(&self) -> Option<Value> {
    Some(json!({"project_id": 123, "title": "Bug report"}))
}

Implementors§