<?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 Can anyone tell me why this notebook would fail when run as a Job? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-why-this-notebook-would-fail-when-run-as-a/m-p/19789#M13320</link>
    <description>&lt;P&gt;When the notebook is run by the jobs/workflow scheduler, the data is never imported, but the files do get removed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When run directly (as in running the cell) or when running the Job manually (as in clicking Run Now from the Jobs UI), the data does get imported.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There aren't any obvious errors reported in the job logs. Previously, if the import files contained an invalid schema, the job would actually fail and an alert sent. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import re
&amp;nbsp;
dir = "/FileStore/shared_uploads/gnosis/import/"
files = dbutils.fs.ls(dir)
&amp;nbsp;
for f in files:
    tab = re.split("_\d+",f.name)[0]
    print(f.name + " -&amp;gt; " + tab)
    df = spark.read.format('csv').load(dir + f.name, inferSchema="true", header="true")
    if tab == "t_1" or tab == "t_2":
        df.write.option("mergeSchema",True).saveAsTable('extracts.{}'.format(tab), format='delta', mode='append')
    else:
        df.write.option("mergeSchema",True).saveAsTable('extracts.{}'.format(tab), format='delta', mode='overwrite')
&amp;nbsp;
    dbutils.fs.rm(dir + f.name)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;{
    "job_id": 1,
    "settings": {
        "name": "import data",
        "email_notifications": {
            "on_failure": [
                "gnosis"
            ],
            "no_alert_for_skipped_runs": true
        },
        "timeout_seconds": 0,
        "schedule": {
            "quartz_cron_expression": "54 5 0/2 * * ?",
            "timezone_id": "America/Detroit",
            "pause_status": "PAUSED"
        },
        "max_concurrent_runs": 1,
        "tasks": [
            {
                "task_key": "import_data",
                "notebook_task": {
                    "notebook_path": "/Users/gnosis/import data"
                },
                "existing_cluster_id": "1",
                "timeout_seconds": 0,
                "email_notifications": {}
            }
        ],
        "format": "MULTI_TASK"
    },
    "created_time": 1648574818835,
    "creator_user_name": "gnosis",
    "run_as_user_name": "gnosis"
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 24 May 2022 15:55:26 GMT</pubDate>
    <dc:creator>gnosis</dc:creator>
    <dc:date>2022-05-24T15:55:26Z</dc:date>
    <item>
      <title>Can anyone tell me why this notebook would fail when run as a Job?</title>
      <link>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-why-this-notebook-would-fail-when-run-as-a/m-p/19789#M13320</link>
      <description>&lt;P&gt;When the notebook is run by the jobs/workflow scheduler, the data is never imported, but the files do get removed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When run directly (as in running the cell) or when running the Job manually (as in clicking Run Now from the Jobs UI), the data does get imported.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There aren't any obvious errors reported in the job logs. Previously, if the import files contained an invalid schema, the job would actually fail and an alert sent. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import re
&amp;nbsp;
dir = "/FileStore/shared_uploads/gnosis/import/"
files = dbutils.fs.ls(dir)
&amp;nbsp;
for f in files:
    tab = re.split("_\d+",f.name)[0]
    print(f.name + " -&amp;gt; " + tab)
    df = spark.read.format('csv').load(dir + f.name, inferSchema="true", header="true")
    if tab == "t_1" or tab == "t_2":
        df.write.option("mergeSchema",True).saveAsTable('extracts.{}'.format(tab), format='delta', mode='append')
    else:
        df.write.option("mergeSchema",True).saveAsTable('extracts.{}'.format(tab), format='delta', mode='overwrite')
&amp;nbsp;
    dbutils.fs.rm(dir + f.name)&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;{
    "job_id": 1,
    "settings": {
        "name": "import data",
        "email_notifications": {
            "on_failure": [
                "gnosis"
            ],
            "no_alert_for_skipped_runs": true
        },
        "timeout_seconds": 0,
        "schedule": {
            "quartz_cron_expression": "54 5 0/2 * * ?",
            "timezone_id": "America/Detroit",
            "pause_status": "PAUSED"
        },
        "max_concurrent_runs": 1,
        "tasks": [
            {
                "task_key": "import_data",
                "notebook_task": {
                    "notebook_path": "/Users/gnosis/import data"
                },
                "existing_cluster_id": "1",
                "timeout_seconds": 0,
                "email_notifications": {}
            }
        ],
        "format": "MULTI_TASK"
    },
    "created_time": 1648574818835,
    "creator_user_name": "gnosis",
    "run_as_user_name": "gnosis"
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 15:55:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-why-this-notebook-would-fail-when-run-as-a/m-p/19789#M13320</guid>
      <dc:creator>gnosis</dc:creator>
      <dc:date>2022-05-24T15:55:26Z</dc:date>
    </item>
  </channel>
</rss>

