RequestQueueBackend
Index
Methods
addBatchOfRequests
Add a batch of requests to the queue.
Each request is deduplicated by its
uniqueKey. Duplicates are reported in the result but not re-added. Withforefront, requests are placed at the beginning of the queue so they are processed sooner.Parameters
requests: RequestSchema[]
optionaloptions: RequestQueueOperationOptions
Returns Promise<BatchAddRequestsResult>
drop
Remove the request queue and all its data.
Returns Promise<void>
fetchNextRequest
Return the next request in the queue to be processed, or
undefinedif there are currently no pending requests.The returned request is marked as in-progress; it will not be returned again until it is either reclaimed via reclaimRequest or marked as handled via markRequestAsHandled.
An
undefinedreturn value does not mean processing is finished — only that there are no pending requests right now. Use isEmpty (together with the frontend's knowledge of pending add operations) to determine whether the queue is truly finished.Returns Promise<undefined | UpdateRequestSchema>
getMetadata
Returns metadata about the request queue (id, name, timestamps, request counts, etc.).
Implementations should throw if the underlying storage no longer exists (e.g. it was deleted externally). This method should never return stale data for a storage that has been removed.
Returns Promise<RequestQueueInfo>
getRequest
Retrieve a request from the queue by its
uniqueKey, orundefinedif it does not exist.Parameters
uniqueKey: string
Returns Promise<undefined | UpdateRequestSchema>
isEmpty
Resolves to
trueif the next call to fetchNextRequest would returnundefined— i.e. there are no pending requests to fetch right now.Requests that are currently in progress (fetched but not yet handled or reclaimed, including requests locked by other clients sharing the same queue) are not counted. An empty queue therefore does not mean crawling is finished — those in-progress requests may still be reclaimed, and background tasks may still add more requests. Use isFinished to detect completion.
Returns Promise<boolean>
isFinished
Resolves to
trueonly when there is no outstanding work left in the queue at all — i.e. there are no pending requests to fetch and no requests currently in progress (fetched but not yet handled or reclaimed, including requests locked by other clients sharing the same queue).This is the strong counterpart of isEmpty: a queue whose only remaining requests are in progress is empty (nothing to fetch) but not finished (that work might still be reclaimed). It is the building block for determining whether crawling is done — though a frontend may still need to account for its own pending background add operations on top of this.
Returns Promise<boolean>
markRequestAsHandled
Mark a request previously returned by fetchNextRequest as handled.
Handled requests are never returned again by fetchNextRequest. Returns information about the operation, or
undefinedif the request was not in progress.An
undefinedresult is a no-op, not an error: the request is simply not something this client is currently processing, so nothing is changed and the request is never added to the queue as a side effect. (Marking an already-handled request is idempotent and still returns operation info withwasAlreadyHandled: truerather thanundefined.)Parameters
request: UpdateRequestSchema
Returns Promise<undefined | QueueOperationInfo>
purge
Remove all requests from the queue but keep the queue itself.
Returns Promise<void>
reclaimRequest
Reclaim a failed request back to the queue so it can be processed again by a later call to fetchNextRequest. With
forefront, the request is returned to the beginning of the queue. Returns information about the operation, orundefinedif the request was not in progress.The request is expected to already be present in the queue (it should have been obtained via fetchNextRequest); reclaiming releases its lock rather than inserting it. An
undefinedresult is a no-op, not an error: the request is simply not something this client is currently processing, so nothing is changed and the request is never added to the queue as a side effect. Use addBatchOfRequests to insert a new request.Parameters
request: UpdateRequestSchema
optionaloptions: RequestQueueOperationOptions
Returns Promise<undefined | QueueOperationInfo>
optionalsetExpectedRequestProcessingTimeSecs
Tells the client how long (in seconds) a consumer expects to hold a request fetched via fetchNextRequest before marking it handled or reclaiming it — typically the consumer's request-processing timeout plus some padding.
A client that coordinates consumers via locking uses this to keep the request reserved for at least this long, so that a long-running consumer does not have its request handed out again while it is still being processed. Clients that do not lock may ignore it.
Parameters
secs: number
Returns Promise<void>
Operations on a single request queue.
A backend implementation owns all request bookkeeping (pending, in-progress, handled). Any coordination required between multiple distributed clients accessing the same queue (e.g. request locking on the Apify platform) is an internal concern of the implementation and is not exposed on this interface.