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
//! Cron watermarks: where each cron wake source left off, so the ticks it missed while no
//! kernel watched replay once, per the schedule's catch-up policy (spec 3.2 §7.4, §7.13).
//!
//! | Item | What it is |
//! |---|---|
//! | [`CronWatermarkStore`] | The cursor of each cron source by name, which only moves forward |
//! | [`SourceWatermark`] | One source's cursor as an `adk_agent::ambient::TickWatermark` |
//!
//! The store runs on in-memory, SQLite, PostgreSQL and Redis ([`InMemoryCronWatermarkStore`],
//! `SqliteCronWatermarkStore`, `PostgresCronWatermarkStore`, `RedisCronWatermarkStore`), and
//! on MongoDB, Firestore and Neo4j (`MongoCronWatermarkStore`,
//! `FirestoreCronWatermarkStore`, `Neo4jCronWatermarkStore`), with the conformance suite
//! `cron_watermark_store_conformance_tests!` (feature `conformance`).
//! A tenant kernel (`managed::TenantKernel`, feature `managed`) keeps its watermarks in the
//! tenant's own store, so a tick missed while no replica of the tenant ran is seen by the next
//! replica that starts.
//!
//! [`InMemoryCronWatermarkStore`]: crate::stores::InMemoryCronWatermarkStore
use Arc;
use TickWatermark;
use async_trait;
use ;
use crateResult;
/// Where each cron wake source left off (spec 3.2 §7.4, §7.13): the instant through which
/// its ticks are accounted for, by source name.
///
/// A cursor only moves forward: [`advance`](Self::advance) keeps the later of the stored
/// cursor and the one given, so replicas that watch one schedule and write in any order
/// never move it back, and a tick already accounted for is never planned again.
///
/// # Example
///
/// ```rust
/// use adk_kernel::CronWatermarkStore;
/// use adk_kernel::stores::InMemoryCronWatermarkStore;
/// use chrono::{TimeZone, Utc};
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> adk_kernel::Result<()> {
/// let store = InMemoryCronWatermarkStore::new();
/// let nine = Utc.with_ymd_and_hms(2026, 10, 24, 9, 0, 0).unwrap();
/// let eight = Utc.with_ymd_and_hms(2026, 10, 24, 8, 0, 0).unwrap();
/// assert_eq!(store.advance("nightly", nine).await?, nine);
/// // An earlier cursor, from a replica behind this one, leaves it where it is.
/// assert_eq!(store.advance("nightly", eight).await?, nine);
/// assert_eq!(store.read("nightly").await?, Some(nine));
/// # Ok(())
/// # }
/// ```
/// The cursor of one cron source in a [`CronWatermarkStore`], as the
/// `adk_agent::ambient::TickWatermark` a [`CronWakeSource`](crate::CronWakeSource) or a
/// `CronTrigger` keeps (spec 3.2 §7.4).
///
/// # Example
///
/// ```rust
/// use std::sync::Arc;
/// use adk_agent::ambient::TickWatermark;
/// use adk_kernel::SourceWatermark;
/// use adk_kernel::stores::InMemoryCronWatermarkStore;
///
/// # #[tokio::main(flavor = "current_thread")]
/// # async fn main() -> adk_core::Result<()> {
/// let watermark = SourceWatermark::new(Arc::new(InMemoryCronWatermarkStore::new()), "nightly");
/// assert_eq!(watermark.read().await?, None);
/// # Ok(())
/// # }
/// ```