Converts the iterable into a caching generator.
Returns a proxy that yields each item of iterable, while at the same time caching those items in a deque.
Parameters: | iterable – an iterable to wrap in a caching generator |
---|---|
Returns: | (proxy(iterable), cached_items) |
Calculates backoff time, in seconds, when retrying an operation.
This function calculates a simple linear backoff time with optional jitter, useful for retrying a request under high concurrency.
The result may be passed directly into time.sleep() in order to mitigate stampeding herd syndrome and introduce backpressure towards the clients, slowing them down.
Parameters: |
|
---|---|
Raises: | ValueError |
Returns: | float representing the number of seconds to sleep, within the interval [0, max_sleep), determined linearly according to the ratio attempt / max_attempts, with optional jitter. |
Returns the unscoped queue name, given a fully-scoped name.
Get the partition number for a given queue and project.
Hashes the queue to a partition number. The hash is stable, meaning given the same queue name and project ID, the same partition number will always be returned. Note also that queues will be uniformly distributed across partitions.
The number of partitions is taken from the “partitions” property in the config file, under the [drivers:storage:mongodb] section.
Returns ‘’ IFF given value is None, passthrough otherwise.
This function normalizes None to the empty string to facilitate string concatenation when a variable could be None.
Converts an ObjectId to a UNIX timestamp.
Raises: | TypeError if oid isn’t an ObjectId |
---|
Returns the project and queue name for a scoped catalogue entry.
Parameters: | scoped_name (six.text_type) – a project/queue as given by :scope_queue_name: |
---|---|
Returns: | (project, queue) |
Return type: | (six.text_type, six.text_type) |
Handles the MongoDB ConnectionFailure error.
This decorator catches MongoDB’s ConnectionFailure error and raises Zaqar’s ConnectionError instead.
Causes the wrapped function to be re-called on AutoReconnect.
This decorator catches MongoDB’s AutoReconnect error and retries the function call.
Note
Assumes that the decorated function has defined self.driver.mongodb_conf so that max_reconnect_attempts and reconnect_sleep can be taken into account.
Warning
The decorated function must be idempotent.
Returns a scoped name for a queue based on project and queue.
If only the project name is specified, a scope signifying “all queues” for that project is returned. If neither queue nor project are specified, a scope for “all global queues” is returned, which is to be interpreted as excluding queues scoped by project.
Returns: | ‘{project}/{queue}’ if project and queue are given, ‘{project}/’ if ONLY project is given, ‘/{queue}’ if ONLY queue is given, and ‘/’ if neither are given. |
---|
Returns a dict usable for querying for scoped project/queues.
Parameters: |
|
---|---|
Returns: | query to issue |
Return type: | dict |
Creates a stat document from the given message, relative to now.
Creates a new ObjectId based on the input.
Returns None when TypeError or berrors.InvalidId is raised by the ObjectId class.
Parameters: | obj – Anything that can be passed as an input to objectid.ObjectId |
---|