pub struct BackgroundJobManager { /* private fields */ }Expand description
Shared manager for background jobs.
Implementations§
Source§impl BackgroundJobManager
impl BackgroundJobManager
pub fn new() -> Self
Sourcepub fn completed_notify(&self) -> Arc<Notify> ⓘ
pub fn completed_notify(&self) -> Arc<Notify> ⓘ
Return a clone of the completed-notify handle.
Used by the TUI loop arbiter to select! on job completion.
When a background job enters a terminal state (Completed, Failed,
TimedOut), notify_one() is called. notify_one() (rather than
notify_waiters()) stores a permit so a completion that happens
while the arbiter is mid-turn (not yet polling) is not lost — the
next notified() poll consumes the stored permit.
Sourcepub fn set_watch(&mut self, path: PathBuf, offset: u64)
pub fn set_watch(&mut self, path: PathBuf, offset: u64)
Register a file for mid-run event wakes. offset is the byte offset to
start reading from (typically the file size at registration time, so
only bytes appended afterwards wake the agent). Replaces any prior
watch.
Sourcepub fn clear_watch(&mut self)
pub fn clear_watch(&mut self)
Clear any registered file watch.
Sourcepub fn set_loop_control(&mut self, ctrl: LoopControl)
pub fn set_loop_control(&mut self, ctrl: LoopControl)
Set an agent-requested loop control (e.g. Stop). Replaces any prior
pending control. Read and consumed by the loop arbiter between turns.
Sourcepub fn take_loop_control(&mut self) -> Option<LoopControl>
pub fn take_loop_control(&mut self) -> Option<LoopControl>
Take (consume) any pending loop-control request. Returns None when
nothing is pending.
Sourcepub fn poll_watch(&mut self) -> Option<String>
pub fn poll_watch(&mut self) -> Option<String>
Poll the registered watch file for new bytes past the stored offset.
On success, advances the offset and returns the new content (capped at
WATCH_CHUNK_BYTES per call; remaining bytes surface on the next
poll). Returns None when no watch is set, the file is gone, or no new
bytes are available. Handles log rotation (file shrank) by resetting to
the start.
Sourcepub fn take_completed(&mut self) -> Option<(String, String)>
pub fn take_completed(&mut self) -> Option<(String, String)>
Remove and return the first completed job, if any.
Returns Some((job_id, output_string)) where output_string includes
the exit code and captured stdout/stderr. Completed jobs are removed
from the tracked set.
If a terminal job remains after this removal, the completion notify is
re-armed. update() uses notify_one(), which stores a single permit:
when ≥2 jobs reach a terminal state before a waiter polls, the second
notify_one() is a no-op, so a waiter that consumes the one permit
would never wake for the remaining job. Re-arming here guarantees every
completed job has a scheduled wake until it is drained (goal-379).