From 7faef3923f1a117f796f451ff320bc5bb6c0cce5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Fri, 26 Jan 2024 15:04:09 +0100 Subject: [PATCH] Ajout du cron pour l'import automatique --- src/agenda_culturel/celery.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/agenda_culturel/celery.py b/src/agenda_culturel/celery.py index 32d7e4f..0e8e3c3 100644 --- a/src/agenda_culturel/celery.py +++ b/src/agenda_culturel/celery.py @@ -128,5 +128,37 @@ def run_recurrent_import(self, pk): close_import_task(self.request.id, False, e, importer) +@app.task(bind=True) +def daily_imports(self): + from agenda_culturel.models import RecurrentImport + logger.messages("Imports quotidiens") + imports = RecurrentImport.objects.filter(recurrence=RecurrentImport.RECURRENCE.DAILY) + + for imp in imports: + run_recurrent_import.delay(imp.pk) + + +@app.task(bind=True) +def weekly_imports(self): + from agenda_culturel.models import RecurrentImport + logger.messages("Imports hebdomadaires") + imports = RecurrentImport.objects.filter(recurrence=RecurrentImport.RECURRENCE.WEEKLY) + + for imp in imports: + run_recurrent_import.delay(imp.pk) + +app.conf.beat_schedule = { + "daily_imports": { + "task": "agenda_culturel.celery.daily_imports", + # Daily imports at 3:14 a.m. + "schedule": crontab(hour=3, minute=14), + }, + "weekly_imports": { + "task": "agenda_culturel.celery.weekly_imports", + # Daily imports on Mondays at 2:22 a.m. + "schedule": crontab(hour=2, minute=22, day_of_week='mon'), + }, +} app.conf.timezone = "Europe/Paris" +