<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to make the job fail via code after handling exception in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/88330#M37532</link>
    <description>&lt;P&gt;you can do some hack arround&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;dbutils = get_dbutils(spark)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;tables_with_exceptions = []&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for table_config in table_configs&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;process(spark, table_config)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;except Exception as e&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;exception_detail = f"Error processing table {table_config.table_name}&lt;/SPAN&gt;&lt;SPAN&gt;: {&lt;/SPAN&gt;&lt;SPAN&gt;e&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tables_with_exceptions.append(exception_detail)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if tables_with_exceptions:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for exception in tables_with_exceptions:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(exception)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise RuntimeError(f"&lt;/SPAN&gt;&lt;SPAN&gt;Job failed with exceptions&lt;/SPAN&gt;&lt;SPAN&gt;: {&lt;/SPAN&gt;&lt;SPAN&gt;tables_with_exceptions&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; else:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbutils.notebook.exit("completed without exceptions")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Sep 2024 11:19:28 GMT</pubDate>
    <dc:creator>kumar_ravi</dc:creator>
    <dc:date>2024-09-04T11:19:28Z</dc:date>
    <item>
      <title>How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29979#M21666</link>
      <description>&lt;P&gt;Hi , We are capturing the exception if an error occurs using try except. But we want the job status to be failed once we got the exception. Whats the best way to do that. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are using pyspark.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 07:38:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29979#M21666</guid>
      <dc:creator>kjoth</dc:creator>
      <dc:date>2022-02-02T07:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29980#M21667</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;try:
 ...
except Exception as error:
  dbutils.notebook.exit(str(jobId) + ' - ERROR!!! - ' + repr(error))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 14:39:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29980#M21667</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2022-02-02T14:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29981#M21668</link>
      <description>&lt;P&gt;Would it work  if we are not running notebook based jobs?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 04:52:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29981#M21668</guid>
      <dc:creator>kjoth</dc:creator>
      <dc:date>2022-02-04T04:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29983#M21670</link>
      <description>&lt;P&gt;Thanks for sharing the link. It doesn't help much for the case.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Feb 2022 09:29:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29983#M21670</guid>
      <dc:creator>kjoth</dc:creator>
      <dc:date>2022-02-10T09:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29984#M21671</link>
      <description>&lt;P&gt;Hi @karthick J​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try the code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Errors in workflows thrown a WorkflowException.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;def&lt;/B&gt; run_with_retry(notebook, timeout, args = {}, max_retries = 3):&lt;/P&gt;&lt;P&gt;  num_retries = 0&lt;/P&gt;&lt;P&gt;  &lt;B&gt;while&lt;/B&gt; &lt;B&gt;True&lt;/B&gt;:&lt;/P&gt;&lt;P&gt;    &lt;B&gt;try&lt;/B&gt;:&lt;/P&gt;&lt;P&gt;      &lt;B&gt;return&lt;/B&gt; dbutils.notebook.run(notebook, timeout, args)&lt;/P&gt;&lt;P&gt;    &lt;B&gt;except&lt;/B&gt; &lt;B&gt;Exception&lt;/B&gt; &lt;B&gt;as&lt;/B&gt; e:&lt;/P&gt;&lt;P&gt;      &lt;B&gt;if&lt;/B&gt; num_retries &amp;gt; max_retries:&lt;/P&gt;&lt;P&gt;        &lt;B&gt;raise&lt;/B&gt; e&lt;/P&gt;&lt;P&gt;      &lt;B&gt;else&lt;/B&gt;:&lt;/P&gt;&lt;P&gt;        print("Retrying error", e)&lt;/P&gt;&lt;P&gt;        num_retries += 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run_with_retry("LOCATION_OF_CALLEE_NOTEBOOK", 60, max_retries = 5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more info please check the docs &lt;A href="https://docs.databricks.com/notebooks/notebook-workflows.html#handle-errors" target="test_blank"&gt;https://docs.databricks.com/notebooks/notebook-workflows.html#handle-errors&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 01:57:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29984#M21671</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2022-03-02T01:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29985#M21672</link>
      <description>&lt;P&gt;Hi @karthick J​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope you are well. &lt;/P&gt;&lt;P&gt;Just wanted to see if you were able to find an answer to your question? &amp;nbsp;If yes, would you be happy to mark it as best so that other members can find the solution more quickly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 14:28:01 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29985#M21672</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-04-22T14:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29986#M21673</link>
      <description>&lt;P&gt;No, didnt get the solution. Maybe there isnt one for this use case. &lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 11:06:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29986#M21673</guid>
      <dc:creator>kjoth</dc:creator>
      <dc:date>2022-04-26T11:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29987#M21674</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Someone knows why the behaviour changes in relation to the format? &lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:43:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29987#M21674</guid>
      <dc:creator>lcalca95</dc:creator>
      <dc:date>2022-12-15T15:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29988#M21675</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try:&lt;/P&gt;&lt;P&gt;     &amp;lt;you code&amp;gt;&lt;/P&gt;&lt;P&gt;except Exception as err:&lt;/P&gt;&lt;P&gt;     &amp;lt;your block of exception handling&amp;gt;&lt;/P&gt;&lt;P&gt;  &lt;B&gt;   raise err&lt;/B&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 10:06:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/29988#M21675</guid>
      <dc:creator>AkA</dc:creator>
      <dc:date>2023-05-04T10:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the job fail via code after handling exception</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/88330#M37532</link>
      <description>&lt;P&gt;you can do some hack arround&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;dbutils = get_dbutils(spark)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;tables_with_exceptions = []&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for table_config in table_configs&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;try&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;process(spark, table_config)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;except Exception as e&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;exception_detail = f"Error processing table {table_config.table_name}&lt;/SPAN&gt;&lt;SPAN&gt;: {&lt;/SPAN&gt;&lt;SPAN&gt;e&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; tables_with_exceptions.append(exception_detail)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if tables_with_exceptions:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for exception in tables_with_exceptions:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(exception)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; raise RuntimeError(f"&lt;/SPAN&gt;&lt;SPAN&gt;Job failed with exceptions&lt;/SPAN&gt;&lt;SPAN&gt;: {&lt;/SPAN&gt;&lt;SPAN&gt;tables_with_exceptions&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; else:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dbutils.notebook.exit("completed without exceptions")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2024 11:19:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-make-the-job-fail-via-code-after-handling-exception/m-p/88330#M37532</guid>
      <dc:creator>kumar_ravi</dc:creator>
      <dc:date>2024-09-04T11:19:28Z</dc:date>
    </item>
  </channel>
</rss>

