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.0a0.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.0a0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: celery_leased_beat-0.1.0a0.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.0a0.tar.gz
Algorithm Hash digest
SHA256 dcdd6ff45b2d831b21f605b0320877cb7176b986d35ef86f709a56b6d3228aaa
MD5 96ce39f7a0fb11b755e351f6c58a5ed4
BLAKE2b-256 acd108ae6c2e3827539fe4b62328e27b14c0b5a68346a0503fbec141990df221

See more details on using hashes here.

File details

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

File metadata

  • Download URL: celery_leased_beat-0.1.0a0-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.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 a88d84329f9341193239b6a82c3b2d3ccb897d8347ab11cde0b3bb9ff78820d6
MD5 151969b572d446957a90b5d7299bb929
BLAKE2b-256 287e8ef8ae3d87b338f6dc87aada0c33b5ea071ecc4205f2a06e045e82fffd21

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