From 54aa761eef7cd2e79b518178540eb7fc808de40a Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Fri, 10 Jan 2025 14:12:32 +0100 Subject: [PATCH] :wrench: Add timeouts to celery tasks Done in the context of issue https://github.com/maykinmedia/charts/issues/148 --- src/openklant/conf/base.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/openklant/conf/base.py b/src/openklant/conf/base.py index 9865cd0f..27679db8 100644 --- a/src/openklant/conf/base.py +++ b/src/openklant/conf/base.py @@ -1,4 +1,5 @@ from open_api_framework.conf.base import * # noqa +from open_api_framework.conf.utils import config # noqa from .api import * # noqa @@ -50,3 +51,28 @@ "openklant.setup_configuration.steps.TokenAuthConfigurationStep", "mozilla_django_oidc_db.setup_configuration.steps.AdminOIDCConfigurationStep", ) + +# +# Celery +# + +# Add (by default) 5 (soft), 15 (hard) minute timeouts to all Celery tasks. +CELERY_TASK_TIME_LIMIT = config( + "CELERY_TASK_HARD_TIME_LIMIT", + default=15 * 60, + help_text=( + "Defaults to: ``900`` seconds. " + "If a celery task exceeds this time limit, the worker processing the task will " + "be killed and replaced with a new one." + ), + group="Celery", +) # hard +CELERY_TASK_SOFT_TIME_LIMIT = config( + "CELERY_TASK_SOFT_TIME_LIMIT", + default=5 * 60, + help_text=( + "Defaults to: ``300`` seconds. " + "If a celery task exceeds this time limit, the ``SoftTimeLimitExceeded`` exception will be raised." + ), + group="Celery", +) # soft