Struct apalis_core::context::JobContext
source · [−]pub struct JobContext { /* private fields */ }Expand description
The context for a job is represented here Used to provide a context when a job is defined through the [Job] trait
Implementations
sourceimpl JobContext
impl JobContext
sourcepub fn data_opt<D: Any + Send + Sync>(&self) -> Option<&D>
pub fn data_opt<D: Any + Send + Sync>(&self) -> Option<&D>
Get a reference to a type previously inserted on this JobContext.
Example
let mut ctx = JobContext::new(1.to_string());
assert!(ctx.data_opt::<i32>().is_none());
ctx.insert(5i32);
assert_eq!(ctx.data_opt::<i32>(), Some(&5i32));sourcepub fn insert<D: Any + Send + Sync>(&mut self, data: D) -> Option<D>
pub fn insert<D: Any + Send + Sync>(&mut self, data: D) -> Option<D>
Insert a type into this JobContext.
Important for embedding data for a job. If a extension of this type already existed, it will be returned.
Example
let mut ctx = JobContext::new(1.to_string());
assert!(ctx.insert(5i32).is_none());
assert!(ctx.insert(4u8).is_none());
assert_eq!(ctx.insert(9i32), Some(5i32));sourcepub fn set_max_attempts(&mut self, max_attempts: i32)
pub fn set_max_attempts(&mut self, max_attempts: i32)
Set the number of attempts
sourcepub fn max_attempts(&self) -> i32
pub fn max_attempts(&self) -> i32
Gets the maximum attempts for a job. Default 25
sourcepub fn set_attempts(&mut self, attempts: i32)
pub fn set_attempts(&mut self, attempts: i32)
Set the number of attempts
sourcepub fn set_done_at(&mut self, done_at: Option<DateTime<Utc>>)
pub fn set_done_at(&mut self, done_at: Option<DateTime<Utc>>)
Set the time a job was done
sourcepub fn set_run_at(&mut self, run_at: DateTime<Utc>)
pub fn set_run_at(&mut self, run_at: DateTime<Utc>)
Set the time a job should run
sourcepub fn set_lock_at(&mut self, lock_at: Option<DateTime<Utc>>)
pub fn set_lock_at(&mut self, lock_at: Option<DateTime<Utc>>)
Set the lock_at value
sourcepub fn set_status(&mut self, status: JobState)
pub fn set_status(&mut self, status: JobState)
Set the job status
sourcepub fn set_lock_by(&mut self, lock_by: Option<String>)
pub fn set_lock_by(&mut self, lock_by: Option<String>)
Set lock_by
sourcepub fn last_error(&self) -> &Option<String>
pub fn last_error(&self) -> &Option<String>
Get the time a job was locked
sourcepub fn set_last_error(&mut self, error: String)
pub fn set_last_error(&mut self, error: String)
Set the last error
Trait Implementations
sourceimpl Clone for JobContext
impl Clone for JobContext
sourcefn clone(&self) -> JobContext
fn clone(&self) -> JobContext
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for JobContext
impl Debug for JobContext
sourceimpl<'de> Deserialize<'de> for JobContext
impl<'de> Deserialize<'de> for JobContext
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Serialize for JobContext
impl Serialize for JobContext
Auto Trait Implementations
impl !RefUnwindSafe for JobContext
impl Send for JobContext
impl Sync for JobContext
impl Unpin for JobContext
impl !UnwindSafe for JobContext
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more