Skip to main content

chronon_core/models/
script.rs

1//! Script model - represents a registered script in the database.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// A registered script in the database.
8///
9/// Scripts are auto-discovered via `#[chronon::script]` and persisted
10/// for reference by jobs.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Script {
13    /// Unique identifier (UUID).
14    pub script_id: String,
15
16    /// Unique stable name from the macro attribute.
17    pub script_name: String,
18
19    /// JSON schema for parameters (excluding context).
20    pub signature_json: Value,
21
22    /// Hash of signature_json for version checking.
23    pub signature_hash: String,
24
25    /// When the script was first registered.
26    pub created_at: DateTime<Utc>,
27}
28
29impl Script {
30    /// Create a new script record.
31    pub fn new(
32        script_name: impl Into<String>,
33        signature_json: Value,
34        signature_hash: String,
35    ) -> Self {
36        Self {
37            script_id: uuid::Uuid::new_v4().to_string(),
38            script_name: script_name.into(),
39            signature_json,
40            signature_hash,
41            created_at: Utc::now(),
42        }
43    }
44}