BackoffSchedule

Struct BackoffSchedule 

Source
pub struct BackoffSchedule<B> { /* private fields */ }
Available on crate feature backoff only.
Expand description

Backs off using a BackoffSchedule from the backoff crate.

Implemented for tasks returning a Result. If the result is Ok, the backoff will be reset. If the result is Err, or the job panics, the backoff increments.

Implementations§

Source§

impl<B: Backoff> BackoffSchedule<B>

Source

pub fn from_backoff(backoff: B) -> Self

Creates a BackoffSchedule using the given backoff policy.

use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use periodically::{Schedule, BackoffSchedule};
use std::time::Duration;

let backoff: ExponentialBackoff = ExponentialBackoffBuilder::new().build();
let backoff_schedule = BackoffSchedule::from_backoff(backoff);
assert_eq!(backoff_schedule.initial(), Some(Duration::from_secs(0)));
assert!(backoff_schedule.next(Err(())).unwrap() < Duration::from_secs(1));

Trait Implementations§

Source§

impl<T, E, B: Backoff + Send> Schedule<Result<T, E>> for BackoffSchedule<B>

Source§

fn next(&self, task_output: Result<T, E>) -> Option<Duration>

Returns the time until this task should be scheduled again. None indicates that this task should never run again. task_output is the last return value of the task, which can be ignored if desired.
Source§

fn next_on_task_panic(&self) -> Option<Duration>

Returns the time until this task should be scheduled again. Only called when the previous task execution fails to return a value. By default, implemented as Schedule::initial.
Source§

fn initial(&self) -> Option<Duration>

How long to wait for the initial execution. Exists since the task’s output is not available initially. Can be used to control initial task execution delays.

Auto Trait Implementations§

§

impl<B> !Freeze for BackoffSchedule<B>

§

impl<B> !RefUnwindSafe for BackoffSchedule<B>

§

impl<B> Send for BackoffSchedule<B>
where B: Send,

§

impl<B> !Sync for BackoffSchedule<B>

§

impl<B> Unpin for BackoffSchedule<B>
where B: Unpin,

§

impl<B> UnwindSafe for BackoffSchedule<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V