Skip to main content

Crate orcher_sdk_macros

Crate orcher_sdk_macros 

Source
Expand description

§ORCHER Macros

Procedural macros for defining Orcher workflows, tasks, handlers, and actors.

Each macro keeps the item you wrote and generates the glue around it: payload (de)serialization, typed references, and registration so a worker finds the item at startup without manual wiring.

§Available Macros

  • #[task] and #[tasks]: define tasks, the units of work that touch the outside world.
  • #[workflow]: define a workflow, the deterministic code that orchestrates tasks.
  • #[query], #[update], #[event]: handlers that read, change, or send events to a running workflow.
  • #[actor], #[operations], #[operation]: stateful actors.
  • #[derive(Payload)] (feature derive): payload conversion methods for a type.

These macros are re-exported by the orcher-sdk crate, which the generated code refers to, so depend on orcher-sdk and import them from its prelude.

§Examples

§Task Macro

use orcher_sdk::prelude::*;

#[task(
    retry_policy(max_attempts = 3, initial_interval = 1, backoff_coefficient = 2.0),
    timeout = 30
)]
async fn process_data(_ctx: TaskContext, input: String) -> Result<String> {
    // Do the work here.
    Ok(format!("Processed: {input}"))
}

§Workflow Macro

use orcher_sdk::prelude::*;

#[workflow(name = "data-pipeline")]
async fn data_pipeline(ctx: WorkflowContext, input: String) -> Result<String> {
    // Orchestrate tasks here.
    ctx.execute_task(process_data, input).await
}

Attribute Macros§

actor
Marks a struct as a stateful actor type.
event
Declares an event: an asynchronous message sent to a running workflow to trigger an action or a state change. The sender does not wait for a result.
operation
Marks a method in an #[operations] block as an actor operation.
operations
Defines the operations of an actor on its impl block.
query
Declares a query: a read of a running workflow’s state that does not affect its execution.
task
Turns an async fn into a task that workers can run.
tasks
Defines a group of tasks as methods on an impl block.
update
Turns an async fn into an update handler for a running workflow.
workflow
Turns an async fn into a workflow definition.

Derive Macros§

Payload
Derives JSON payload conversion methods for a type.