Skip to main content

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's broker_url or result_backend settings, 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.txt and requirements-testing.txt.
  • Set up a local Redis instance, the tests/ directory includes a compose.yml file which sets up a local Redis instance using docker and docker-compose.
  • Run the tox command.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rhubarb-0.2.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rhubarb-0.2.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file rhubarb-0.2.0.tar.gz.

File metadata

  • Download URL: rhubarb-0.2.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for rhubarb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 30dc72f4b62752d04f7c56b80f440df3acb1e2bda1d0224a3077dfee99f7dcf9
MD5 2f7f173c82ccc130c044ddb27f6ebc28
BLAKE2b-256 0380ef75b763e37008acdb8f03c253686651335510fceb23a9e27653b1ebc115

See more details on using hashes here.

File details

Details for the file rhubarb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rhubarb-0.2.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

Hashes for rhubarb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dace39832ad85884e940a1e9a4b41a392730f0de87892d96357690886ab35a7c
MD5 aa567f3658304b06045f408040b2d8be
BLAKE2b-256 51a158b9b0a8beb97f4892e206da0d6ac2a490546eed3b7a0aba689100795ba2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page