1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Chronon proc-macro crate.
//!
//! Provides the [`script`] attribute macro for auto-registering scheduled Rust functions.
//!
//! # Quick start
//!
//! 1. Annotate an async function with `#[chronon::script(name = "...")]`.
//! 2. First parameter must be `Box<dyn ScriptContext>`.
//! 3. Link the defining crate into your worker binary.
//! 4. Boot Chronon with `.auto_registry()` and a `ContextFactory` from `chronon-core`.
//!
//! # Identity
//!
//! Handlers receive `Box<dyn ScriptContext>`. At boot, install a factory on `ChrononBuilder`:
//!
//! - `JsonScriptContextFactory` for examples and actor-json-only handlers.
//! - A custom `ContextFactory` when handlers need application-specific session state rebuilt
//! from `actor_json`.
//!
//! See `chronon-core` rustdoc for factory types. Runnable samples:
//! - `examples/script_macro.rs` โ register script, `Job::new`, upsert, tick
//! - `examples/script_handle_job.rs` โ typed `ScriptHandle` defaults
use TokenStream;
/// 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
///
/// ```ignore
/// 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`.