Struct pueue_lib::state::State

source ·
pub struct State {
    pub tasks: BTreeMap<usize, Task>,
    pub groups: BTreeMap<String, Group>,
}
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§

§tasks: BTreeMap<usize, Task>

All tasks currently managed by the daemon.

§groups: BTreeMap<String, Group>

All groups with their current state a configuration.

Implementations§

source§

impl State

source

pub fn new() -> State

Create a new default state.

source

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

Add a new task

source

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

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

source

pub fn create_group(&mut self, name: &str) -> &mut Group

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.

source

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

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

source

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

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

source

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

Get all ids of task inside a specific group.

source

pub fn filter_tasks<F>( &self, condition: F, task_ids: Option<Vec<usize>> ) -> FilteredTasks
where F: Fn(&Task) -> bool,

This checks, whether some tasks match the expected filter criteria.
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.

source

pub fn filter_tasks_of_group<F>( &self, condition: F, group: &str ) -> FilteredTasks
where F: Fn(&Task) -> bool,

Same as State::filter_tasks, but only checks for tasks of a specific group.

Trait Implementations§

source§

impl Clone for State

source§

fn clone(&self) -> State

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for State

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for State

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for State

source§

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

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for State

source§

fn eq(&self, other: &State) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for State

source§

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

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for State

source§

impl StructuralPartialEq for State

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnwindSafe for State

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

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