Queue service built on top of mongo.
Project description
mongo_queue
Task queue built on mongo with channels and unique job id.
Website • autobotAI Cloud Governance
Inspired from kapilt/mongoqueue
Change Log:
v0.0.3
- Added unique index with job_id and channel. This is to make sure that the same job is not added multiple times. If not job id provided an unique id generated by default.
Usage
Install the package.
pip install mongo_queue
Usage Example:
- Create Queue Object
from mongo_queue.queue import Queue
from pymongo import MongoClient
queue = Queue(MongoClient('localhost', 27017).task_queue, consumer_id="consumer-1", timeout=300, max_attempts=3)
- Add task to queue default channel
queue.put({"task_id": 1})
- Add task to queue with priority to default channel
queue.put({"task_id": 1}, priority=1)
- Add task to queue in a specific channel
queue.put({"task_id": 1}, priority=1, channel="channel_1")
- Add task to queue with unique job_id
queue.put({"task_id": 1}, priority=1, channel="channel_1", job_id="x_job")
- Get the next job to be executed from the default channel
job = queue.next()
- Get the next job to be executed from a specific channel
job = queue.next(channel="channel_1")
- Update job progress for long running jobs
job.progress(count=10)
- Put the job back in queue, this will be picked up again later, this will update attempts after max attempts the job will not be picked up again.
job.release()
- Put the job back in queue with error, this will be picked up again later, this will update attempts after max attempts the job will not be picked up again.
job.error("Some error occured")
- Complete the job. This will delete job from the database.
job.complete()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for mongo_queue_service-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ae8d6213fbb93a25ff5facf3af2f4b9ab8e68c12b7a5e68bf64d18261821478 |
|
MD5 | dedcceace5efe1943bcb8aca04d5b53c |
|
BLAKE2b-256 | 293ea0641d5ae7b9367d67daa84215ce686fb9569c9f8893affff82cdb791c0f |
Close
Hashes for mongo_queue_service-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36bb004f0226febb237e0f80c509e879bf802030da029e086cb5d3ad1138a68b |
|
MD5 | e6cee436d8062b8184cb9dd5fa447be2 |
|
BLAKE2b-256 | 157e7d175d8a5800ae9594abd4c966b2151c1db8a7a94eecf7927fcb5d8b36d5 |