Skip to main content

fraiseql_cli/config/toml_schema/
observers.rs

1//! Observer/event system configuration for TOML schema.
2
3use serde::{Deserialize, Serialize};
4
5/// Observers/event system configuration
6#[derive(Debug, Clone, Deserialize, Serialize)]
7#[serde(default, deny_unknown_fields)]
8pub struct ObserversConfig {
9    /// Enable observers system
10    #[serde(default)]
11    pub enabled:   bool,
12    /// Backend service (redis, nats, postgresql, mysql, in-memory)
13    pub backend:   String,
14    /// Redis connection URL (required when backend = "redis")
15    pub redis_url: Option<String>,
16    /// NATS connection URL (required when backend = "nats")
17    ///
18    /// Example: `nats://localhost:4222`
19    /// Can be overridden at runtime via the `FRAISEQL_NATS_URL` environment variable.
20    pub nats_url:  Option<String>,
21    /// Event handlers
22    pub handlers:  Vec<EventHandler>,
23}
24
25impl Default for ObserversConfig {
26    fn default() -> Self {
27        Self {
28            enabled:   false,
29            backend:   "redis".to_string(),
30            redis_url: None,
31            nats_url:  None,
32            handlers:  vec![],
33        }
34    }
35}
36
37/// Event handler configuration
38#[derive(Debug, Clone, Deserialize, Serialize)]
39#[serde(deny_unknown_fields)]
40pub struct EventHandler {
41    /// Handler name
42    pub name:           String,
43    /// Event type to handle
44    pub event:          String,
45    /// Action to perform (slack, email, sms, webhook, push, etc.)
46    pub action:         String,
47    /// Webhook URL for webhook actions
48    pub webhook_url:    Option<String>,
49    /// Retry strategy
50    pub retry_strategy: Option<String>,
51    /// Maximum retry attempts
52    pub max_retries:    Option<u32>,
53    /// Handler description
54    pub description:    Option<String>,
55}