Stop all scheduled jobs

Use the included sample code to stop all of your scheduled jobs in the workspace.

Written by simran.arora

Last published at: June 7th, 2023

Under normal conditions, jobs run periodically and auto-terminate once their task is completed. In some cases, you may want to stop all scheduled jobs.

For more information on scheduled jobs, please review the Create, run, and manage Databricks Jobs (AWS | Azure | GCP) documentation.

This article provides sample code that you can use to stop all of your scheduled jobs.

Delete

Info

If you are a standard user, this will only stop scheduled jobs owned by you.

If you are a workspace admin, this will stop all scheduled jobs in the workspace.

Instructions

Use the following sample code to stop all of your scheduled jobs in the workspace.

Delete

Info

To get your workspace URL, review Workspace instance names, URLs, and IDs (AWS | Azure | GCP).

Review the Generate a personal access token (AWS | Azure | GCP) documentation for details on how to create a personal access token for use with the REST APIs.


  1. Copy and paste the sample code into a notebook cell.
  2. Replace the <workspace-domain-without-trailing-backslash> and <personal-access-token> values with ones specific to your workspace.
  3. Run the cell to stop all of your scheduled jobs in the workspace.


%python

import requests
import json

shard_url= "<workspace-domain-without-trailing-backslash>"
access_token= "<personal-access-token>"
flag = 0

headers_auth = {
 'Authorization': f'Bearer {access_token}'
}


jobs_list = requests.request("GET", job_list_url, headers=headers_auth).json()


for job in jobs_list['jobs']:
    if "schedule" in job['settings']:
        if job['settings']['schedule']['pause_status'] == "UNPAUSED":
            flag += 1
            schedule = job['settings']['schedule']
            schedule['pause_status'] = "PAUSED"
            job_name = job['settings']['name']
            job_id = job['job_id']
            
            payload_pause_schedule = json.dumps({
             "job_id": job['job_id'],
             "new_settings": {
             "schedule": schedule
              }
              })


            response = requests.request("POST", job_update_url, headers = headers_auth, data = payload_pause_schedule)
            print("Pausing job ",job_id)


if flag == 0:
    print("No jobs to be paused")