@@ -40,6 +40,7 @@ def load_yaml(filepath, native_k8s_connector_mode=False):
4040
4141# SECURITY WARNING: keep the secret key used in production secret!
4242SECRET_KEY = env .str ("DJANGO_SECRET_KEY" , default = 'django-insecure-3-9*i+n@+)07+$lde6v%+705m+jz9_v9r6##qizm+0&x%)963g' )
43+ NATIVE_KUBERNETES_API_MODE = env .bool ("NATIVE_KUBERNETES_API_MODE" , default = False )
4344
4445# SECURITY WARNING: don't run with debug turned on in production!
4546DEBUG = env .bool ("DJANGO_DEBUG" , default = True )
@@ -141,20 +142,46 @@ def load_yaml(filepath, native_k8s_connector_mode=False):
141142CELERY_WORKER_PREFETCH_MULTIPLIER = 1
142143CELERY_WORKER_MAX_TASKS_PER_CHILD = 1000
143144
145+ # Task timeout settings
146+ CELERY_TASK_TIME_LIMIT = 40 # Hard timeout: 100s (task will be killed, and worker respawned)
147+ CELERY_TASK_SOFT_TIME_LIMIT = 35
148+
144149# Define task queues and route tasks to appropriate queues
145150CELERY_TASK_DEFAULT_QUEUE = 'celery'
146151CELERY_TASK_QUEUES = (
147152 Queue ('celery' ),
148153 Queue ('exec' ),
149154 Queue ('asset_extraction' ),
150155)
151- CELERY_TASK_ROUTES = {
152- # Regular playbook task execution - high priority, needs good resources
153- 'playbooks_engine.tasks.execute_task_and_send_result' : {'queue' : 'exec' },
154-
155- # Asset extraction tasks - can run slower, dedicated resources
156- 'asset_manager.tasks.populate_connector_metadata' : {'queue' : 'asset_extraction' },
157- 'asset_manager.tasks.extractor_async_method_call' : {'queue' : 'asset_extraction' },
156+ if NATIVE_KUBERNETES_API_MODE :
157+ CELERY_TASK_ROUTES = {
158+ # Regular playbook task execution - high priority, needs good resources
159+ 'playbooks_engine.tasks.execute_task_and_send_result' : {'queue' : 'exec' },
160+
161+ # Asset extraction tasks - can run slower, dedicated resources
162+ 'asset_manager.tasks.populate_connector_metadata' : {'queue' : 'asset_extraction' },
163+ 'asset_manager.tasks.extractor_async_method_call' : {'queue' : 'asset_extraction' },
164+ }
165+
166+ else :
167+ CELERY_TASK_ROUTES = {
168+ 'playbooks_engine.tasks.execute_task_and_send_result' : {'queue' : 'exec' },
169+ }
170+
171+ # Queue-specific timeout settings
172+ CELERY_TASK_ANNOTATIONS = {
173+ 'playbooks_engine.tasks.execute_task_and_send_result' : {
174+ 'time_limit' : 40 ,
175+ 'soft_time_limit' : 35 ,
176+ },
177+ 'asset_manager.tasks.populate_connector_metadata' : {
178+ 'time_limit' : 40 ,
179+ 'soft_time_limit' : 35 ,
180+ },
181+ 'asset_manager.tasks.extractor_async_method_call' : {
182+ 'time_limit' : 40 ,
183+ 'soft_time_limit' : 35 ,
184+ },
158185}
159186
160187# Celery Beat Configuration Options
@@ -250,8 +277,6 @@ def load_yaml(filepath, native_k8s_connector_mode=False):
250277DRD_CLOUD_API_HOST = env .str ("DRD_CLOUD_API_HOST" , default = "https://agent-api.drdroid.io" )
251278VPC_AGENT_COMMIT_HASH = env .str ("VPC_AGENT_COMMIT_HASH" , default = "unknown" )
252279
253- NATIVE_KUBERNETES_API_MODE = env .bool ("NATIVE_KUBERNETES_API_MODE" , default = False )
254-
255280SECRETS_FILE_PATH = BASE_DIR / 'credentials/secrets.yaml'
256281LOADED_CONNECTIONS = load_yaml (SECRETS_FILE_PATH , NATIVE_KUBERNETES_API_MODE )
257282
0 commit comments