Job scheduling in Azure Databricks

Krishnamoorthy, Rajamannar 61 Reputation points
2021-10-29T13:00:45.727+00:00

I'm trying to create a Job in Databricks using python code,

Also the cluster I'm trying to attach is an all-purpose cluster which has all the libraries installed for the job.

   response = requests.post(  
       'https://%s/api/2.0/jobs/create' % (DOMAIN),  
       headers={'Authorization': 'Bearer {}'.format(TOKEN)},  
       json={  
           "settings": {  
               "existing_cluster_id": "cluster-id",  # all-purpose cluster  
               "notebook_task": {  
                   "notebook_path": "/Notebooks/prediction/f2.py"  
               },  
               "email_notifications": {  
                   "on_failure": [  
                       "abc@org.com"  
                   ]  
               },  
               "name": "Job 01",  
               "schedule": {  
                   "quartz_cron_expression": "24 59 7 * * ?",  
                   "timezone_id": "UTC",  
                   "pause_status": "UNPAUSED"  
               },  
               "max_concurrent_runs": 1  
           }  
       }  
       )  

but I get the following error

144998-image.png

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,311 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,160 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shalvin 161 Reputation points
    2021-10-30T23:16:21.077+00:00

    Hi @Krishnamoorthy, Rajamannar

    I assume you manually created the job in databricks and copied the JSON from the job. You do not need the settings object when using the JSON API as it is the settings actually. Please try the below code and that should work.

    response = requests.post(  
        'https://%s/api/2.0/jobs/create' % (DOMAIN),  
        headers={'Authorization': 'Bearer {}'.format(TOKEN)},  
        json={  
                "existing_cluster_id": "cluster-id",  # all-purpose cluster  
                "notebook_task": {  
                    "notebook_path": "/Notebooks/prediction/f2.py"  
                },  
                "email_notifications": {  
                    "on_failure": [  
                        "abc@org.com"  
                    ]  
                },  
                "name": "Job 01",  
                "schedule": {  
                    "quartz_cron_expression": "24 59 7 * * ?",  
                    "timezone_id": "UTC",  
                    "pause_status": "UNPAUSED"  
                },  
                "max_concurrent_runs": 1  
            }  
        )  
    

    Thanks,
    Shalvin

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.