Avoid running multiple instances of the same celery task concurrently
Project description
Lock-based celery tasks using Redis
rhubarb provides a LockableTask which implements the Redlock
algorithm in order to guarantee that only one instance of a given task is
running at the same time, while preventing deadlocks from happening in case
of e.g. a worker getting killed, which is not uncommon in cloud environments.
Why use rhubarb?
There are certainly other very similar libraries and tools that can help you achieve the same results, but rhubarb aims to be a very opinionated approach to the same problem these other libraries solve. You can use rhubarb without changing any settings and be confident that the defaults will be enough to not worry about it.
Rhubarb's long-term goal is to guarantee exclusive task execution with minimal, almost inexistent downtime while taking resiliency towards unexpected worker termination very seriously.
Usage
from rhubarb.tasks import LockableTask
@app.task(base=LockableTask)
def my_task():
...
Settings
See the official celery docs on where/how to set the following settings:
rhubarb_backend_url: URL to the Redis instance which will be used for creating the locks. If not present, will fallback to Celery'sbroker_urlorresult_backendsettings, in that order of precedence.rhubarb_backend_kwargs: Dict of keyword arguments to pass to the Redis connection constructor, use for anything not present in the URL. Note that query parameters in the URL always take precedence over key-value pairs in this dict.rhubarb_task_lock_ttl: Global default expiry time for locks in seconds, if not present will default to 60 minutes.
Testing
- Make sure you install both
requirements.txtandrequirements-testing.txt. - Set up a local Redis instance, the
tests/directory includes acompose.ymlfile which sets up a local Redis instance usingdockeranddocker-compose. - Run the
toxcommand.
Why is it called rhubarb?
It's a plugin for celery that implements the Redlock algorithm using Redis... Have you ever seen a rhubarb? It's practically a red celery :-)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rhubarb-0.3.0.tar.gz.
File metadata
- Download URL: rhubarb-0.3.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b0a09b11765c54c038296195458ee39d3638d64a61e36b2d9de8a5c6c9aae6
|
|
| MD5 |
594c91615dda0e8b2a2921db2bd2d7c2
|
|
| BLAKE2b-256 |
c58afb4906ec124d4e1b17279df1cf23d903a268c6566de61091f1baf7693978
|
File details
Details for the file rhubarb-0.3.0-py3-none-any.whl.
File metadata
- Download URL: rhubarb-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edfa73b5cff9b1bdf30a56af4b53388a177c161cce374e1f1bc63e0cc4ba657b
|
|
| MD5 |
7509d3ef6d8a256455ac3ff9cb59ab85
|
|
| BLAKE2b-256 |
cc7720895d503f9074038501a867fc9e7e99aece5cf1d4e5ac617889bd111594
|