Simple Queue based on MongoDb
- Free software: MIT license
- Documentation: https://mongodb-queue.readthedocs.io.
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)
- bulk writes?
- FIFO (by 'id')
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.