diff --git a/fbr/cache/tasks.py b/fbr/cache/tasks.py index 45b32e4..e848762 100644 --- a/fbr/cache/tasks.py +++ b/fbr/cache/tasks.py @@ -8,7 +8,7 @@ from fbr.search.utils.documents import clear_all_documents -@shared_task(binding=True) +@shared_task(bind=True, max_retries=3) def rebuild_cache(): try: start = time.time() @@ -19,4 +19,4 @@ def rebuild_cache(): end = time.time() return {"message": "rebuilt cache", "duration": round(end - start, 2)} except Exception as e: - return {"message": f"error clearing documents: {e}"} + return {"message": f"error building cache data: {e}"} diff --git a/fbr/config/celery.py b/fbr/config/celery.py index 3b25156..ee7ab60 100644 --- a/fbr/config/celery.py +++ b/fbr/config/celery.py @@ -18,6 +18,6 @@ celery_app.conf.beat_schedule = { "schedule-fbr-cache-task": { "task": "fbr.cache.tasks.rebuild_cache", - "schedule": crontab(hour="1", minute="0"), + "schedule": crontab(hour="1", minute="0"), # Runs daily at 1:00 AM }, } diff --git a/fbr/config/settings/base.py b/fbr/config/settings/base.py index 98dd57e..05b0b6c 100644 --- a/fbr/config/settings/base.py +++ b/fbr/config/settings/base.py @@ -149,6 +149,12 @@ CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers.DatabaseScheduler" CELERY_RESULT_EXTENDED = True +CELERY_TASK_TIME_LIMIT = ( + 450 # Maximum runtime for a task in seconds (e.g., 7.5 minutes) +) +CELERY_TASK_SOFT_TIME_LIMIT = ( + 270 # Optional: Grace period before forced termination +) # Internationalisation LANGUAGE_CODE = "en-gb" diff --git a/fbr/config/settings/local.py b/fbr/config/settings/local.py index ddae925..f101f73 100644 --- a/fbr/config/settings/local.py +++ b/fbr/config/settings/local.py @@ -6,6 +6,7 @@ BASE_APPS = [ "whitenoise.runserver_nostatic", # Serve static files via WhiteNoise "rest_framework", + "fbr.cache", ] # REST_FRAMEWORK = {