pub enum JobError {
Retryable(Box<dyn Error + Send + Sync + 'static>),
Fatal(Box<dyn Error + Send + Sync + 'static>),
Deferred {
delay: Duration,
reason: String,
},
}Expand description
Error returned by a crate::JobHandler.
Variants§
Retryable(Box<dyn Error + Send + Sync + 'static>)
Transient failure; the retry policy decides whether to retry.
Fatal(Box<dyn Error + Send + Sync + 'static>)
Permanent failure; go straight to dead-letter regardless of policy.
Deferred
Not a failure: the job could not run yet and must be tried again in delay.
The motivating case is an external API answering 429 Too Many Requests with
Retry-After: 30: nothing went wrong. The job has to wait exactly that
long and then run before the backlog that piled up meanwhile.
Unlike JobError::Retryable:
crate::Envelope::attemptis unchanged, so a deferral never burns down the retry budget and a job may defer itself indefinitely;- the retry policy is not consulted: neither its backoff (the handler
states the delay) nor its
max_attempts(nothing failed, so nothing is dead-lettered); crate::Envelope::deferralsis incremented and the envelope comes back with the highest priority its queue supports, ahead of normally enqueued work;- the worker logs it at
INFO, notWARN/ERROR.
There is no built-in cap: a handler that wants one inspects
crate::JobContext::deferrals and returns JobError::Fatal instead.
Implementations§
Source§impl JobError
impl JobError
Sourcepub fn retryable<E: Error + Send + Sync + 'static>(e: E) -> Self
pub fn retryable<E: Error + Send + Sync + 'static>(e: E) -> Self
Wrap e as a transient failure.
Sourcepub fn retryable_msg(msg: impl Into<String>) -> Self
pub fn retryable_msg(msg: impl Into<String>) -> Self
Transient failure with a plain message.
Sourcepub fn deferred(delay: Duration) -> Self
pub fn deferred(delay: Duration) -> Self
Defer the job by delay with the generic reason "deferred".
Not a failure: the attempt counter is untouched and the retry policy is not
consulted. See JobError::Deferred.
Sourcepub fn deferred_msg(delay: Duration, msg: impl Into<String>) -> Self
pub fn deferred_msg(delay: Duration, msg: impl Into<String>) -> Self
Defer the job by delay, recording why ("rate limited: Retry-After 30s").
Not a failure: the attempt counter is untouched and the retry policy is not
consulted. See JobError::Deferred.
Trait Implementations§
Source§impl Error for JobError
impl Error for JobError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()