pub struct JobRequest<T> { /* private fields */ }
Expand description

Represents a job which can be serialized and executed

Implementations§

source§

impl<T> JobRequest<T>

source

pub fn new(job: T) -> Self

Creates a new JobRequest

source

pub fn new_with_context(job: T, ctx: JobContext) -> Self

Creates a Job request with context provided

source

pub fn inner(&self) -> &T

Get the underlying reference of the job

source

pub fn record_attempt(&mut self)

Records a job attempt

Methods from Deref<Target = JobContext>§

source

pub fn data_opt<D: Any + Send + Sync>(&self) -> Option<&D>

Get an optional reference to a type previously inserted on this JobContext.

Example
let mut ctx = JobContext::new(JobId::new());
assert!(ctx.data_opt::<i32>().is_none());
ctx.insert(5i32);

assert_eq!(ctx.data_opt::<i32>(), Some(&5i32));
source

pub fn data<D: Any + Send + Sync>(&self) -> Result<&D, JobError>

Get a reference to a type previously inserted on this JobContext.

Errors

If the type requested is not in the JobContext

Example
let mut ctx = JobContext::new(JobId::new());
assert!(ctx.data::<i32>().is_err());
assert_eq!(
    ctx.data::<i32>().unwrap_err().to_string(),
    "MissingContext: Attempted to fetch context of i32. Did you add `.layer(Extension(i32))"
);
ctx.insert(5i32);

assert_eq!(ctx.data::<i32>().unwrap(), &5i32);
source

