Skip to main content

Celery Beat with leader election

Project description

ENGLISH 🇺🇸 / 简体中文 🇨🇳

Celery Leased Beat

Celery Beat with leader election using Redis.

This package provides a custom scheduler for Celery Beat that ensures only one instance of the scheduler is active at a time in a distributed environment. It uses Redis to acquire a distributed lock (lease).

Installation

uv add celery-leased-beat
# or
pip install celery-leased-beat

# For Django support
uv add "celery-leased-beat[django]"
# or
pip install "celery-leased-beat[django]"

Usage

Configuration

Add the following configuration to your Celery settings:

# Required: Redis URL for the lease lock
CELERY_LEASE_URL = 'redis://localhost:6379/0'

# Optional: Key name for the lock (default: 'celery_lease:lock')
CELERY_LEASE_KEY = 'celery_lease:lock'

# Optional: Lock TTL in seconds (default: 60)
CELERY_LEASE_LOCK_TTL = 60

# Optional: Interval to check/renew the lease in seconds (default: 15)
CELERY_LEASE_INTERVAL = 15

# Optional: Additional Redis connection options
# CELERY_LEASE_OPTIONS = {}

Redis Sentinel

For Redis Sentinel, use the sentinel:// scheme with multiple sentinel nodes:

CELERY_LEASE_URL = 'sentinel://localhost:26379;sentinel://localhost:26380;sentinel://localhost:26381'
CELERY_LEASE_OPTIONS = {
    'master_name': 'cluster1',
    # 'sentinel_kwargs': {'password': 'password'},  # If sentinel_kwargs is needed
}

Running the Scheduler

You can use one of the provided scheduler classes:

  • celery_leased_beat.scheduler.LeasedScheduler: In-memory scheduler with leader election.
  • celery_leased_beat.scheduler.LeasedPersistentScheduler: Persistent scheduler (shelve) with leader election.
  • celery_leased_beat.django.LeasedDjangoScheduler: Django database scheduler with leader election (requires django-celery-beat).

Example command:

celery -A your_project beat -S celery_leased_beat.scheduler.LeasedPersistentScheduler

For Django:

celery -A your_project beat -S celery_leased_beat.django.LeasedDjangoScheduler

Development

This project uses uv for dependency management and flit for packaging.

# Install dependencies
uv sync --all-extras

# Run tests
uv run -- pytest -n auto

# Run matrix tests
uv tool install tox --with tox-uv
tox

License

MIT

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

celery_leased_beat-0.1.0a1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

celery_leased_beat-0.1.0a1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file celery_leased_beat-0.1.0a1.tar.gz.

File metadata

  • Download URL: celery_leased_beat-0.1.0a1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for celery_leased_beat-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 c74f94c1ce0b82f9120026366a1a9b0397b4e6f33e37aa4f9eff149848996777
MD5 27c03278c2ff440c2c03c077a858df1a
BLAKE2b-256 83e89f445e7bba558ed0febe185c32e10246afa153733ac59c698998f5846ac2

See more details on using hashes here.

File details

Details for the file celery_leased_beat-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: celery_leased_beat-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for celery_leased_beat-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e835d45a1bb01fb70d124a7c11b7c16c50a4f39a22a6ae780ca5aca3f81b8c6
MD5 9a3b4221227355a64cacd03fae683759
BLAKE2b-256 3c7a32bff57df7f4d38cfcf58f01b3f97a94b55016d6b5147983ef640408f92b

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