diff --git a/fbr/celery_app.py b/fbr/celery_app.py new file mode 100644 index 0000000..6e33420 --- /dev/null +++ b/fbr/celery_app.py @@ -0,0 +1,24 @@ +# isort:skip_file +# flake8: noqa + +import os + +from celery import Celery +from celery.schedules import crontab + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fbr.settings") + +from dbt_copilot_python.celery_health_check import healthcheck + +celery_app = Celery("fbr_celery") +celery_app.config_from_object("django.conf:settings", namespace="CELERY") +celery_app.autodiscover_tasks() + +celery_app = healthcheck.setup(celery_app) + +celery_app.conf.beat_schedule = { + "schedule-fbr-cache-task": { + "task": "celery_worker.tasks.rebuild_cache", + "schedule": crontab(hour="1", minute="0"), # Runs daily at 1:00 AM + }, +} diff --git a/fbr/config/celery.py b/fbr/config/celery.py deleted file mode 100644 index cd0473b..0000000 --- a/fbr/config/celery.py +++ /dev/null @@ -1,34 +0,0 @@ -# isort:skip_file - -from __future__ import absolute_import, unicode_literals - -import os - -from celery import Celery -from celery.schedules import crontab -from dbt_copilot_python.celery_health_check import healthcheck - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fbr.config.settings.local") - -celery_app = Celery("fbr_celery") - -celery_app.config_from_object("django.conf:settings", namespace="CELERY") - -celery_app.autodiscover_tasks() - -celery_app = healthcheck.setup(celery_app) - - -@celery_app.on_after_configure.connect -def setup_periodic_tasks(sender, **kwargs): - schedule = get_cache_beat_schedule() - celery_app.conf.beat_schedule = schedule - - -def get_cache_beat_schedule(): - return { - "schedule-fbr-cache-task": { - "task": "fbr.cache.tasks.rebuild_cache", - "schedule": crontab(hour="1", minute="0"), # Runs daily at 1:00 AM - }, - }