Skip to main content

ralph/contracts/config/
loop_.rs

1//! Run loop waiting configuration for daemon/continuous mode.
2//!
3//! Responsibilities:
4//! - Define loop config struct and merge behavior.
5//!
6//! Not handled here:
7//! - Loop execution logic (see `crate::commands::run` module).
8
9use schemars::JsonSchema;
10use serde::{Deserialize, Serialize};
11
12/// Run loop waiting configuration for daemon/continuous mode.
13#[derive(Debug, Clone, Serialize, Deserialize, Default, JsonSchema)]
14#[serde(default, deny_unknown_fields)]
15pub struct LoopConfig {
16    /// Wait when queue is empty instead of exiting (continuous/daemon mode).
17    pub wait_when_empty: Option<bool>,
18
19    /// Poll interval in milliseconds while waiting for new tasks when queue is empty.
20    /// Default: 30000 (30 seconds). Minimum: 50.
21    #[schemars(range(min = 50))]
22    pub empty_poll_ms: Option<u64>,
23
24    /// Wait when blocked by dependencies/schedule instead of exiting.
25    pub wait_when_blocked: Option<bool>,
26
27    /// Poll interval in milliseconds while waiting for blocked tasks to become runnable.
28    /// Default: 1000 (1 second). Minimum: 50.
29    #[schemars(range(min = 50))]
30    pub wait_poll_ms: Option<u64>,
31
32    /// Timeout in seconds for waiting (0 = no timeout).
33    #[schemars(range(min = 0))]
34    pub wait_timeout_seconds: Option<u64>,
35
36    /// Send notification when queue transitions from blocked to runnable.
37    pub notify_when_unblocked: Option<bool>,
38}
39
40impl LoopConfig {
41    pub fn merge_from(&mut self, other: Self) {
42        if other.wait_when_empty.is_some() {
43            self.wait_when_empty = other.wait_when_empty;
44        }
45        if other.empty_poll_ms.is_some() {
46            self.empty_poll_ms = other.empty_poll_ms;
47        }
48        if other.wait_when_blocked.is_some() {
49            self.wait_when_blocked = other.wait_when_blocked;
50        }
51        if other.wait_poll_ms.is_some() {
52            self.wait_poll_ms = other.wait_poll_ms;
53        }
54        if other.wait_timeout_seconds.is_some() {
55            self.wait_timeout_seconds = other.wait_timeout_seconds;
56        }
57        if other.notify_when_unblocked.is_some() {
58            self.notify_when_unblocked = other.notify_when_unblocked;
59        }
60    }
61}