pub struct TriggerStore { /* private fields */ }Implementations§
Source§impl TriggerStore
impl TriggerStore
pub fn default_root() -> Result<PathBuf>
pub fn open(root: impl Into<PathBuf>) -> Result<Self>
pub fn open_default() -> Result<Self>
Sourcepub fn open_existing_default() -> Option<Self>
pub fn open_existing_default() -> Option<Self>
Open only if it already exists — for read paths that must not create state as a side effect.
pub fn root(&self) -> &Path
pub fn path_of(&self, name: &str) -> PathBuf
pub fn ledger_path(&self) -> PathBuf
Sourcepub fn list(&self) -> Result<(Vec<Trigger>, Vec<String>)>
pub fn list(&self) -> Result<(Vec<Trigger>, Vec<String>)>
Every trigger, by name.
An unreadable or invalid file is reported and skipped rather than failing the whole listing: one bad trigger must not stop the other three from firing.
pub fn get(&self, name: &str) -> Result<Trigger>
pub fn exists(&self, name: &str) -> bool
pub fn save(&self, trigger: &Trigger) -> Result<()>
pub fn remove(&self, name: &str) -> Result<()>
Sourcepub fn append_run(&self, record: &RunRecord) -> Result<()>
pub fn append_run(&self, record: &RunRecord) -> Result<()>
Append one row. Held under the store lock so two ticks cannot interleave a line.
Sourcepub fn runs(&self) -> Result<Vec<RunRecord>>
pub fn runs(&self) -> Result<Vec<RunRecord>>
The ledger, oldest first. A torn or unparseable line is skipped: this is an audit trail, and one bad line must not hide the rest.
Sourcepub fn scan_runs_rev(&self, visit: impl FnMut(RunRecord) -> bool) -> Result<()>
pub fn scan_runs_rev(&self, visit: impl FnMut(RunRecord) -> bool) -> Result<()>
Visit ledger rows newest-first, stopping as soon as visit returns
false — the tail read behind “what happened last”, for callers that
need one recent row and must not deserialize an append-only file that
only ever grows. Read once as bytes, not read_to_string: one
invalid-UTF-8 byte in an old torn line would otherwise poison every
future tail read of a file whose end is fine. An undecodable or
unparseable line is skipped, the same audit-trail rule as runs:
one bad line must not hide the rest.
Sourcepub fn last_slots(&self) -> Result<BTreeMap<String, DateTime<Utc>>>
pub fn last_slots(&self) -> Result<BTreeMap<String, DateTime<Utc>>>
The most recent accounted-for slot per trigger — one ledger scan for the whole tick. Manual runs carry no slot and so are invisible here, which is the point.
Sourcepub fn try_claim(&self, name: &str) -> Result<Option<RunLock>>
pub fn try_claim(&self, name: &str) -> Result<Option<RunLock>>
Claim the right to run name, or None if a run of it is already in
flight — in this process or any other.
Non-blocking on purpose: the answer “someone else is running it” is the useful one, and waiting for a twenty-minute briefing to finish so a second copy can start is never what anybody wanted.
Sourcepub fn mark_running(
&self,
name: &str,
slot: Option<DateTime<Utc>>,
) -> Result<()>
pub fn mark_running( &self, name: &str, slot: Option<DateTime<Utc>>, ) -> Result<()>
Announce that a run has started, for anything that wants to display
whether one is in flight. See crate::runmarker for why this is not
the flock.
Sourcepub fn clear_running(&self, name: &str)
pub fn clear_running(&self, name: &str)
Clear the marker and any unclaimed cancel request.
Sourcepub fn request_cancel(&self, name: &str) -> Result<bool>
pub fn request_cancel(&self, name: &str) -> Result<bool>
Ask the run in flight to stop. Returns false when there is nothing to stop, so a caller can say so rather than pretending.
Sourcepub fn cancel_requested(&self, name: &str) -> bool
pub fn cancel_requested(&self, name: &str) -> bool
Has a cancel been requested for the run in flight?