ralph/lock/mod.rs
1//! Directory lock facade for queue and daemon coordination.
2//!
3//! Responsibilities:
4//! - Expose lock acquisition, owner metadata, stale-lock handling, and PID liveness helpers.
5//! - Keep concurrency-critical concerns split into focused submodules.
6//!
7//! Not handled here:
8//! - Queue mutation or config validation.
9//! - Cross-machine or distributed locking.
10//!
11//! Invariants/assumptions:
12//! - Callers hold `DirLock` for the full critical section.
13//! - The lock directory path is stable for the resource being protected.
14//! - The `task` label remains reserved for shared supervisor/task lock semantics.
15
16mod acquisition;
17mod cleanup;
18mod owner;
19mod pid;
20mod stale;
21
22use std::path::PathBuf;
23
24pub use acquisition::{acquire_dir_lock, is_supervising_process, queue_lock_dir};
25pub use owner::{LockOwner, TASK_OWNER_PREFIX, is_task_owner_file, read_lock_owner};
26pub use pid::{PidLiveness, pid_is_running, pid_liveness};
27
28/// Held directory lock guard.
29#[derive(Debug)]
30pub struct DirLock {
31 lock_dir: PathBuf,
32 owner_path: PathBuf,
33}
34
35impl Drop for DirLock {
36 fn drop(&mut self) {
37 if let Err(error) = cleanup::cleanup_lock_dir(&self.lock_dir, &self.owner_path, false) {
38 log::warn!("Failed to clean up lock directory after retries: {}", error);
39 }
40 }
41}
42
43#[cfg(test)]
44mod tests;