Skip to main content
Version: 3.3

ApifyRequestQueueSingleClient

Internal request queue client implementation for single-consumer scenarios on the Apify platform.

This implementation minimizes API calls and resource usage by leveraging local caching and head estimation. It is designed for scenarios where only one client consumes requests from the queue at a time, though multiple producers may add requests concurrently.

Usage constraints

This client must operate within the following constraints to function correctly:

  • Single consumer: Only one client should be consuming (fetching) requests from the queue at any given time.
  • Multiple producers allowed: Multiple clients can add requests concurrently, but their forefront requests may not be prioritized immediately since this client relies on local head estimation.
  • Append-only queue: Requests should only be added to the queue, never deleted by other clients. Marking requests as handled is permitted.
  • No external modifications: Other producers can add new requests but should not modify existing ones, as modifications won't be reflected in the local cache.

If these constraints are not met, the client may exhibit unpredictable behavior.

This class is used internally by ApifyRequestQueueClient when access='single' is specified.

Public methods are not individually documented as they implement the interface defined in RequestQueueClient.

Index

Methods

__init__

  • __init__(*, api_client, metadata, cache_size): None
  • Initialize a new single-consumer request queue client instance.

    Use ApifyRequestQueueClient.open(access='single') instead of calling this directly.


    Parameters

    • keyword-onlyapi_client: RequestQueueClientAsync

      The Apify API client for request queue operations.

    • keyword-onlymetadata: RequestQueueMetadata

      Initial metadata for the request queue.

    • keyword-onlycache_size: int

      Maximum number of requests to cache locally.

    Returns None

add_batch_of_requests

  • async add_batch_of_requests(requests, *, forefront): AddRequestsResponse
  • Specific implementation of this method for the RQ single access mode.


    Parameters

    • requests: Sequence[Request]
    • optionalkeyword-onlyforefront: bool = False

    Returns AddRequestsResponse

fetch_next_request

  • async fetch_next_request(): Request | None
  • Specific implementation of this method for the RQ single access mode.


    Returns Request | None

get_request

  • async get_request(unique_key): Request | None
  • Specific implementation of this method for the RQ single access mode.


    Parameters

    • unique_key: str

    Returns Request | None

is_empty

  • async is_empty(): bool
  • Specific implementation of this method for the RQ single access mode.


    Returns bool

mark_request_as_handled

  • async mark_request_as_handled(request): ProcessedRequest | None
  • Specific implementation of this method for the RQ single access mode.


    Parameters

    • request: Request

    Returns ProcessedRequest | None

reclaim_request

  • async reclaim_request(request, *, forefront): ProcessedRequest | None
  • Specific implementation of this method for the RQ single access mode.


    Parameters

    • request: Request
    • optionalkeyword-onlyforefront: bool = False

    Returns ProcessedRequest | None