Skip to main content

stormchaser_model/
event.rs

1//! System event and correlation models for async execution.
2
3use crate::id::*;
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Maps a correlation key and value to a specific step instance waiting for an event.
9#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
10pub struct EventCorrelation {
11    /// Unique identifier for the correlation record.
12    pub id: EventId,
13    /// Associated step instance ID waiting for the event.
14    pub step_instance_id: StepInstanceId,
15    /// Associated workflow run ID.
16    pub run_id: RunId,
17    /// The key used for correlation (e.g., a specific payload field).
18    pub correlation_key: String,
19    /// The expected value for the correlation key.
20    pub correlation_value: String,
21    /// Timestamp when the correlation record was created.
22    pub created_at: DateTime<Utc>,
23}
24
25/// Registry of human-in-the-loop approvals.
26#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
27pub struct ApprovalRegistry {
28    /// Unique identifier for the approval record.
29    pub id: EventId,
30    /// Associated step instance ID that requires approval.
31    pub step_instance_id: StepInstanceId,
32    /// Identifier of the user who provided the approval or rejection.
33    pub user_id: String,
34    /// Status of the approval request (e.g., 'approved', 'rejected').
35    pub status: String, // approved, rejected
36    /// Optional metadata or comments provided with the approval decision.
37    pub payload: Value,
38    /// Timestamp when the approval record was created.
39    pub created_at: DateTime<Utc>,
40}