From 64dca19daaf1b04b235f7cc813cd8db11e680309 Mon Sep 17 00:00:00 2001 From: pbugni Date: Mon, 10 Apr 2023 16:52:01 -0700 Subject: [PATCH] TN-3226 new celery job to intentionally raise exceptions (#4305) NB, this job is not scheduled, but can be manually triggered anytime we need to verify handling and routing of errors. --- portal/config/eproms/ScheduledJob.json | 11 +++++++++++ portal/tasks.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/portal/config/eproms/ScheduledJob.json b/portal/config/eproms/ScheduledJob.json index a012427b0..d34131e87 100644 --- a/portal/config/eproms/ScheduledJob.json +++ b/portal/config/eproms/ScheduledJob.json @@ -264,6 +264,17 @@ "resourceType": "ScheduledJob", "schedule": "1 4,10,16,22 * * *", "task": "process_triggers_task" + }, + { + "active": false, + "args": null, + "kwargs": { + "exception_type": "ValueError" + }, + "name": "Raise Background Exception", + "resourceType": "ScheduledJob", + "schedule": "0 0 0 0 0", + "task": "raise_background_exception_task" } ], "id": "SitePersistence v0.2", diff --git a/portal/tasks.py b/portal/tasks.py index 85f651e12..3d4af057e 100644 --- a/portal/tasks.py +++ b/portal/tasks.py @@ -413,3 +413,14 @@ def process_triggers_task(**kwargs): # Include within function as not all applications include the blueprint from portal.trigger_states.empro_states import fire_trigger_events fire_trigger_events() + + +@celery.task() +@scheduled_task +def raise_background_exception_task(**kwargs): + """Manually trigger to verify job raised exceptions are caught""" + if kwargs.get("exception_type") == "RuntimeError": + raise RuntimeError("intentional RuntimeError raised from task") + if kwargs.get("exception_type") == "ValueError": + raise ValueError("intentional ValueError raised from task") + raise Exception("intentional Exception raised from task")