You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to understand how to properly handle exceptions that occur in a job.
The following code simulates an asynchronous job that occasionally raises an exception.
When the job fails, a callback runs to simulate post-failure actions.
My job : sleep 0.5
My job : Success
My job : sleep 0.6000000000000001
My job : Error
My job raised ValueError
Job "run_job (trigger: interval[0:00:03], next run at: 2025-01-10 15:36:15 CET)" raised an exception
Traceback (most recent call last):
File "[...].venv/lib/python3.13/site-packages/apscheduler/executors/base_py3.py", line 30, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[...]", line 18, in run_job
raise ValueError(f"Job {job_id} : An error occur")
ValueError: Job My job : An error occur
Shutdown scheduler...
As you can see, the exception is not handled and is displayed in the output.
However, if I change the code to handle the exception in the run_job function, the callback is not triggered.
How can I properly handle exceptions raised in an AsyncIOScheduler job to trigger the EVENT_JOB_ERROR event while avoiding the display of the traceback exception in the output?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm trying to understand how to properly handle exceptions that occur in a job.
The following code simulates an asynchronous job that occasionally raises an exception.
When the job fails, a callback runs to simulate post-failure actions.
Here's an example of the output:
As you can see, the exception is not handled and is displayed in the output.
However, if I change the code to handle the exception in the run_job function, the callback is not triggered.
How can I properly handle exceptions raised in an AsyncIOScheduler job to trigger the EVENT_JOB_ERROR event while avoiding the display of the traceback exception in the output?
Thank you in advance for your advice.
Beta Was this translation helpful? Give feedback.
All reactions