Skip to main content

JobContext

Struct JobContext 

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

What a job sees while it runs, on its own thread.

use ravenrs_app::{JobContext, Object};

fn count(job: &JobContext) -> Result<(), String> {
    for (done, record) in job.selected().iter().enumerate() {
        if job.cancelled() {
            return Ok(());
        }
        job.progress((done + 1) as f32 / job.selected().len() as f32, record.entity());
        let mut record = record.clone();
        record.set("Counted", true);
        job.save(record);
    }
    Ok(())
}

Implementations§

Source§

impl JobContext

Source

pub fn selected(&self) -> &[Object]

The records selected when it started, as they were then.

Source

pub fn input(&self) -> &ActionInput

What people gave the action.

Source

pub fn progress(&self, done: f32, doing: impl Into<String>)

How far it got, from 0 to 1, and what it is doing now.

Source

pub fn doing(&self, doing: impl Into<String>)

What it is doing, when it cannot tell how far it got.

Source

pub fn cancelled(&self) -> bool

Whether someone asked it to stop. It stops by returning; what it handed over stays.

Source

pub fn save(&self, record: Object)

Keeps this record, new or changed.

Source

pub fn delete(&self, record: Object)

Removes this record.

Source

pub fn tell(&self, text: impl Into<String>, kind: MessageKind)

Tells people something.

Trait Implementations§

Source§

impl Debug for JobContext

Source§

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

Formats the value using the given formatter. Read more

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.