'Advanced Python Scheduler running multiple times in production (Django on DigitalOcean)

I have a simple use of Advanced Python Scheduler to run some django code overnight everyday. The code itself works fine, and locally using manage.py runserver with the --noreload flag everything is spot on.

My problem is in production where the APS code is being executed three times; as an example, I receive a status update by email at the end of the process each night, and this email is delivered 3 times within a 10 second period.

This is the apps.py which is the custom initializer for the scheduler app I've created within the django project:

from django.apps import AppConfig


class UpdaterConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'scheduler'

def ready(self):
    from scheduler import updater
    updater.start()

This is then the APScheduler set-up:

from datetime import datetime
from apscheduler.schedulers.background import BackgroundScheduler
from scheduler import schemecutoff, stockcheck,schedulertest, payment_run, new_scheme_cut_off, cutoff_warnings

def start():
    scheduler = BackgroundScheduler()
    scheduler.add_job(schedulertest.test, 'interval', minutes = 1)
    #scheduler.add_job(schemecutoff.run_scheme_cut_off_process, 'interval', minutes = 1)
    #scheduler.add_job(payment_run.find_unpaid_invoices, 'interval', minutes = 1)
    #scheduler.add_job(new_scheme_cut_off.identify_schemes, 'cron', hour = 1, minute = 10)
    scheduler.add_job(cutoff_warnings.check_schemes, 'cron', hour = 11, minute = 3)
    #scheduler.add_job(stockcheck.run_stock_take, 'cron', hour = 1, minute = 5)
    #scheduler.add_job(payment_run.find_unpaid_invoices, 'cron', hour = 5, minute = 30)
    scheduler.start()

Where should I be looking to replicate the protections of the --noreload flag in a production set up?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source