/mongodb_queue

Simple implementation of queue based on mongodb

Primary LanguagePythonMIT LicenseMIT

Very simple Mongodb Queue

image image Documentation Status Updates

Simple Queue based on MongoDb

Examples

from mongodb_queue.mongodb_queue import PayloadValidationError

class MongodbQueue(BaseMongodbQueue):
    _queue_name = 'some_queue'
    _payload_schema = {
        'key': {'type': 'string', 'required': True},
        'required_value': {'type': 'string', 'required': True},
        'default_value': {'type': 'string', 'default': 'nope'},
    }

client = pymongo.MongoClient()

q = MongodbQueue(client, 'mongodb_queue')
q.sort_by = [('created_at', 1)]

# add element to the queue
q.put({'key': '12', 'required_value': 'here'})

for key in range(6):
    payload = {
        'key': str(key),
        'required_value': 'yes' if key % 2 == 0 else 'nope',
        'default_value': 'yes!'
    }
    task = q.put(payload, priority=key)

assert q.size() == 7

# get 3 documents not yet processed
tasks = q.get(3)

Features

  • bulk writes?
  • FIFO (by 'id')

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.