Skip to main content

cron

Attribute Macro cron 

Source
#[cron]
Expand description

Marks a function as a scheduled cron task.

Cron jobs run on a schedule, exactly once per scheduled time across the cluster.

§Attributes

All attributes are specified inline within the macro:

  • First argument: Cron schedule expression (required)
  • timezone = "UTC" - Timezone for the schedule
  • timeout = "1h" - Execution timeout
  • catch_up - Run missed executions after downtime
  • catch_up_limit = 10 - Maximum number of catch-up runs

§Example

#[forge::cron("0 0 * * *", timezone = "America/New_York", timeout = "30m", catch_up)]
pub async fn daily_cleanup(ctx: &CronContext) -> Result<()> {
    // ...
}