Skip to main content

Identities

Struct Identities 

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

The identities of a crawl, and how they are picked, set aside and replaced.

A request pinned with Seed::with_identity goes out as that identity; any other gets one picked in turn, at random, or per host.

An identity whose requests fail max_failures times in a row, through connection failures, timeouts, or 403, 407 or 429 answers, is taken out of use: a generated one is retired and replaced by the next, a listed one set aside for a while, longer each time.

Implementations§

Source§

impl Identities

Source

pub const DEFAULT_MAX_ACTIVE: usize = 16

The identities generated at once by default, see max_active.

Source

pub fn new(identities: impl IntoIterator<Item = Identity>) -> Self

Uses a fixed list of identities.

§Panics

Panics if identities is empty or two share a name.

Source

pub fn from_fn<F>(generate: F) -> Self
where F: Fn(u64) -> Result<Identity> + Send + Sync + 'static,

Builds identities on demand: identity n, counting from 0, from generate, e.g. a gateway’s session n, or the nth proxy of a list. Up to max_active are in use at once; one taken out of use is replaced by the next n.

Names should follow from n, so a resumed crawl builds the same identities again. A failure to build one fails the request that needed it.

Source

pub fn max_active(self, n: usize) -> Self

Generates at most n identities at once, created as requests need them, so a thousand cost nothing until used. Ignored for a fixed list.

§Panics

Panics if n is zero.

Source

pub const fn in_turn(self) -> Self

Picks identities in turn, one request each. This is the default.

Source

pub const fn at_random(self) -> Self

Picks an identity at random for every request.

Source

pub const fn sticky_per_host(self) -> Self

Keeps each host on one identity, as one visitor would be, for as long as that identity stays in use; a new host gets a new identity while fewer than max_active are.

Source

pub const fn retire_after_requests(self, n: u64) -> Self

Retires a generated identity after n requests, replacing it with the next.

Source

pub const fn retire_after(self, age: Duration) -> Self

Retires a generated identity once it is age old, replacing it with the next.

Source

pub fn max_failures(self, n: u32) -> Self

Takes an identity out of use after n failures in a row, 3 by default.

§Panics

Panics if n is zero.

Source

pub const fn rest(self, duration: Duration) -> Self

Sets a failing listed identity aside for duration the first time, one minute by default, and twice as long each time after.

Trait Implementations§

Source§

impl Clone for Identities

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 Debug for Identities

Source§

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

Formats the value using the given formatter. Read more

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.