Skip to main content

task

Attribute Macro task 

Source
#[task]
Expand description

Define a Rustvello task from a function.

Generates a params struct (if the function has parameters), a task struct, and a Task trait implementation.

§Basic usage

#[rustvello::task]
fn add(x: i32, y: i32) -> i32 {
    x + y
}

This generates:

  • AddParams — a serializable struct with fields x: i32, y: i32
  • AddTask — a unit struct implementing Task
  • The original add function is preserved for direct calls

§Configuration

#[rustvello::task(max_retries = 3)]
fn process(data: String) -> String {
    data.to_uppercase()
}

§Fallible tasks

If the function returns Result<T, _> or RustvelloResult<T>, the macro extracts T as the task’s result type and passes the function’s return value through without wrapping in Ok.

#[rustvello::task]
fn divide(x: f64, y: f64) -> RustvelloResult<f64> {
    if y == 0.0 {
        return Err(RustvelloError::runner_err("division by zero".into()));
    }
    Ok(x / y)
}

§Supported attributes

AttributeTypeDescription
max_retriesu32Maximum retry attempts (default: 0)
module&strOverride module in TaskId
concurrency&strConcurrency control: “unlimited”
registration_concurrency&strRegistration-time concurrency control
key_arguments[&str]Parameter names used as concurrency keys
cache_resultsboolCache results for identical arguments
disable_cache_args[&str]Arg names to exclude from cache key
retry_for_errors[&str]Error type names that trigger retries
on_diff_non_key_args_raiseboolRaise on non-key arg mismatch
parallel_batch_sizeusizeBatch size for parallelize()
force_new_workflowboolForce a new workflow for each invocation
reroute_on_ccboolReroute when hitting concurrency limits
blockingboolRun on a blocking thread