Skip to main content

TaskStore

Struct TaskStore 

Source
pub struct TaskStore { /* private fields */ }
Expand description

A store for managing tasks with JSONL persistence and file locking.

Implementations§

Source§

impl TaskStore

Source

pub fn load(path: &Path) -> Result<Self>

Loads tasks from the JSONL file at the given path.

If the file doesn’t exist, returns an empty store. Logs warnings for malformed JSON lines and skips them.

Uses a shared lock to allow concurrent reads from multiple loops.

Source

pub fn save(&self) -> Result<()>

Saves all tasks to the JSONL file.

Creates parent directories if they don’t exist. Uses an exclusive lock to prevent concurrent writes.

Source

pub fn reload(&mut self) -> Result<()>

Reloads tasks from disk, useful after external modifications.

Logs warnings for malformed JSON lines and skips them. Uses a shared lock to allow concurrent reads.

Source

pub fn with_exclusive_lock<F, T>(&mut self, f: F) -> Result<T>
where F: FnOnce(&mut Self) -> T,

Executes a read-modify-write operation atomically.

Acquires an exclusive lock, reloads from disk, executes the provided function, and saves back to disk. This ensures that concurrent modifications from other loops are not lost.

§Example
store.with_exclusive_lock(|store| {
    let task = Task::new("New task".to_string(), 1);
    store.add(task);
})?;
Source

pub fn add(&mut self, task: Task) -> &Task

Adds a new task to the store and returns a reference to it.

Source

pub fn get(&self, id: &str) -> Option<&Task>

Gets a task by ID (immutable reference).

Source

pub fn get_by_key(&self, key: &str) -> Option<&Task>

Gets a task by stable key (immutable reference).

Source

pub fn get_mut(&mut self, id: &str) -> Option<&mut Task>

Gets a task by ID (mutable reference).

Source

pub fn get_by_key_mut(&mut self, key: &str) -> Option<&mut Task>

Gets a task by stable key (mutable reference).

Source

pub fn close(&mut self, id: &str) -> Option<&Task>

Closes a task by ID and returns a reference to it.

Source

pub fn start(&mut self, id: &str) -> Option<&Task>

Starts a task by ID and returns a reference to it.

Source

pub fn fail(&mut self, id: &str) -> Option<&Task>

Fails a task by ID and returns a reference to it.

Source

pub fn reopen(&mut self, id: &str) -> Option<&Task>

Reopens a task by ID and returns a reference to it.

Source

pub fn ensure(&mut self, task: Task) -> &Task

Ensures a task exists for a stable key, returning the existing or created task.

If a task with the same key already exists, its non-lifecycle metadata is refreshed and the existing task is returned.

Source

pub fn all(&self) -> &[Task]

Returns all tasks as a slice.

Source

pub fn open(&self) -> Vec<&Task>

Returns all open tasks (not closed).

Source

pub fn ready(&self) -> Vec<&Task>

Returns all ready tasks (open with no pending blockers).

Source

pub fn has_open_tasks(&self) -> bool

Returns true if there are any open tasks.

A task is considered open if it is not Closed. This includes Failed tasks.

Source

pub fn has_pending_tasks(&self) -> bool

Returns true if there are any pending (non-terminal) tasks.

A task is pending if its status is not terminal (i.e., not Closed or Failed). Use this when you need to check if there’s active work remaining.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more