From cfe9b11cf601e75f47852ca6bab8f6492b4f6b2c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 18 Dec 2024 14:09:22 -0800 Subject: [PATCH] remove tasks from redis after they complete --- app/celery/tasks.py | 8 ++++++++ app/config.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/app/celery/tasks.py b/app/celery/tasks.py index b612933ef..c21f4e65c 100644 --- a/app/celery/tasks.py +++ b/app/celery/tasks.py @@ -1,5 +1,6 @@ import json +from celery.signals import task_postrun from flask import current_app from requests import HTTPError, RequestException, request from sqlalchemy.exc import IntegrityError, SQLAlchemyError @@ -170,6 +171,13 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id): return True +@task_postrun.connect +def log_task_ejection(sender=None, task_id=None, **kwargs): + current_app.logger.info( + f"Task {task_id} ({sender.name if sender else 'unknown_task'}) has been completed and removed" + ) + + @notify_celery.task(bind=True, name="save-sms", max_retries=2, default_retry_delay=600) def save_sms(self, service_id, notification_id, encrypted_notification, sender_id=None): """Persist notification to db and place notification in queue to send to sns.""" diff --git a/app/config.py b/app/config.py index 12159e289..e8db17ff2 100644 --- a/app/config.py +++ b/app/config.py @@ -168,6 +168,9 @@ class Config(object): CELERY = { "worker_max_tasks_per_child": 500, + "task_ignore_result": True, + "result_expires": 0, + "result_persistent": False, "broker_url": REDIS_URL, "broker_transport_options": { "visibility_timeout": 310,