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
//! Time source for taquba.
//!
//! Every state transition that records a timestamp (`enqueued_at`,
//! `completed_at`, `failed_at`, `lease_expires_at`) and every comparison
//! against a stored timestamp (retention cutoffs, scheduled-job
//! promotion) reads the current time through a [`Clock`]. Production
//! callers leave [`OpenOptions::clock`](crate::OpenOptions::clock) at
//! its default [`SystemClock`]; tests can substitute [`MockClock`] to
//! advance time deterministically without `std::thread::sleep` or
//! `tokio::time::sleep`.
use Arc;
use ;
use ;
/// A source of "current time" in milliseconds since the UNIX epoch.
///
/// Carried by [`Queue`](crate::Queue) (and threaded into its background
/// reaper / scheduler tasks) so the same wall-clock semantics apply
/// everywhere. Implementors must be cheap to call and thread-safe
/// (the value is read from many tokio tasks concurrently).
/// Reads `SystemTime::now()` and converts to milliseconds since the
/// UNIX epoch. The default for
/// [`OpenOptions::clock`](crate::OpenOptions::clock).
;
/// A clock whose value the caller controls. Useful in tests where time
/// has to move past a retention window or a scheduled-job `run_at`
/// without waiting on the real clock.
///
/// `MockClock` is cheaply cloneable: every clone shares the same
/// underlying value, so advancing one advances all of them. Pass a
/// clone into `OpenOptions::clock` and keep the original around to
/// call [`advance`](Self::advance) / [`set`](Self::set) from the test
/// body.
///
/// ```
/// use std::time::Duration;
/// use taquba::{Clock, MockClock};
///
/// let clock = MockClock::new(1_700_000_000_000);
/// assert_eq!(clock.now_ms(), 1_700_000_000_000);
/// clock.advance(Duration::from_secs(60));
/// assert_eq!(clock.now_ms(), 1_700_000_060_000);
/// ```
;
pub