Struct pueue_lib::state::State[][src]

pub struct State {
    pub settings: Settings,
    pub tasks: BTreeMap<usize, Task>,
    pub groups: BTreeMap<String, GroupStatus>,
    // some fields omitted
}

This is the full representation of the current state of the Pueue daemon.

This includes

  • The currently used settings.
  • The full task list
  • The current status of all tasks
  • All known groups.

However, the State does NOT include:

  • Information about child processes
  • Handles to child processes

That information is saved in the daemon's TaskHandler.

Most functions implemented on the state shouldn't be used by third party software. The daemon is constantly changing and persisting the state.
Any changes applied to a state and saved to disk, will most likely be overwritten after a short time.

The daemon uses the state as a piece of shared memory between it's threads. It's wrapped in a MutexGuard, which allows us to guarantee sequential access to any crucial information, such as status changes and incoming commands by the client.

Fields

settings: Settings

The current settings used by the daemon.

tasks: BTreeMap<usize, Task>

All tasks currently managed by the daemon.

groups: BTreeMap<String, GroupStatus>

All groups

Implementations

impl State[src]

pub fn new(settings: &Settings, config_path: Option<PathBuf>) -> State[src]

Create a new default state.

pub fn add_task(&mut self, mut task: Task) -> usize[src]

Add a new task

pub fn change_status(&mut self, id: usize, new_status: TaskStatus)[src]

A small helper to change the status of a specific task.

pub fn set_enqueue_at(&mut self, id: usize, enqueue_at: Option<DateTime<Local>>)[src]

Set the time a specific task should be enqueued at.

pub fn create_group(&mut self, group: &str)[src]

Add a new group to the daemon.
This also check if the given group already exists. Create a state.group entry and a settings.group entry, if it doesn't.

pub fn remove_group(&mut self, group: &str) -> Result<()>[src]

Remove a group. This also iterates through all tasks and sets any tasks' group to the default group if it matches the deleted group.

pub fn set_status_for_all_groups(&mut self, status: GroupStatus)[src]

Set the group status (running/paused) for all groups including the default queue.

pub fn task_ids_in_group_with_stati(
    &self,
    group: &str,
    stati: Vec<TaskStatus>
) -> Vec<usize>
[src]

Get all ids of task with a specific state inside a specific group.

pub fn task_ids_in_group(&self, group: &str) -> Vec<usize>[src]

Get all ids of task inside a specific group.

pub fn tasks_in_statuses(
    &self,
    statuses: Vec<TaskStatus>,
    task_ids: Option<Vec<usize>>
) -> (Vec<usize>, Vec<usize>)
[src]

This checks, whether some tasks have one of the specified statuses.
The first result is the list of task_ids that match these statuses.
The second result is the list of task_ids that don't match these statuses.

By default, this checks all tasks in the current state. If a list of task_ids is provided as the third parameter, only those tasks will be checked.

pub fn is_task_removable(&self, task_id: &usize, to_delete: &[usize]) -> bool[src]

Check if a task can be deleted.
We have to check all dependant tasks, that haven't finished yet. This is necessary to prevent deletion of tasks which are specified as a dependency.

to_delete A list of task ids, which should also be deleted. This allows to remove dependency tasks as well as their dependants.

pub fn handle_task_failure(&mut self, group: String)[src]

A small helper for handling task failures.
Users can specify whether they want to pause the task's group or the whole daemon on a failed tasks. This function wraps that logic and decides if anything should be paused depending on the current settings.

group should be the name of the failed task.

pub fn reset(&mut self)[src]

Do a full reset of the state. This doesn't reset any processes!

pub fn save_settings(&self) -> Result<()>[src]

A small convenience wrapper for saving the settings to a file.

pub fn save(&self)[src]

Convenience wrapper around save_to_file.

pub fn backup(&self)[src]

Save the current current state in a file with a timestamp. At the same time remove old state logs from the log directory. This function is called, when large changes to the state are applied, e.g. clean/reset.

pub fn restore(&mut self)[src]

Restore the last state from a previous session.
The state is stored as json in the log directory.

Trait Implementations

impl Clone for State[src]

impl Debug for State[src]

impl<'de> Deserialize<'de> for State[src]

impl Serialize for State[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,