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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//! `SQLite` [`SchedulerStore`](chronon_core::store::SchedulerStore) for Chronon.
//!
//! **When to use:** durable single-host **Mode 1**, or same-host **Mode 2** when coordinator and
//! worker open the **same database file** (SQLite allows one writer at a time — prefer Postgres
//! ± Redis for multi-worker fleets).
//!
//! Getting started:
//! [Mode 1](https://docs.rs/uf-chronon/latest/chronon/index.html#mode-1--embedded-one-binary) /
//! [Mode 2](https://docs.rs/uf-chronon/latest/chronon/index.html#mode-2--coordinator--worker-two-binaries).
//!
//! ## Stack position
//!
//! ```text
//! chronon (facade, `sqlite` feature) → chronon-backend-sqlite → chronon-backend-sql-common → chronon-core
//! ```
//!
//! ## Entry points
//!
//! - [`SqliteSchedulerStore::new`] — open a database file
//! - [`SqliteSchedulerStore::connect`] — connect via URL (including `:memory:`)
//!
//! ## Mode 1 — Embedded
//!
//! ```ignore
//! use std::sync::Arc;
//! use chronon::prelude::*;
//! use chronon::SqliteSchedulerStore;
//!
//! let store = SqliteSchedulerStore::connect("sqlite:///var/lib/chronon/chronon.db").await?;
//! let chronon = ChrononBuilder::new()
//! .scheduler_store(Arc::new(store))
//! .context_factory(Arc::new(JsonScriptContextFactory))
//! .embedded()
//! .auto_registry()
//! .build()?;
//! ```
//!
//! Runnable: `cargo run -p uf-chronon --example sqlite_boot --features sqlite`
//!
//! ## Mode 2 — Coordinator binary
//!
//! Shared file path with the worker. Tick only — no script execution in this process:
//!
//! ```ignore
//! use std::sync::Arc;
//! use chronon::prelude::*;
//! use chronon::SqliteSchedulerStore;
//!
//! let path = std::env::var("CHRONON_SQLITE_PATH")
//! .unwrap_or_else(|_| "/tmp/chronon-remote.db".into());
//! let store = SqliteSchedulerStore::new(&path).await?;
//! let mut chronon = ChrononBuilder::new()
//! .scheduler_store(Arc::new(store))
//! .context_factory(Arc::new(JsonScriptContextFactory))
//! .instance_id("coordinator-0")
//! .coordinator_only()
//! .build()?;
//! chronon.scheduler.init_partitions().await;
//! chronon.run().await?;
//! ```
//!
//! ## Mode 2 — Worker binary
//!
//! Same `CHRONON_SQLITE_PATH`, unique `CHRONON_INSTANCE_ID`, scripts linked via `.auto_registry()`:
//!
//! ```ignore
//! use std::sync::Arc;
//! use chronon::prelude::*;
//! use chronon::SqliteSchedulerStore;
//!
//! let path = std::env::var("CHRONON_SQLITE_PATH")
//! .unwrap_or_else(|_| "/tmp/chronon-remote.db".into());
//! let store = SqliteSchedulerStore::new(&path).await?;
//! let mut chronon = ChrononBuilder::new()
//! .scheduler_store(Arc::new(store))
//! .context_factory(Arc::new(JsonScriptContextFactory))
//! .instance_id(std::env::var("CHRONON_INSTANCE_ID").unwrap_or_else(|_| "worker-1".into()))
//! .auto_registry()
//! .worker("general")
//! .build()?;
//! chronon.run().await?;
//! ```
//!
//! Other Mode 2 backends:
//! [Postgres](../chronon_backend_postgres/index.html#mode-2--coordinator-binary),
//! [Postgres + Redis](../chronon_backend_redis/index.html#mode-2--coordinator-binary).
use Path;
use SqlSchedulerStore;
use Result;
use SqlitePool;
/// SQLite-backed scheduler store.
///
/// Durable **single-host** persistence for Mode 1 embedded deployments and CI. SQLite allows
/// one writer at a time — prefer Postgres (+ Redis) for multi-worker Mode 2 claim throughput.
/// Same-host Mode 2 is possible when both binaries open the **same path**.
///
/// Mode 2 examples: [coordinator](index.html#mode-2--coordinator-binary) /
/// [worker](index.html#mode-2--worker-binary).
///
/// Enable the facade `sqlite` feature. Construct with [`Self::new`] (file path) or
/// [`Self::connect`] (URL, including `sqlite://:memory:`).
///
/// # Examples
///
/// ```rust,no_run
/// use chronon_backend_sqlite::SqliteSchedulerStore;
///
/// # async fn example() -> chronon_core::Result<()> {
/// let store = SqliteSchedulerStore::connect("sqlite://:memory:").await?;
/// # let _ = store;
/// # Ok(())
/// # }
/// ```
///
/// Runnable: `cargo run -p uf-chronon --example sqlite_boot --features sqlite`.
delegate_scheduler_store!;