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
impl JobContext
Sourcepub fn input(&self) -> &ActionInput
pub fn input(&self) -> &ActionInput
What people gave the action.
Sourcepub fn progress(&self, done: f32, doing: impl Into<String>)
pub fn progress(&self, done: f32, doing: impl Into<String>)
How far it got, from 0 to 1, and what it is doing now.
Sourcepub fn doing(&self, doing: impl Into<String>)
pub fn doing(&self, doing: impl Into<String>)
What it is doing, when it cannot tell how far it got.
Sourcepub fn cancelled(&self) -> bool
pub fn cancelled(&self) -> bool
Whether someone asked it to stop. It stops by returning; what it handed over stays.
Sourcepub fn tell(&self, text: impl Into<String>, kind: MessageKind)
pub fn tell(&self, text: impl Into<String>, kind: MessageKind)
Tells people something.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JobContext
impl RefUnwindSafe for JobContext
impl Send for JobContext
impl Sync for JobContext
impl Unpin for JobContext
impl UnsafeUnpin for JobContext
impl UnwindSafe for JobContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more