Skip to main content

script

Attribute Macro script 

Source
#[script]
Expand description

Marks an async function as a Chronon script, enabling automatic registration and typed parameter handling.

§Requirements

  • Function must be async
  • First parameter must be Box<dyn ScriptContext>
  • Return type must be Result<()> (for example chronon_core::Result<()>)
  • name attribute is required and must be unique
  • Parameters after ScriptContext must be simple identifiers

Boot with ChrononBuilder::auto_registry() so inventory discovers the handler. In Mode 2, link scripts into worker binaries. Prefer chronon_core::ScriptHandle for typed job defaults; see the chronon facade getting-started §4–5.

§Examples

use chronon::prelude::*;

#[chronon::script(name = "nightly_cleanup")]
async fn nightly_cleanup(
    ctx: Box<dyn ScriptContext>,
    retention_days: u32,
) -> chronon::Result<()> {
    let _ = (ctx.label(), retention_days);
    Ok(())
}

Runnable: cargo run -p uf-chronon --example script_macro --features mem and script_handle_job.