Struct apalis_core::request::JobRequest
source · [−]pub struct JobRequest<T> { /* private fields */ }Expand description
Represents a job which can be serialized and executed
Implementations
sourceimpl<T> JobRequest<T>
impl<T> JobRequest<T>
sourcepub fn new(job: T) -> Self
pub fn new(job: T) -> Self
Creates a new JobRequest
sourcepub fn new_with_context(job: T, ctx: JobContext) -> Self
pub fn new_with_context(job: T, ctx: JobContext) -> Self
Creates a Job request with context provided
sourcepub fn context_mut(&mut self) -> &mut JobContext
pub fn context_mut(&mut self) -> &mut JobContext
Gets a mutable reference to the job context.
sourcepub fn context(&self) -> &JobContext
pub fn context(&self) -> &JobContext
Gets a reference to the job context.
sourcepub fn record_attempt(&mut self)
pub fn record_attempt(&mut self)
Records a job attempt
Methods from Deref<Target = 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<T: Clone> Clone for JobRequest<T>
impl<T: Clone> Clone for JobRequest<T>
sourcefn clone(&self) -> JobRequest<T>
fn clone(&self) -> JobRequest<T>
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<T: Debug> Debug for JobRequest<T>
impl<T: Debug> Debug for JobRequest<T>
sourceimpl<T> Deref for JobRequest<T>
impl<T> Deref for JobRequest<T>
type Target = JobContext
type Target = JobContext
The resulting type after dereferencing.
sourceimpl<T> DerefMut for JobRequest<T>
impl<T> DerefMut for JobRequest<T>
sourceimpl<'de, T> Deserialize<'de> for JobRequest<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for JobRequest<T> where
T: Deserialize<'de>,
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<T> Policy<JobRequest<T>, JobResult, JobError> for DefaultRetryPolicy where
T: Clone,
Available on crate feature retry only.
impl<T> Policy<JobRequest<T>, JobResult, JobError> for DefaultRetryPolicy where
T: Clone,
retry only.type Future = Ready<DefaultRetryPolicy>
type Future = Ready<DefaultRetryPolicy>
The Future type returned by Policy::retry.
sourcefn retry(
&self,
req: &JobRequest<T>,
result: Result<&JobResult, &JobError>
) -> Option<Self::Future>
fn retry(
&self,
req: &JobRequest<T>,
result: Result<&JobResult, &JobError>
) -> Option<Self::Future>
Check the policy if a certain request should be retried. Read more
sourcefn clone_request(&self, req: &JobRequest<T>) -> Option<JobRequest<T>>
fn clone_request(&self, req: &JobRequest<T>) -> Option<JobRequest<T>>
Tries to clone a request before being passed to the inner service. Read more
sourceimpl<T> Serialize for JobRequest<T> where
T: Serialize,
impl<T> Serialize for JobRequest<T> where
T: Serialize,
sourceimpl<J, S, T> Service<JobRequest<J>> for AddExtension<S, T> where
S: Service<JobRequest<J>>,
T: Clone + Send + Sync + 'static,
Available on crate feature extensions only.
impl<J, S, T> Service<JobRequest<J>> for AddExtension<S, T> where
S: Service<JobRequest<J>>,
T: Clone + Send + Sync + 'static,
extensions only.type Response = <S as Service<JobRequest<J>>>::Response
type Response = <S as Service<JobRequest<J>>>::Response
Responses given by the service.
type Error = <S as Service<JobRequest<J>>>::Error
type Error = <S as Service<JobRequest<J>>>::Error
Errors produced by the service.
type Future = <S as Service<JobRequest<J>>>::Future
type Future = <S as Service<JobRequest<J>>>::Future
The future response value.
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
sourcefn call(&mut self, req: JobRequest<J>) -> Self::Future
fn call(&mut self, req: JobRequest<J>) -> Self::Future
Process the request and return the response asynchronously. Read more
sourceimpl<S, J, F> Service<JobRequest<J>> for PrometheusService<S> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F>,
F: Future<Output = Result<JobResult, JobError>> + 'static,
J: Job,
Available on crate feature prometheus only.
impl<S, J, F> Service<JobRequest<J>> for PrometheusService<S> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F>,
F: Future<Output = Result<JobResult, JobError>> + 'static,
J: Job,
prometheus only.type Response = <S as Service<JobRequest<J>>>::Response
type Response = <S as Service<JobRequest<J>>>::Response
Responses given by the service.
type Error = <S as Service<JobRequest<J>>>::Error
type Error = <S as Service<JobRequest<J>>>::Error
Errors produced by the service.
type Future = ResponseFuture<F>
type Future = ResponseFuture<F>
The future response value.
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
sourcefn call(&mut self, request: JobRequest<J>) -> Self::Future
fn call(&mut self, request: JobRequest<J>) -> Self::Future
Process the request and return the response asynchronously. Read more
sourceimpl<S, J, F> Service<JobRequest<J>> for SentryJobService<S> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F>,
F: Future<Output = Result<JobResult, JobError>> + 'static,
J: Job,
Available on crate feature sentry only.
impl<S, J, F> Service<JobRequest<J>> for SentryJobService<S> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F>,
F: Future<Output = Result<JobResult, JobError>> + 'static,
J: Job,
sentry only.type Response = <S as Service<JobRequest<J>>>::Response
type Response = <S as Service<JobRequest<J>>>::Response
Responses given by the service.
type Error = <S as Service<JobRequest<J>>>::Error
type Error = <S as Service<JobRequest<J>>>::Error
Errors produced by the service.
type Future = SentryHttpFuture<<S as Service<JobRequest<J>>>::Future>
type Future = SentryHttpFuture<<S as Service<JobRequest<J>>>::Future>
The future response value.
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
sourcefn call(&mut self, request: JobRequest<J>) -> Self::Future
fn call(&mut self, request: JobRequest<J>) -> Self::Future
Process the request and return the response asynchronously. Read more
sourceimpl<J, S, OnRequestT, OnResponseT, OnFailureT, MakeSpanT, F> Service<JobRequest<J>> for Trace<S, MakeSpanT, OnRequestT, OnResponseT, OnFailureT> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F> + Unpin + Send + 'static,
S::Error: Display + 'static,
MakeSpanT: MakeSpan<J>,
OnRequestT: OnRequest<J>,
OnResponseT: OnResponse + Clone + 'static,
F: Future<Output = Result<JobResult, JobError>> + 'static,
OnFailureT: OnFailure + Clone + 'static,
Available on crate feature trace only.
impl<J, S, OnRequestT, OnResponseT, OnFailureT, MakeSpanT, F> Service<JobRequest<J>> for Trace<S, MakeSpanT, OnRequestT, OnResponseT, OnFailureT> where
S: Service<JobRequest<J>, Response = JobResult, Error = JobError, Future = F> + Unpin + Send + 'static,
S::Error: Display + 'static,
MakeSpanT: MakeSpan<J>,
OnRequestT: OnRequest<J>,
OnResponseT: OnResponse + Clone + 'static,
F: Future<Output = Result<JobResult, JobError>> + 'static,
OnFailureT: OnFailure + Clone + 'static,
trace only.type Future = ResponseFuture<F, OnResponseT, OnFailureT>
type Future = ResponseFuture<F, OnResponseT, OnFailureT>
The future response value.
sourcefn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
sourcefn call(&mut self, req: JobRequest<J>) -> Self::Future
fn call(&mut self, req: JobRequest<J>) -> Self::Future
Process the request and return the response asynchronously. Read more
sourceimpl<T, F, Request> Service<JobRequest<Request>> for JobFn<T> where
Request: Debug + 'static,
T: Fn(Request, JobContext) -> F,
F: Future<Output = Result<JobResult, JobError>> + 'static,
Request: Job,
impl<T, F, Request> Service<JobRequest<Request>> for JobFn<T> where
Request: Debug + 'static,
T: Fn(Request, JobContext) -> F,
F: Future<Output = Result<JobResult, JobError>> + 'static,
Request: Job,
type Future = JobFnHttpFuture<F>
type Future = JobFnHttpFuture<F>
The future response value.
sourcefn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
sourcefn call(&mut self, job: JobRequest<Request>) -> Self::Future
fn call(&mut self, job: JobRequest<Request>) -> Self::Future
Process the request and return the response asynchronously. Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for JobRequest<T>
impl<T> Send for JobRequest<T> where
T: Send,
impl<T> Sync for JobRequest<T> where
T: Sync,
impl<T> Unpin for JobRequest<T> where
T: Unpin,
impl<T> !UnwindSafe for JobRequest<T>
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