From 36594d57dba2c6881e183e719ce0127dfce8271f Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Wed, 26 Jul 2023 11:26:12 -0400 Subject: [PATCH 1/2] Adding debug stack trace feature to celery tasks --- app/celery/scheduled_tasks.py | 12 ++++++++++++ app/config.py | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/celery/scheduled_tasks.py b/app/celery/scheduled_tasks.py index b4937f415d..ad139d42a5 100644 --- a/app/celery/scheduled_tasks.py +++ b/app/celery/scheduled_tasks.py @@ -315,6 +315,17 @@ def beat_inbox_email_bulk(): receipt_id_email, list_of_email_notifications = email_bulk.poll() +if current_app.config["FF_DEBUG_STACK_TRACE"]: + + @notify_celery.task(name="debug-stack-trace") + @statsd(namespace="tasks") + def debug_stack_trace(): + """ + This function, when enabled, will throw an exception so that we can test multi-line logging + """ + raise Exception("Debugging") + + @notify_celery.task(name="beat-inbox-email-priority") @statsd(namespace="tasks") def beat_inbox_email_priority(): @@ -325,6 +336,7 @@ def beat_inbox_email_priority(): to another list(list#2). The heartbeat will then call a job that saves list#2 to the DB and actually sends the email for each notification saved. """ + receipt_id_email, list_of_email_notifications = email_priority.poll() while list_of_email_notifications: diff --git a/app/config.py b/app/config.py index b83e63f9ec..46a94057a8 100644 --- a/app/config.py +++ b/app/config.py @@ -445,6 +445,8 @@ class Config(object): # 'options': {'queue': QueueNames.PERIODIC} # }, } + + CELERY_QUEUES: List[Any] = [] CONTACT_FORM_EMAIL_ADDRESS = os.getenv("CONTACT_FORM_EMAIL_ADDRESS", "helpdesk@cds-snc.ca") @@ -525,6 +527,18 @@ class Config(object): # Timestamp in epoch milliseconds to seed the bounce rate. We will seed data for (24, the below config) included. FF_BOUNCE_RATE_SEED_EPOCH_MS = os.getenv("FF_BOUNCE_RATE_SEED_EPOCH_MS", False) + # Feature flag for stack trace debugging + FF_DEBUG_STACK_TRACE = env.bool("FF_DEBUG_STACK_TRACE", False) + if FF_DEBUG_STACK_TRACE: + CELERYBEAT_SCHEDULE.update({ + "debug-stack-trace": { + "task": "debug-stack-trace", + "schedule": 10, + "options": {"queue": QueueNames.PERIODIC}, + }, + } + ) + @classmethod def get_sensitive_config(cls) -> list[str]: "List of config keys that contain sensitive information" From 9c333b907eda4256fe93d369e0cf3b8ec0e1659c Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Wed, 26 Jul 2023 11:36:23 -0400 Subject: [PATCH 2/2] fixing formatting --- app/config.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/config.py b/app/config.py index 46a94057a8..cf9fae7ba4 100644 --- a/app/config.py +++ b/app/config.py @@ -446,7 +446,6 @@ class Config(object): # }, } - CELERY_QUEUES: List[Any] = [] CONTACT_FORM_EMAIL_ADDRESS = os.getenv("CONTACT_FORM_EMAIL_ADDRESS", "helpdesk@cds-snc.ca") @@ -529,15 +528,16 @@ class Config(object): # Feature flag for stack trace debugging FF_DEBUG_STACK_TRACE = env.bool("FF_DEBUG_STACK_TRACE", False) - if FF_DEBUG_STACK_TRACE: - CELERYBEAT_SCHEDULE.update({ - "debug-stack-trace": { - "task": "debug-stack-trace", - "schedule": 10, - "options": {"queue": QueueNames.PERIODIC}, - }, - } - ) + if FF_DEBUG_STACK_TRACE: + CELERYBEAT_SCHEDULE.update( + { + "debug-stack-trace": { + "task": "debug-stack-trace", + "schedule": 10, + "options": {"queue": QueueNames.PERIODIC}, + }, + } + ) @classmethod def get_sensitive_config(cls) -> list[str]: