Skip to main content

A queue using mongo as backend storage.

Project description

mongoqueue
----------

Properties
==========

- Isolation

Do not let different consumers process the same message.

- Reliablity

Do not let a failed consumer disappear an item.

- Atomic

Operations on the queue are atomic.

Usage
=====

A queue can be instantiated with a mongo collection and a consumer
identifier. The consumer identifier helps distinguish multiple queue
consumers that are taking jobs from the queue.

>> from pymongo import Connection
>> from mongoqueue import MongoQueue
>> queue = MongoQueue(
... Connection(TEST_DB).doctest_queue,
... consumer_id="consumer-1",
... timeout=300,
... max_attempts=3)

The ``MongoQueue`` class ``timeout`` parameters specifies how long in a
seconds a how long a job may be held by a consumer before its
considered failed.

A job which timeouts or errors more than the ``max_attempts``
parameter is considered permanently failed, and will no longer be
processed.

New jobs/items can be placed in the queue by passing a dictionary.

>> queue.put({"foobar": 1})

A job ``priority`` key and integer value can be specified in the
dictionary which will cause the job to be processed before lower
priority items.

>> queue.put({"foobar": 0, "priority": 1})

An item can be fetched out by calling the ``next`` method on a queue.
This returns a Job object.

>> job = queue.next()
>> job.data
{"foobar": 1}

The job class exposes some control methods on the job, for marking progress,
completion, errors, or releasing the job back into the queue.

- ``complete`` Marks a job as complete and removes it from the queue.

- ``error`` Optionally specified with a message, releases the job back to the
queue, and increments its attempts, and stores the error message on the job.

- ``progress`` Optionally takes a progress count integer, notes progress on the job
and resets the lock timeout.

- ``release`` Release a job back to the pool. The attempts counter is not modified.

As a convience the job supports the context manager protocol.

>> with job as data:
... print data

{"foobar: 0}

If the context closure is exited without the job is marked complete,
if there's an exception the error is stored on the job.


Inspired By
===========

[0] https://github.com/skiz/mongo_queue/blob/master/lib/mongo_queue.rb
[1] http://blog.boxedice.com/2011/09/28/replacing-rabbitmq-with-mongodb/
[2] http://blog.boxedice.com/2011/04/13/queueing-mongodb-using-mongodb/
[3] https://github.com/lunaru/mongoqueue
[4] http://www.captaincodeman.com/2011/05/28/simple-service-bus-message-queue-mongodb/


Running

Fully Configurable

Distributed

Atomic Locking

Thread Safe

Priority Support

Worker Timeout Support

Fully Tested

Production Ready

Simple API


--------------------------



Per Queue error queues

Max attempts per item


Identity in queue.

---------------------------

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongoqueue-0.5.0.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file mongoqueue-0.5.0.tar.gz.

File metadata

  • Download URL: mongoqueue-0.5.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mongoqueue-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c07c82b2bd132390dd6c29c94dda846c18ea1e1b3be848ea18002642fa0f47fe
MD5 bb77d2991f77154e4ce75adc135edc06
BLAKE2b-256 64f6798270dc6f3e649670d682fd6cdf60dbd02620152b5c4b3282fe7274e34b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page