agenda_culturel/src/agenda_culturel/celery.py

36 lines
965 B
Python
Raw Normal View History

2023-05-10 09:02:59 +02:00
import os
from celery import Celery
2023-05-10 13:19:19 +02:00
from celery.schedules import crontab
2023-05-10 09:02:59 +02:00
# Set the default Django settings module for the 'celery' program.
2023-05-15 15:00:20 +02:00
APP_ENV = os.getenv("APP_ENV", "dev")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"agenda_culturel.settings.{APP_ENV}")
2023-05-10 09:02:59 +02:00
app = Celery("agenda_culturel")
2023-05-10 09:02:59 +02:00
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
2023-05-10 13:19:19 +02:00
app.config_from_object("django.conf:settings", namespace="CELERY")
2023-05-10 09:02:59 +02:00
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
2023-05-10 13:19:19 +02:00
print(f"Request: {self.request!r}")
app.conf.beat_schedule = {
"delete_job_files": {
"task": "test_periodic_task",
# Every 1 minute for testing purposes
"schedule": crontab(minute="*/1"),
},
}
app.conf.timezone = "UTC"