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
//! 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
///
/// # Examples
///
/// ```ignore
/// #[chronon::script(name = "nightly_cleanup")]
/// async fn nightly_cleanup(
/// ctx: Box<dyn ScriptContext>,
/// retention_days: u32,
/// ) -> chronon::Result<()> {
/// let _ = (ctx.label(), retention_days);
/// Ok(())
/// }
/// ```