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
}
Expand description

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, 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<(), Error>[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) -> Result<(), Error>[src]

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

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

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

pub fn save(&self) -> Result<(), Error>[src]

Convenience wrapper around save_to_file.

pub fn backup(&self) -> Result<(), Error>[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) -> Result<(), Error>[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]

fn clone(&self) -> State[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for State[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Serialize for State[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl RefUnwindSafe for State

impl Send for State

impl Sync for State

impl Unpin for State

impl UnwindSafe for State

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

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

Performs the conversion.

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.

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

Performs the conversion.

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

pub fn vzip(self) -> V

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