Skip to main content
Version: Next

RequestManagerTandem

A request manager that combines a IRequestLoader (such as a RequestList) with a writable IRequestManager (such as a RequestQueue). It first reads requests from the loader and then, when needed, transfers them in batches to the manager.

Implements

Index

Constructors

constructor

Methods

[asyncIterator]

  • Can be used to iterate over the loader instance in a for await .. of loop. Provides an alternative for the repeated use of fetchNextRequest.


    Returns AsyncGenerator<CrawleeRequest<Dictionary>, void, unknown>

addRequest

addRequestsBatched

checkReadiness

  • Reports whether the loader has a request to hand over, is waiting on one, or is done — see RequestSourceStatus.

    A consumer's task loop is gated on this, so implementations MUST answer ready before evaluating anything else. finished may arrive late behind distributed storage, but it is never wrong.


    Returns Promise<RequestSourceStatus>

fetchNextRequest

  • Gets the next Request to process, or null if there are no more pending requests.

    The returned request is marked as in progress and remains so until it is passed to IRequestLoader.markRequestAsHandled. The caller is responsible for eventually marking every fetched request as handled; otherwise the loader never considers itself finished and the request may be re-served after a restart. See the request lifecycle contract on IRequestLoader.


    Returns Promise<null | CrawleeRequest<T>>

getHandledCount

  • getHandledCount(): Promise<number>
  • Returns the number of requests in the loader that have been handled.


    Returns Promise<number>

getPendingCount

  • getPendingCount(): Promise<number>
  • Returns an approximation of the number of pending requests in the loader.


    Returns Promise<number>

getTotalCount

  • getTotalCount(): Promise<number>
  • Returns an approximation of the total number of requests in the loader (i.e. pending + handled).


    Returns Promise<number>

markRequestAsHandled

  • Marks a request previously returned by IRequestLoader.fetchNextRequest as handled, removing it from the set of in-progress requests.

    Call this once you are done with the request — whether processing succeeded or was abandoned after exhausting retries. Because a loader cannot take a request back, marking it handled is the only way to signal completion; failing to do so prevents IRequestLoader.checkReadiness from ever reporting finished and skews the handled and pending counts. See the request lifecycle contract on IRequestLoader.


    Parameters

    Returns Promise<null | void | RequestQueueOperationInfo>

persistState

  • persistState(): Promise<void>
  • Persists the current state of the loader into the default KeyValueStore.

    Not all loaders support persistence; implementations that do not should leave this undefined.


    Returns Promise<void>

purge

  • purge(): Promise<void>
  • Remove all requests from the queue but keep the queue itself, resetting it so it can be reused (e.g. across multiple crawler.run() calls).

    Implementations that do not support purging may leave this undefined.


    Returns Promise<void>

reclaimRequest

recordPacingSignal

  • recordPacingSignal(signal): boolean
  • Records something said about the pace requests should go out at, so that a manager which paces its own dispatch can hold requests back.

    Required rather than optional, so that a wrapping manager always forwards it and a pacer nested in a composition still receives it; a manager that does not pace returns false.


    Parameters

    Returns boolean

    true if anything in the composition took responsibility for the signal.

setExpectedRequestProcessingTimeSecs

  • setExpectedRequestProcessingTimeSecs(secs): Promise<void>
  • Tells the manager how long a consumer expects to hold a request fetched via fetchNextRequest() before marking it handled or reclaiming it (typically the request-handler timeout plus padding).

    Managers backed by a storage backend that reserves requests via locking use this to avoid handing the same request out again while it is still being processed. Implementations that do not need this hint may leave it undefined.


    Parameters

    • secs: number

    Returns Promise<void>