Skip to main content

HostDelay

Struct HostDelay 

Source
pub struct HostDelay { /* private fields */ }
Expand description

The gap between starting two requests to the same host, see Crawler::with_host_delay: at least a minimum, growing towards a maximum while the host is throttled.

A host is throttled when it answers 429 Too Many Requests or 503 Service Unavailable, or a request to it times out. Once its concurrency cannot go lower, at a fixed limit or at one with HostConcurrency::adaptive, each round of throttling doubles its gap, from the minimum, or one second without one, up to the maximum. Each success halves it back to the minimum. A Retry-After from the host pauses it for exactly as long as it asks, beyond the maximum if need be, without widening its gap. The next request waits for the gap after the last one started, as the gap is when it is due, so a widened gap applies at once.

A Duration is the minimum, with the default maximum. A range sets both ends; the same value at both ends keeps the gap fixed.

use std::time::Duration;

use spire_core::crawler::Crawler;
use spire_core::backend::Noop;
use spire_core::worker::from_fn;

let worker = from_fn(|_: spire_core::Context<Noop>| async {});
let crawler = Crawler::new(Noop, worker)
    .with_host_delay(Duration::from_millis(200)..=Duration::from_secs(300));

Implementations§

Source§

impl HostDelay

Source

pub const DEFAULT_MAX: Duration

The maximum gap when only a minimum is given: one request a minute.

Source

pub fn new(min: Duration, max: Duration) -> Self

A gap of at least min, growing up to max, or min if max is smaller.

Source

pub const fn min(self) -> Duration

Returns the smallest gap.

Source

pub const fn max(self) -> Duration

Returns the largest gap.

Trait Implementations§

Source§

impl Clone for HostDelay

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for HostDelay

Source§

impl Debug for HostDelay

Source§

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

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

impl Default for HostDelay

Source§

fn default() -> Self

No gap, growing up to DEFAULT_MAX while a host is throttled.

Source§

impl Eq for HostDelay

Source§

impl From<Duration> for HostDelay

Source§

fn from(min: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<RangeInclusive<Duration>> for HostDelay

Source§

fn from(range: RangeInclusive<Duration>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for HostDelay

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HostDelay

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<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<W> WorkerExt for W

Source§

fn layer<C, M>(self, middleware: M) -> Layered<M, C>
where C: Send + 'static, Self: Worker<C>, M: Middleware<C>,

Wraps this worker in middleware, which runs before it, and before any middleware added earlier.