pub fn insert<D: Any + Send + Sync + Clone>(&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(JobId::new());
assert!(ctx.insert(5i32).is_none());
assert!(ctx.insert(4u8).is_none());
assert_eq!(ctx.insert(9i32), Some(5i32));
source

pub fn set_max_attempts(&mut self, max_attempts: i32)

Set the number of attempts

source

pub fn max_attempts(&self) -> i32

Gets the maximum attempts for a job. Default 25

source

pub fn id(&self) -> &JobId

Get the id for a job

source

pub fn attempts(&self) -> i32

Gets the current attempts for a job. Default 0

source

pub fn set_attempts(&mut self, attempts: i32)

Set the number of attempts

source

pub fn done_at(&self) -> &Option<DateTime<Utc>>

Get the time a job was done

source

pub fn set_done_at(&mut self, done_at: Option<DateTime<Utc>>)

Set the time a job was done

source

pub fn run_at(&self) -> &DateTime<Utc>

Get the time a job is supposed to start

source

pub fn set_run_at(&mut self, run_at: DateTime<Utc>)

Set the time a job should run

source

pub fn lock_at(&self) -> &Option<DateTime<Utc>>

Get the time a job was locked

source

pub fn set_lock_at(&mut self, lock_at: Option<DateTime<Utc>>)

Set the lock_at value

source

pub fn status(&self) -> &JobState

Get the job status

source

pub fn set_status(&mut self, status: JobState)

Set the job status

source

pub fn lock_by(&self) -> &Option<WorkerId>

Get the time a job was locked

source

pub fn set_lock_by(&mut self, lock_by: Option<WorkerId>)

Set lock_by

source

pub fn last_error(&self) -> &Option<String>

Get the time a job was locked

source

pub fn set_last_error(&mut self, error: String)

Set the last error

Trait Implementations§

source§

impl<T: Clone> Clone for JobRequest<T>

source§

fn clone(&self) -> JobRequest<T>

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<T: Debug> Debug for JobRequest<T>

source§

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

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

impl<T> Deref for JobRequest<T>

§

type Target = JobContext

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for JobRequest<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

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

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<J> HasJobContext for JobRequest<J>

source§

fn context_mut(&mut self) -> &mut JobContext

Gets a mutable reference to the job context.

source§

fn context(&self) -> &JobContext

Gets a reference to the job context.

source§

impl<T, Res> Policy<JobRequest<T>, Res, JobError> for DefaultRetryPolicywhere T: Clone,

Available on crate feature retry only.
§

type Future = Ready<DefaultRetryPolicy>

The Future type returned by Policy::retry.
source§

fn retry( &self, req: &JobRequest<T>, result: Result<&Res, &JobError> ) -> Option<Self::Future>

Check the policy if a certain request should be retried. Read more
source§

fn clone_request(&self, req: &JobRequest<T>) -> Option<JobRequest<T>>

Tries to clone a request before being passed to the inner service. Read more
source§

impl<T> Serialize for JobRequest<T>where T: Serialize,

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<SV, A, J> Service<JobRequest<J>> for AckService<SV, A, J>where SV: Service<JobRequest<J>> + Send + Sync + 'static, SV::Error: Error + Send + Sync + 'static, <SV as Service<JobRequest<J>>>::Future: Send + 'static, A: Ack<J> + Send + 'static + Clone + Sync, J: 'static, <SV as Service<JobRequest<J>>>::Response: Send, <A as Ack<J>>::Acknowledger: Sync + Send + Clone,

Available on crate feature extensions only.
§

type Response = <SV as Service<JobRequest<J>>>::Response

Responses given by the service.
§

type Error = <SV as Service<JobRequest<J>>>::Error

Errors produced by the service.
§

type Future = Pin<Box<dyn Future<Output = Result<<AckService<SV, A, J> as Service<JobRequest<J>>>::Response, <AckService<SV, A, J> as Service<JobRequest<J>>>::Error>> + Send>>

The future response value.
source§

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
source§

fn call(&mut self, request: JobRequest<J>) -> Self::Future

Process the request and return the response asynchronously. Read more
source§

impl<S, J, F, Res> Service<JobRequest<J>> for PrometheusService<S>where S: Service<JobRequest<J>, Response = Res, Error = JobError, Future = F>, F: Future<Output = Result<Res, JobError>> + 'static, J: Job,

Available on crate feature prometheus only.
§

type Response = <S as Service<JobRequest<J>>>::Response

Responses given by the service.
§

type Error = <S as Service<JobRequest<J>>>::Error

Errors produced by the service.
§

type Future = ResponseFuture<F>

The future response value.
source§

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
source§

fn call(&mut self, request: JobRequest<J>) -> Self::Future

Process the request and return the response asynchronously. Read more
source§

impl<S, J, F, Res> Service<JobRequest<J>> for SentryJobService<S>where S: Service<JobRequest<J>, Response = Res, Error = JobError, Future = F>, F: Future<Output = Result<Res, JobError>> + 'static, J: Job,

Available on crate feature sentry only.
§

type Response = <S as Service<JobRequest<J>>>::Response

Responses given by the service.
§

type Error = <S as Service<JobRequest<J>>>::Error

Errors produced by the service.
§

type Future = SentryHttpFuture<<S as Service<JobRequest<J>>>::Future>

The future response value.
source§

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
source§

fn call(&mut self, request: JobRequest<J>) -> Self::Future

Process the request and return the response asynchronously. Read more
source§

impl<J, S, OnRequestT, OnResponseT, OnFailureT, MakeSpanT, F, Res> Service<JobRequest<J>> for Trace<S, MakeSpanT, OnRequestT, OnResponseT, OnFailureT>where S: Service<JobRequest<J>, Response = Res, Error = JobError, Future = F> + Unpin + Send + 'static, S::Error: Display + 'static, MakeSpanT: MakeSpan<J>, OnRequestT: OnRequest<J>, OnResponseT: OnResponse<Res> + Clone + 'static, F: Future<Output = Result<Res, JobError>> + 'static, OnFailureT: OnFailure + Clone + 'static,

Available on crate feature trace only.
§

type Response = Res

Responses given by the service.
§

type Error = JobError

Errors produced by the service.
§

type Future = ResponseFuture<F, OnResponseT, OnFailureT>

The future response value.
source§

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
source§

fn call(&mut self, req: JobRequest<J>) -> Self::Future

Process the request and return the response asynchronously. Read more
source§

impl<T, F, Request, E, R> Service<JobRequest<Request>> for JobFn<T>where T: Fn(Request, JobContext) -> F, F: Future, F::Output: IntoResponse<Result = Result<R, E>>,

§

type Response = R

Responses given by the service.
§

type Error = E

Errors produced by the service.
§

type Future = Map<F, fn(_: <F as Future>::Output) -> Result<R, E>>

The future response value.
source§

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
source§

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

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