Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New example to list compute resource for SUBMIT_RUN job runs #572

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions examples/list_compute_submitrun_runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!env python3
import logging
import sys

from databricks.sdk import WorkspaceClient
from databricks.sdk.service import jobs

if __name__ == "__main__":
logging.basicConfig(stream=sys.stdout,
level=logging.INFO,
format="%(asctime)s [%(name)s][%(levelname)s] %(message)s",
)

w = WorkspaceClient()

# we set expand_tasks to true because the cluster information will exist in the tasks
job_runs = w.jobs.list_runs(expand_tasks=True)

for run in job_runs:
# filter to SubmitRun jobs
if run.run_type == jobs.RunType.SUBMIT_RUN:
tasks = run.tasks

compute_used = []
# Iterate over tasks in the run
for task in run.tasks:
'''
- Tasks with All Purpose clusters will have an existing_cluster_id
- Tasks with a Jobs cluster will have the new_cluster represented as ClusterSpec
- SQL tasks will have a sql_warehouse_id
'''
task_compute = (
{"existing_cluster_id": task.existing_cluster_id} if task.existing_cluster_id else
{"new_cluster": task.new_cluster} if task.new_cluster else
{"sql_warehouse_id": task.sql_task.warehouse_id} if task.sql_task else
{}
)

# Append the task compute info to a list for the job
compute_used.append(task_compute)

logging.info(f"run_id: {run.run_id}, compute_used: {compute_used}")
Loading