fmadeiro
Contributor II

@jeremy98

Accessing metadata such as the start time, end time, and trigger information of a running Databricks job cannot be accomplished using dbutils.widgets.get(). The dbutils.widgets utility is designed for retrieving the current value of input widgets within notebooks and does not provide access to job metadata.

To obtain metadata about a running job, you should utilize the Databricks REST API, specifically the Jobs API. The GET /api/2.0/jobs/runs/get endpoint allows you to retrieve detailed information about a specific job run, including its start time, end time, and the user who triggered the run. See the Jobs Api docs for more deitails Jobs API 2.0 | Databricks on AWS

Here's an example of how you can use the Databricks REST API to retrieve job run metadata:

 

import requests

# Replace with your Databricks workspace URL and access token
workspace_url = 'https://<databricks-instance>'
access_token = 'your_access_token'

# Replace with your job run ID
run_id = '<run_id>'

# Set up the request headers with the access token
headers = {
    'Authorization': f'Bearer {access_token}'
}

# Make the API request to get job run details
response = requests.get(f'{workspace_url}/api/2.0/jobs/runs/get?run_id={run_id}', headers=headers)

# Check if the request was successful
if response.status_code == 200:
    run_details = response.json()
    # Extract metadata from the response
    start_time = run_details.get('start_time')
    end_time = run_details.get('end_time')
    triggered_by = run_details.get('creator_user_name')
    print(f'Start Time: {start_time}')
    print(f'End Time: {end_time}')
    print(f'Triggered By: {triggered_by}')
else:
    print(f'Error: {response.status_code} - {response.text}')