Skip to main content

Schedules celery tasks to run in the potentially far future, using a separate storage backend (currently only redis is supported) in combination with a cronjob.

Usage

  • Configure the storage by adding a setting like longterm_scheduler_backend = 'redis://localhost:6739/1' to your celery configuration. (The storage also respects the built-in celery configuration settings redis_socket_timeout, redis_socket_connect_timeout and redis_max_connections.)

  • Configure your celery app to use a customized task class MYCELERY = celery.Celery(task_cls=celery_longterm_scheduler.Task)

  • Set up a cronjob to run celery longterm_scheduler (e.g. every 5 minutes)

  • Now you can schedule your tasks by calling mytask.apply_async(args, kwargs, eta=datetime) as normal. This returns a normal AsyncResult object, but only reading the .id is supported; any other methods or properties may fail explictly or implicitly.

  • You can completely delete a scheduled job by calling celery_longterm_scheduler.get_scheduler(MYCELERY).revoke('mytaskid') (we cannot hook into the celery built-in AsyncResult.revoke(), unfortunately). revoke() returns True on success and False if the given task cannot be found in the storage backend (e.g. because it has already come due and been executed).

Instead of sending a normal job to the celery broker (with added timing information), this creates a job entry in the scheduler storage backend. The cronjob then periodically checks the storage for any jobs that are due, and only then sends a normal celery job to the broker.

Rationale

Why not use the celery built-in apply_async(eta=)? Because you cannot ever really delete a pending job. AsyncResult('mytaskid').revoke() can only add the task ID to the statedb, where it has to stay _forever_ so the job is recognized as revoked. For jobs that are scheduled to run in 6 months time or later, this would create an unmanageable, ever-growing statedb.

Why not use celerybeat? Because it is built for periodic jobs, and we need single-shot jobs. And then there’s not much to gain from the celerybeat implementation, especially since we want to use redis as storage (since we’re already using that as broker and result backend).

Implementation

Redis schema

celery_longterm_scheduler assumes that it talks to a dedicated redis database. It creates an entry per scheduled job using SET jobid job-configuration (job-configuration is serialized with JSON) and uses a single sorted set named scheduled_task_id_by_time that contains the jobids scored by the unix timestamp (UTC) when they are due.

Run tests

Using tox and py.test. Maybe install tox (e.g. via pip install tox) and then simply run tox.

For the integration tests you need to have the redis binary installed (tests start their own server).

celery_longterm_scheduler changes

1.3.1 (2026-07-27)

  • Remove unused setuptools dependency

1.3.0 (2024-01-08)

  • Also support rediss:// URLs

1.2.0 (2022-06-23)

  • Update to celery-5.x

1.1.2 (2020-05-27)

  • Add bw-compat so py3 can read py2-serialized tasks

1.1.1 (2019-12-19)

  • Update to current redis client library version 3.x

1.1.0 (2019-11-28)

  • Make Python-3 compatible.

1.0.1 (2018-01-17)

  • Don’t try to schedule on apply_async(eta=None) calls

1.0.0 (2017-09-29)

  • Initial release

Metadata

Release files for celery-longterm-scheduler 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for celery-longterm-scheduler 1.3.1
File Size Uploaded Provenance Actions
celery_longterm_scheduler-1.3.1.tar.gz 13.8 kB Without provenance Details for celery_longterm_scheduler-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for celery-longterm-scheduler 1.3.1
File Interpreter ABI Platform Actions
celery_longterm_scheduler-1.3.1-py3-none-any.whl Python 3 none any Details for celery_longterm_scheduler-1.3.1-py3-none-any.whl

Total release size: 28.7 kB

Release files / celery_longterm_scheduler-1.3.1.tar.gz

Download URL celery_longterm_scheduler-1.3.1.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
41d2d0f6202ac2e98d06c44905557dd620a131b96674ecd21c56dd07b592f5ab
BLAKE2b-256 checksum
How to use checksums
4da104bcb951a3e96f371f5b110c925f1c89d82fa1e94abedbfc97ecffef0d3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / celery_longterm_scheduler-1.3.1-py3-none-any.whl

Download URL celery_longterm_scheduler-1.3.1-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dafb4caa1a98bcbbe5178a60e103c01a6872ce4c23891759e1e66cea82445614
BLAKE2b-256 checksum
How to use checksums
265d4185fa4f71ac136ef718af66d43751f725c6504b0ef273adebb55a1a2e93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for celery-longterm-scheduler 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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