88from databricks .labs .lsql .backends import SqlBackend
99from databricks .sdk import WorkspaceClient
1010from databricks .sdk .service import compute
11- from databricks .sdk .service .compute import ClusterDetails
11+ from databricks .sdk .service .compute import ClusterDetails , ClusterSpec
1212from databricks .sdk .service .jobs import (
1313 BaseJob ,
1414 BaseRun ,
@@ -43,7 +43,7 @@ class JobInfo:
4343
4444class JobsMixin :
4545 @classmethod
46- def _get_cluster_configs_from_all_jobs (cls , all_jobs , all_clusters_by_id ):
46+ def _get_cluster_configs_from_all_jobs (cls , all_jobs : list [ BaseJob ] , all_clusters_by_id : dict [ str , ClusterDetails ] ):
4747 for job in all_jobs :
4848 if job .settings is None :
4949 continue
@@ -54,7 +54,11 @@ def _get_cluster_configs_from_all_jobs(cls, all_jobs, all_clusters_by_id):
5454 yield from cls ._task_clusters (job , all_clusters_by_id )
5555
5656 @classmethod
57- def _task_clusters (cls , job , all_clusters_by_id ):
57+ def _task_clusters (
58+ cls , job : BaseJob , all_clusters_by_id : dict [str , ClusterDetails ]
59+ ) -> Iterable [tuple [BaseJob , ClusterDetails | ClusterSpec ]]:
60+ if not job .settings or not job .settings .tasks :
61+ return
5862 for task in job .settings .tasks :
5963 if task .existing_cluster_id is not None :
6064 interactive_cluster = all_clusters_by_id .get (task .existing_cluster_id , None )
@@ -65,7 +69,9 @@ def _task_clusters(cls, job, all_clusters_by_id):
6569 yield job , task .new_cluster
6670
6771 @staticmethod
68- def _job_clusters (job ):
72+ def _job_clusters (job : BaseJob ) -> Iterable [tuple [BaseJob , ClusterSpec ]]:
73+ if not job .settings or not job .settings .job_clusters :
74+ return
6975 for job_cluster in job .settings .job_clusters :
7076 if job_cluster .new_cluster is None :
7177 continue
@@ -79,7 +85,7 @@ def __init__(self, ws: WorkspaceClient, sbe: SqlBackend, schema):
7985
8086 def _crawl (self ) -> Iterable [JobInfo ]:
8187 all_jobs = list (self ._ws .jobs .list (expand_tasks = True ))
82- all_clusters = {c .cluster_id : c for c in self ._ws .clusters .list ()}
88+ all_clusters = {c .cluster_id : c for c in self ._ws .clusters .list () if c . cluster_id }
8389 return self ._assess_jobs (all_jobs , all_clusters )
8490
8591 def _assess_jobs (self , all_jobs : list [BaseJob ], all_clusters_by_id ) -> Iterable [JobInfo ]:
0 commit comments