APScheduler (with Redis)

Tip

Before you use APScheduler, Check Celery has been removed from your project

Install Dramatiq (using Redis).

Add the following to requirements/base.txt:

APScheduler==

Tip

See Requirements for the current version.

Create a management command to start the scheduler:

project/management/commands/start_scheduler.py

This command should create the scheduler and then add jobs e.g:

import logging

from django.core.management.base import BaseCommand
from pytz import utc

from base.scheduler_utils import create_scheduler


logger = logging.getLogger(__name__)


class Command(BaseCommand):
    """Start APScheduler scheduler."""

    help = "Start APScheduler..."

    def handle(self, *args, **options):
        self.stdout.write("{}...".format(self.help))
        scheduler = create_scheduler()
        self.stdout.write("Scheduler, adding jobs...")
        # payment_intent_fulfillment
        scheduler.add_job(
            "checkout.tasks:payment_intent_fulfillment",
            "interval",
            id="payment_intent_fulfillment",
            minutes=15,
            replace_existing=True,
        )
        # email_task_reminders
        scheduler.add_job(
            "flow.tasks:email_task_reminders",
            "cron",
            day_of_week="mon-fri",
            hour=5,
            minute=30,
        )
        # process_mail
        scheduler.add_job(
            "mail.tasks:process_mail",
            "interval",
            id="process_mail",
            minutes=60,
            replace_existing=True,
        )
        self.stdout.write("Scheduler, starting...")
        scheduler.start()
        self.stdout.write("{} - Complete".format(self.help))

Check Celery has been removed from your project

To remove Celery from your project:

# 1. remove the following line from 'project/__init__.py'
from .celery import app as celery_app
# 2. delete 'project/celery.py'
# 3. Remove Celery from settings files...
# 4. Remove ``celery`` from requirements.