Skip to main content

Redis-backed runtime-editable cron scheduler for RQ

Project description

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",
    id="metric:pm25",
    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.

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.

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

rq_rediscron-0.1.5.tar.gz (47.0 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.5-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rq_rediscron-0.1.5.tar.gz
  • Upload date:
  • Size: 47.0 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.5.tar.gz
Algorithm Hash digest
SHA256 2bd360ba8e16162f2bcf02161db5085ddd45c0b9df438d219ddc09918024de74
MD5 bc8846da4dd3d55403891ce4994667bb
BLAKE2b-256 bae421bde67030b028dd8dbad2c9c458c1ba24d40de8d327feab8167dbd966be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rq_rediscron-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 71091b9cba8d42776991398652ed3d8236ffb8e213bb282aab7ba8b8df579c24
MD5 7dee03c20f4c11d44ab015d5d9b9c20a
BLAKE2b-256 071930133b9d8d102b5f687a5589fe21467837c01ff1b7a2a037f32b77cfa4e4

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