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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! [`RunWaker`] -- wakes `Sleeping` runs whose `scheduled_at` has passed.
//!
//! A run goes `Sleeping` when a [`delay`](crate::context::WorkflowContext::delay)
//! step pauses it, or when
//! [`wait_for_signal`](crate::context::WorkflowContext::wait_for_signal) suspends
//! it until a signal or its deadline. Either way the wake-up time lives on the
//! run itself (`scheduled_at`), so the timer survives an API or worker restart:
//! nothing is held in memory, and a brand-new process picks the run up on its
//! next tick.
//!
//! [`RunWaker::tick`] claims every due run and moves it back to `Pending` in
//! the same transaction that clears `scheduled_at`, so a run wakes **exactly
//! once** even with several API instances running a waker. Under
//! [`ExecutionMode::Workers`] a worker then picks the run up; under
//! [`ExecutionMode::Local`] the waker resumes it in-process.
use Arc;
use info;
use Run;
use crate;
use crateEngineError;
/// How many runs a single [`RunWaker::tick`] wakes.
pub const DEFAULT_WAKE_BATCH_SIZE: u32 = 50;
/// Wakes `Sleeping` runs whose wake-up time has passed.
///
/// # Examples
///
/// ```no_run
/// use std::sync::Arc;
/// use ironflow_core::providers::claude::ClaudeCodeProvider;
/// use ironflow_engine::engine::Engine;
/// use ironflow_engine::wake::RunWaker;
/// use ironflow_store::memory::InMemoryStore;
/// use ironflow_store::store::Store;
///
/// # async fn example() -> Result<(), ironflow_engine::error::EngineError> {
/// let store: Arc<dyn Store> = Arc::new(InMemoryStore::new());
/// let engine = Arc::new(Engine::new(store, Arc::new(ClaudeCodeProvider::new())));
///
/// let waker = RunWaker::new(engine).batch_size(10);
/// let woken = waker.tick().await?;
/// println!("{} runs woken", woken.len());
/// # Ok(())
/// # }
/// ```