pub struct Queue { /* private fields */ }Expand description
A queue on disk.
Implementations§
Source§impl Queue
impl Queue
Sourcepub fn at(root: PathBuf) -> Self
pub fn at(root: PathBuf) -> Self
A queue at an explicit root. Tests use this; so could an operator who wants a queue per project.
Sourcepub fn put(&self, task: &mut Task) -> Result<()>
pub fn put(&self, task: &mut Task) -> Result<()>
Write a task, atomically, so a daemon killed mid-write leaves the previous state readable rather than a truncated file.
Sourcepub fn remove(&self, id: &str, in_flight: bool) -> Result<String>
pub fn remove(&self, id: &str, in_flight: bool) -> Result<String>
Remove a task, and the claim lock that belongs to it.
in_flight comes from the caller — a live daemon’s heartbeat naming
this task — because the task’s own running status cannot answer the
question. A daemon killed mid-competition leaves the status at
running and an orphaned .lock behind, and a guard that trusted
either would make the task undeletable for good: the phone showed
exactly that, refusing a task whose daemon had been gone for an hour.
So the lock is removed with the task rather than respected. Any lock
still there once no live daemon claims the task is by definition stale,
and leaving it would make a deleted task look claimed to
Queue::claim and to whoever reads the directory.
Sourcepub fn list(&self) -> Vec<Task>
pub fn list(&self) -> Vec<Task>
Every task on disk, highest priority first and newest first within a
priority. This is what magi task list and GET /api/queue print, so
a raised priority has to move a task here the moment it is saved, not
only in Queue::next_runnable’s own ordering - the operator reading
the backlog and the loop about to drain it must agree on what “first”
means. Every existing task defaults to priority 0, so this is a no-op
change from the old newest-first order for a queue nobody has
reprioritised.
Unreadable files are skipped rather than fatal: one corrupt task must not take the queue - or the web UI, or an unattended daemon - down with it.
Sourcepub fn next_runnable(&self) -> Option<Task>
pub fn next_runnable(&self) -> Option<Task>
The task a daemon should run next, or None when the queue is idle.
Highest priority first, oldest first within a priority, so a burst of agent-filed work cannot starve the task a human filed this morning.
Sourcepub fn claim(&self, id: &str) -> Result<Claim>
pub fn claim(&self, id: &str) -> Result<Claim>
Take exclusive ownership of a task.
The lock is a create_new file next to the task, which is atomic on
every platform magi targets. It exists so two daemons - or a daemon and
a human running magi run - cannot drive one task into two competing
runs. The returned guard releases on drop, including on panic.
Sourcepub fn resolve_id(&self, prefix: &str) -> Result<String>
pub fn resolve_id(&self, prefix: &str) -> Result<String>
Expand an id prefix to exactly one task id.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Change detection token for the queue.
Combines file names and modification times of all task files in the queue, so adding, modifying, or deleting any task — even an older one — moves the revision and notifies connected clients via the change stream. Returns 0 when the queue is completely empty.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Queue
impl RefUnwindSafe for Queue
impl Send for Queue
impl Sync for Queue
impl Unpin for Queue
impl UnsafeUnpin for Queue
impl UnwindSafe for Queue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more