How to make the job fail via code after handling exception
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-01-2022 11:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-02-2022 06:39 AM
try:
...
except Exception as error:
dbutils.notebook.exit(str(jobId) + ' - ERROR!!! - ' + repr(error))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-03-2022 08:52 PM
Would it work if we are not running notebook based jobs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-10-2022 01:29 AM
Thanks for sharing the link. It doesn't help much for the case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-01-2022 05:57 PM
Hi @karthick Jā ,
Please try the code below:
# Errors in workflows thrown a WorkflowException.
def run_with_retry(notebook, timeout, args = {}, max_retries = 3):
num_retries = 0
while True:
try:
return dbutils.notebook.run(notebook, timeout, args)
except Exception as e:
if num_retries > max_retries:
raise e
else:
print("Retrying error", e)
num_retries += 1
run_with_retry("LOCATION_OF_CALLEE_NOTEBOOK", 60, max_retries = 5)
For more info please check the docs https://docs.databricks.com/notebooks/notebook-workflows.html#handle-errors

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-22-2022 07:28 AM
Hi @karthick Jā
Hope you are well.
Just wanted to see if you were able to find an answer to your question? If yes, would you be happy to mark it as best so that other members can find the solution more quickly?
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-26-2022 04:06 AM
No, didnt get the solution. Maybe there isnt one for this use case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā12-15-2022 07:43 AM
Hi,
I've build a job on a python wheel and I've obtained the opposite behaviour (the job failed). I'm using a try/except like your. I've also tried to create a job from a simple notebook and now the job succeded!
Someone knows why the behaviour changes in relation to the format?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-04-2023 03:06 AM
Instead of exiting the notebook which make the task/job success, Exception objects needs to be raised again from Exception block to fail the job.
try:
<you code>
except Exception as err:
<your block of exception handling>
raise err
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-04-2024 04:19 AM
you can do some hack arround

