Skip to main content

Cron style scheduler for asynchronous Dramatiq tasks in Django.

Project description

Dramatiq Crontab

dramtiq-crontab logo: person in front of a schedule

Cron style scheduler for asynchronous Dramatiq tasks in Django.

  • setup recurring tasks via crontab syntax
  • lightweight helpers build on robust tools like Dramatiq and APScheduler
  • Sentry cron monitor support

PyPi Version Test Coverage GitHub License

Setup

You need to have Dramatiq installed and setup properly.

python3 -m pip install dramatiq-crontab
# or
python3 -m pip install dramatiq-crontab[sentry]  # with sentry cron monitor support

Add dramatiq_crontab to your INSTALLED_APPS in settings.py:

# settings.py
INSTALLED_APPS = [
    'dramatiq_crontab',
    # ...
]

Finally, you lauch the scheduler in a separate process:

python3 manage.py crontab

Setup Redis as a lock backend (optional)

If you use Redis as a broker, you can use Redis as a lock backend as well. The lock backend is used to prevent multiple instances of the scheduler from running at the same time.

# settings.py
DRAMATIQ_CRONTAB = {
    "REDIS_URL": "redis://localhost:6379/0",
}

Usage

# tasks.py
import dramatiq
from dramatiq_crontab import cron


@cron("*/5 * * * *")  # every 5 minutes
@dramatiq.actor
def my_task():
    my_task.logger.info("Hello World")

Sentry Cron Monitors

If you use Sentry you can add cron monitors to your tasks. The monitor's slug will be the actor's name. Like my_task in the example above.

The crontab command

$ python3 manage.py crontab --help
usage: manage.py crontab [-h] [--no-task-loading] [--no-heartbeat] [--version] [-v {0,1,2,3}]
                         [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                         [--force-color] [--skip-checks]

Run dramatiq task scheduler for all tasks with the `cron` decorator.

options:
  -h, --help            show this help message and exit
  --no-task-loading     Don't load tasks from installed apps.
  --no-heartbeat        Don't start the heartbeat actor.

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

dramatiq-crontab-1.0.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

dramatiq_crontab-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file dramatiq-crontab-1.0.1.tar.gz.

File metadata

  • Download URL: dramatiq-crontab-1.0.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for dramatiq-crontab-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c4f33089ce71b28699e48efb95d05be2e857d1d771cccc7de5ec2fce63acab2a
MD5 2cc5083164b90a4fae9528d3c00d5871
BLAKE2b-256 98f36356945a72e7221fbaec36cf167aeaa5a1f1a2ab86c5409f2dc8a2ea518b

See more details on using hashes here.

File details

Details for the file dramatiq_crontab-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dramatiq_crontab-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b59616952a11c4fd2b29a8ca25e11bbeb87fbbf78b8c6565baa516743b7fefde
MD5 6e7d6c418a13caac514e99d995e535d4
BLAKE2b-256 061814f87eedbb9a1d9ab0d74ebc076700afed6e2fcf8888f1d7be3e19ff5242

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page