Easy Job lite is a simple Python library for queueing jobs and processing them in the background with workers. It is backed by RabbitMQ and it is designed to support retial and deal letter management.
rabbitMQ
First, run a rabbitMQ server, of course:
$ rabbitmq-server
The library supports two mode of operation. remote jobs and local jobs. To put jobs on queues:
from easyjoblite import orchestrator, constants
from local_tst import got_error
from local_tst import local_method_job
def test_job_work():
worker = orchestrator.Orchestrator(rabbitmq_url='amqp://guest:guest@localhost:5672//')
worker.start_service()
data = {"test1": "test2"}
worker.enqueue_job(local_method_job, constants.API_LOCAL, data=data, notification_handler=got_error)
import easyjoblite.orchestrator
import easyjoblite.constants
def test_job_work():
worker = orchestrator.Orchestrator(rabbitmq_url='amqp://guest:guest@localhost:5672//')
worker.start_service()
api = "https://test.domain.com/booking_conform"
notification_handler = "https://test.domain.com/failure_listner"
data = {"hotel_id": "DL001", "room_id": 101, "user_id": 12321}
worker.enqueue_job(api, constants.API_REMOTE, data=data, notification_handler=notification_handler)
And you are done.
For a more complete example, refer to the samples folder in the repo. But this is the essence.
Simply use the following command to install the latest released version:
pip install easyjoblite
The library can be configured in some key attibutes as follows:
The url of the rabbitmq server to be used.
The no of maximum retries to be done for a retriable job before giving up.
The timeout for a remote call if the job is a remote call type.
The duration of sleep for the retry worker inbetween every consuption cycle.
The no of job workers to be spawned.
No of retry consumer to be spawned
No of dead letter consumer to be spawned
semi color seperated list of import paths to be used by the library to search the modules for the job api passed for local job types.
The file location of the pid file where the pid's of the workers are saved. DEFAULT: /var/tmp/easyjoblite.pid
The log file location for the workers DEFAULT: /var/tmp/easyjoblite.log
The maximum worker count which can be spawned (TO BO implemented)
Here are some of the key points to be kept in
Here are the basic limitations which need to be kept in mind while using the library:
- No central manager to manage the lifecycle of the worker processes.
- No signal handling in the workers to handle clean exit of the workers( e.g. complete the current job and then exit)
- RabbitMQ is the only backend supported.
- If no notification handler is provided the message in deal letter queue is lost.
- Message ttl is not supported.
The current limitation of the library is planed to be addressed in the future releases. also below are some of the key features which are planed for future releases:
- A central manager which owns the lifecycle of the workers and spawnes and kills workers as needed.
This project has been inspired by the good parts of Celery, RabbitMQ and Reddis Queue, and has been created as a lightweight alternative to the heaviness of Celery or other AMQP-based queueing implementations.