forked from databrickslabs/dbx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide final bugfix for databrickslabs#136
- Loading branch information
1 parent
8ff5773
commit 74e828e
Showing
4 changed files
with
34 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import List, Dict, Any, Optional | ||
|
||
from databricks_cli.sdk.service import JobsService | ||
|
||
|
||
def list_all_jobs(js: JobsService) -> List[Dict[str, Any]]: | ||
all_jobs = js.list_jobs( | ||
version="2.0" | ||
) # version 2.0 is expected to list all jobs without iterations over limit/offset | ||
return all_jobs.get("jobs", []) | ||
|
||
|
||
def find_job_by_name(js: JobsService, job_name: str) -> Optional[Dict[str, Any]]: | ||
all_jobs = list_all_jobs(js) | ||
matching_jobs = [j for j in all_jobs if j["settings"]["name"] == job_name] | ||
|
||
if len(matching_jobs) > 1: | ||
raise Exception( | ||
f"""There are more than one jobs with name {job_name}. | ||
Please delete duplicated jobs first""" | ||
) | ||
|
||
if not matching_jobs: | ||
return None | ||
else: | ||
return matching_jobs[0] |