Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions src/sdk/python/rtdip_sdk/pipelines/deploy/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,21 @@ def launch(self):
raise ValueError("Job not found in Databricks Workflows")

return True

def stop(self):
"""
Cancels an RTDIP Pipeline Job in Databricks Workflows. This will perform the equivalent of a `Cancel All Runs` in Databricks Workflows
"""
workspace_client = WorkspaceClient(
host=self.host, token=self.token, auth_type="pat"
)
job_found = False
for existing_job in workspace_client.jobs.list(name=self.databricks_job.name):
workspace_client.jobs.cancel_all_runs(job_id=existing_job.job_id)
job_found = True
break

if job_found == False:
raise ValueError("Job not found in Databricks Workflows")

return True
4 changes: 4 additions & 0 deletions src/sdk/python/rtdip_sdk/pipelines/deploy/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ def deploy(self):
@abstractmethod
def launch(self):
pass

@abstractmethod
def stop(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def reset(self, job_id=None, new_settings=None):
def run_now(self, job_id=None):
return None

def cancel_all_runs(self, job_id=None):
return None

def list(self, name=None, job_id=None):
return [self]

Expand Down Expand Up @@ -166,6 +169,13 @@ def test_pipeline_job_deploy(mocker: MockerFixture):
launch_result = databricks_job.launch()
assert launch_result

mocker.patch(default_list_package, return_value=[DummyJob()])
mocker.patch(
"databricks.sdk.service.jobs.JobsAPI.cancel_all_runs", return_value=None
)
launch_result = databricks_job.stop()
assert launch_result


def test_pipeline_job_deploy_fails(mocker: MockerFixture):
cluster_list = []
Expand Down Expand Up @@ -233,3 +243,10 @@ def test_pipeline_job_deploy_fails(mocker: MockerFixture):
mocker.patch("databricks.sdk.service.jobs.JobsAPI.run_now", side_effect=Exception)
with pytest.raises(Exception):
databricks_job.launch()

mocker.patch(default_list_package, return_value=[DummyJob()])
mocker.patch(
"databricks.sdk.service.jobs.JobsAPI.cancel_all_runs", side_effect=Exception
)
with pytest.raises(Exception):
databricks_job.launch()