Skip to main content

task

Attribute Macro task 

Source
#[task]
Expand description

Transforms an async function into a CoreTask implementation.

§Attributes

  • id = "custom_name" — override the task ID (default: function name)
  • display_name = "Charge Card" — human-readable name
  • description = "Charges the customer's card" — task description
  • timeout = "30s" — task timeout (supports ms, s, m, h suffixes)
  • retries = 3 — maximum retry count
  • backoff = "100ms" — initial retry delay
  • backoff_multiplier = 2.0 — exponential multiplier (default: 2.0)
  • tags = "io" — categorization tags (can be repeated)

§Parameters

  • Exactly one non-#[inject] parameter: the task input type
  • Zero or more #[inject] parameters: dependency-injected fields

§Return Types

  • Result<T, E> — fallible; E is converted via Into<BoxError>
  • T — infallible; automatically wrapped in Ok(...)

§Generated Code

  • A PascalCase struct (e.g., fn chargestruct Charge)
  • new() constructor with positional args for injected dependencies
  • task_id() and metadata() helper methods
  • register() method for TaskRegistry integration
  • CoreTask trait implementation
  • The original function is preserved for direct use/testing