#[workflow]Expand description
Marks a function as a durable workflow.
Workflows are multi-step processes that survive restarts and handle failures with compensation.
§Authentication
By default, workflows require an authenticated user to start. Override with:
public- Can be started without authenticationrequire_role("admin")- Requires specific role to start
§Attributes
version = 1- Workflow version (increment for breaking changes)timeout = "24h"- Maximum execution timename = "custom_name"- Override workflow name
§Example
ⓘ
#[forge::workflow(version = 1, timeout = "24h")] // Requires authenticated user (default)
pub async fn user_onboarding(ctx: &WorkflowContext, input: OnboardingInput) -> Result<OnboardingResult> {
let user = ctx.step("create_user", || async { /* ... */ }).await?;
ctx.step("send_welcome", || async { /* ... */ }).await;
Ok(OnboardingResult { user })
}
#[forge::workflow(public)] // Can be started without auth
pub async fn process_webhook(ctx: &WorkflowContext, input: WebhookInput) -> Result<()> {
// ...
}
#[forge::workflow(version = 2, require_role("admin"))]
pub async fn admin_workflow(ctx: &WorkflowContext, input: AdminInput) -> Result<AdminResult> {
// Requires admin role to start
}