This repository was archived by the owner on Jun 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
Add --wait option to databricks runs submit CLI command #487
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
654301e
wip
jerrylian-db 8781f67
lint
jerrylian-db 950fce6
remove 2.1 check
jerrylian-db 7fb6c5c
fix tests
jerrylian-db 54838e5
adapt feedback
jerrylian-db 6a92534
wip
jerrylian-db a81db2b
wip
jerrylian-db 1ab5c09
wip
jerrylian-db 6e92837
wip
jerrylian-db c1bc00c
adapt feedback
jerrylian-db 6f4d5b4
update tests
jerrylian-db 4862b46
wip
jerrylian-db b4bd046
adapt feedback
jerrylian-db 561e8c5
adapt feedback
jerrylian-db 3b4012e
spelling
jerrylian-db 2c4382d
wording
jerrylian-db e28bcfe
Merge branch 'main' into add_wait
pietern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -21,13 +21,17 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
| import time | ||
| from json import loads as json_loads | ||
|
|
||
| import click | ||
| from tabulate import tabulate | ||
|
|
||
| from databricks_cli.click_types import OutputClickType, JsonClickType, RunIdClickType | ||
| from databricks_cli.jobs.cli import check_version | ||
| from databricks_cli.utils import eat_exceptions, CONTEXT_SETTINGS, pretty_format, json_cli_base, \ | ||
| truncate_string | ||
| from databricks_cli.utils import eat_exceptions, CONTEXT_SETTINGS, pretty_format, truncate_string, \ | ||
| error_and_quit, backoff_with_jitter | ||
| from databricks_cli.configure.config import provide_api_client, profile_option, debug_option, \ | ||
| api_version_option | ||
| from databricks_cli.runs.api import RunsApi | ||
|
|
@@ -39,21 +43,48 @@ | |
| help='File containing JSON request to POST to /api/2.*/jobs/runs/submit.') | ||
| @click.option('--json', default=None, type=JsonClickType(), | ||
| help=JsonClickType.help('/api/2.*/jobs/runs/submit')) | ||
| @click.option('--wait', is_flag=True, default=False, | ||
| help='Waits for the submitted run to complete.') | ||
| @api_version_option | ||
| @debug_option | ||
| @profile_option | ||
| @eat_exceptions | ||
| @provide_api_client | ||
| def submit_cli(api_client, json_file, json, version): | ||
| def submit_cli(api_client, json_file, json, wait, version): | ||
| """ | ||
| Submits a one-time run. | ||
| Submits a one-time run and optionally waits for its completion. | ||
|
|
||
| The specification for the request json can be found | ||
| https://docs.databricks.com/api/latest/jobs.html#runs-submit | ||
| """ | ||
| check_version(api_client, version) | ||
| json_cli_base(json_file, json, lambda json: RunsApi( | ||
| api_client).submit_run(json, version=version)) | ||
| if json_file: | ||
| with open(json_file, 'r') as f: | ||
| json = f.read() | ||
| submit_res = RunsApi(api_client).submit_run(json_loads(json), version=version) | ||
| click.echo(pretty_format(submit_res)) | ||
| if wait: | ||
| run_id = submit_res['run_id'] | ||
| completed_states = set(['TERMINATED', 'SKIPPED', 'INTERNAL_ERROR']) | ||
| prev_life_cycle_state = "" | ||
| attempt = 0 | ||
| # Wait for run to complete | ||
| while True: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should have a time-out? So it's not perpetually waiting if something goes wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaning towards not having a time-out for now. I believe that the submitted run themselves have an internal timeouts in Databricks. Users can also force exit on their own.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 Users can always CTRL-C |
||
| run = RunsApi(api_client).get_run(run_id, version=version) | ||
| run_state = run['state'] | ||
| life_cycle_state = run_state['life_cycle_state'] | ||
| if life_cycle_state in completed_states: | ||
| if run_state['result_state'] == 'SUCCESS': | ||
| sys.exit(0) | ||
| else: | ||
| error_and_quit('Run failed with state ' + run_state['result_state'] + | ||
| ' and state message ' + run_state['state_message']) | ||
| if prev_life_cycle_state != life_cycle_state: | ||
| click.echo('Waiting on run to complete. Current state: ' + life_cycle_state + | ||
| '. URL: ' + run['run_page_url'], err=True) | ||
| prev_life_cycle_state = life_cycle_state | ||
| time.sleep(backoff_with_jitter(attempt)) | ||
| attempt += 1 | ||
|
|
||
|
|
||
| def _runs_to_table(runs_json): | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.