Skip to main content

rq-rediscron provides Redis-backed subclasses for RQ cron scheduling:

  • RedisCronJob

  • RedisCronScheduler

Cron job definitions are stored in Redis hashes and indexed in a sorted set by next enqueue time. This lets scheduler processes pick up job creates, edits, and deletes at runtime without restart.

Only one RedisCronScheduler process runs at a time. The scheduler acquires rq:cron_jobs:lock during register_birth(), extends that lock on heartbeat, and releases it during register_death(). A second scheduler can start after the lock TTL expires, which provides failover without duplicate enqueue loops.

Usage

from redis import Redis
from rediscron import RedisCronScheduler


def rebuild_metric(metric_id: str) -> None:
    ...


connection = Redis.from_url("redis://localhost:6379/0")
scheduler = RedisCronScheduler(connection)
scheduler.register(
    rebuild_metric,
    queue_name="metrics",
    args=("pm25",),
    interval=300,
)
scheduler.start()

Redis keys

Keys used by this package:

  • rq:cron_job:{id} stores one cron job hash.

  • rq:cron_jobs indexes job ids by next enqueue timestamp.

  • rq:cron_jobs:lock allows one live scheduler process at a time.

  • rq:cron_jobs:last_update records runtime changes.

  • rq:cron_jobs:events publishes create, update, and delete events.

Development

To install pre-commit, do the following:

$ uv tool install pre-commit --with pre-commit-uv

To enable pre-commit git hooks:

$ pre-commit install

Why?

The original cron implementation in RQ is holding all the cron jobs locally as a list inside the instance of the scheduler. Because of this design choice, as soon as the scheduler is started, the list of scheduled jobs cannot be easily modified.

In some cases, we want to be able to add/edit/delete scheduled jobs on the fly and for the scheduler to acknowledge those events accordingly. This is what lead the design choices for this package.

Inspired by redisbeat, a celery scheduler using redis to store metadata. See Hello RedBeat: A New Celery Beat Scheduler for mor info.

Download files

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

Source Distribution

rq_rediscron-0.1.10.tar.gz (51.3 kB view details)

Uploaded Source

Built Distribution

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

rq_rediscron-0.1.10-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file rq_rediscron-0.1.10.tar.gz.

File metadata

  • Download URL: rq_rediscron-0.1.10.tar.gz
  • Upload date:
  • Size: 51.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rq_rediscron-0.1.10.tar.gz
Algorithm Hash digest
SHA256 e70fc5d8c59522bcd1674d17f122abd2989d3632bc43ea09a8cf669cd3c0bd66
MD5 a34abf6f13cd1e419bbde2479c946f42
BLAKE2b-256 cacb0eb65097285d6e92880a05cb24204e90a5855669192090e70946b710a72c

See more details on using hashes here.

File details

Details for the file rq_rediscron-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: rq_rediscron-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rq_rediscron-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 349872f7915017e88adecab3c7f0181edbd03a60af1e9942f9fbf27b172a77fa
MD5 222c0e7c4b9b0a89a6e8178944ce2e11
BLAKE2b-256 38d13586fbc83e85bd79cfb1a95c1537812dfad1d36e5a3c56d6f8bc46b235c3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page