diff --git a/allianceauth/apps.py b/allianceauth/apps.py index 098f50ba..3a831f59 100644 --- a/allianceauth/apps.py +++ b/allianceauth/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.core.checks import Warning, Error, register +from celery.schedules import crontab class AllianceAuthConfig(AppConfig): @@ -7,3 +7,48 @@ class AllianceAuthConfig(AppConfig): def ready(self) -> None: import allianceauth.checks # noqa + from django_celery_beat.models import CrontabSchedule, PeriodicTask + from allianceauth.framework.cron import offset_cron + + PeriodicTask.objects.update_or_create( + name='esi_cleanup_callbackredirect', + defaults={ + 'task': 'esi.tasks.cleanup_callbackredirect', + 'crontab': CrontabSchedule.objects.get_or_create(minute='0', hour='0', day_of_week='*', day_of_month='*', month_of_year='*', timezone='UTC')[0], + }, + ) + PeriodicTask.objects.update_or_create( + name='esi_cleanup_token', + defaults={ + 'task': 'esi.tasks.cleanup_token', + 'crontab': CrontabSchedule.objects.get_or_create(minute='0', hour='0', day_of_week='*', day_of_month='*', month_of_year='*', timezone='UTC')[0], + }, + ) + + z = CrontabSchedule.from_schedule(offset_cron(crontab(minute='0', hour='*/6'))) + PeriodicTask.objects.update_or_create( + name='run_model_update', + defaults={ + 'task': 'allianceauth.eveonline.tasks.run_model_update', + 'crontab': CrontabSchedule.objects.get_or_create( # Convert the offsetted cron into a DB object + minute=z.minute, hour=z.hour, day_of_week=z.day_of_week, day_of_month=z.day_of_month, month_of_year=z.month_of_year, timezone=z.timezone)[0], + }, + ) + + z = CrontabSchedule.from_schedule(offset_cron(crontab(minute='0', hour='*/4'))) + PeriodicTask.objects.update_or_create( + name='check_all_character_ownership', + defaults={ + 'task': 'allianceauth.authentication.tasks.check_all_character_ownership', + 'crontab': CrontabSchedule.objects.get_or_create( # Convert the offsetted cron into a DB object + minute=z.minute, hour=z.hour, day_of_week=z.day_of_week, day_of_month=z.day_of_month, month_of_year=z.month_of_year, timezone=z.timezone)[0], + }, + ) + PeriodicTask.objects.update_or_create( + name='analytics_daily_stats', + defaults={ + 'task': 'allianceauth.analytics.tasks.analytics_daily_stats', + 'crontab': CrontabSchedule.objects.get_or_create( + minute='0', hour='12', day_of_week='*', day_of_month='*', month_of_year='*', timezone='UTC')[0], + }, + ) diff --git a/allianceauth/project_template/project_name/settings/base.py b/allianceauth/project_template/project_name/settings/base.py index fb18e4de..77897c99 100644 --- a/allianceauth/project_template/project_name/settings/base.py +++ b/allianceauth/project_template/project_name/settings/base.py @@ -50,28 +50,7 @@ SECRET_KEY = "wow I'm a really bad default secret key" # Celery configuration BROKER_URL = 'redis://localhost:6379/0' CELERYBEAT_SCHEDULER = "django_celery_beat.schedulers.DatabaseScheduler" -CELERYBEAT_SCHEDULE = { - 'esi_cleanup_callbackredirect': { - 'task': 'esi.tasks.cleanup_callbackredirect', - 'schedule': crontab(minute='0', hour='*/4'), - }, - 'esi_cleanup_token': { - 'task': 'esi.tasks.cleanup_token', - 'schedule': crontab(minute='0', hour='0'), - }, - 'run_model_update': { - 'task': 'allianceauth.eveonline.tasks.run_model_update', - 'schedule': crontab(minute='0', hour="*/6"), - }, - 'check_all_character_ownership': { - 'task': 'allianceauth.authentication.tasks.check_all_character_ownership', - 'schedule': crontab(minute='0', hour='*/4'), - }, - 'analytics_daily_stats': { - 'task': 'allianceauth.analytics.tasks.analytics_daily_stats', - 'schedule': crontab(minute='0', hour='2'), - } -} +CELERYBEAT_SCHEDULE = {} # Build paths inside the project like this: os.path.join(BASE_DIR, ...) PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))