File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
ads/jobs/builders/infrastructure
tests/unitary/default_setup/jobs Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -376,12 +376,13 @@ def delete(self, force_delete: bool = False) -> DSCJob:
376
376
"""
377
377
runs = self .run_list ()
378
378
for run in runs :
379
- if run .lifecycle_state in [
380
- DataScienceJobRun .LIFECYCLE_STATE_ACCEPTED ,
381
- DataScienceJobRun .LIFECYCLE_STATE_IN_PROGRESS ,
382
- DataScienceJobRun .LIFECYCLE_STATE_NEEDS_ATTENTION ,
383
- ]:
384
- run .cancel (wait_for_completion = True )
379
+ if force_delete :
380
+ if run .lifecycle_state in [
381
+ DataScienceJobRun .LIFECYCLE_STATE_ACCEPTED ,
382
+ DataScienceJobRun .LIFECYCLE_STATE_IN_PROGRESS ,
383
+ DataScienceJobRun .LIFECYCLE_STATE_NEEDS_ATTENTION ,
384
+ ]:
385
+ run .cancel (wait_for_completion = True )
385
386
run .delete ()
386
387
self .client .delete_job (self .id )
387
388
return self
@@ -866,6 +867,12 @@ def download(self, to_dir):
866
867
self .job .download (to_dir )
867
868
return self
868
869
870
+ def delete (self , force_delete : bool = False ):
871
+ if force_delete :
872
+ self .cancel (wait_for_completion = True )
873
+ super ().delete ()
874
+ return
875
+
869
876
870
877
# This is for backward compatibility
871
878
DSCJobRun = DataScienceJobRun
Original file line number Diff line number Diff line change @@ -45,3 +45,18 @@ def test_job_run_exit_code(self):
45
45
run .lifecycle_state = run .LIFECYCLE_STATE_FAILED
46
46
run .lifecycle_details = "Job run artifact execution failed with exit code 21."
47
47
self .assertEqual (run .exit_code , 21 )
48
+
49
+ @mock .patch ("ads.jobs.builders.infrastructure.dsc_job.DataScienceJobRun.cancel" )
50
+ @mock .patch ("ads.common.oci_datascience.OCIDataScienceMixin.delete" )
51
+ def test_job_run_delete (self , mock_delete , mock_cancel ):
52
+ """Tests deleting job run."""
53
+ run = DataScienceJobRun ()
54
+ # Cancel will not be called if job run is succeeded.
55
+ run .lifecycle_state = run .LIFECYCLE_STATE_SUCCEEDED
56
+ run .delete ()
57
+ mock_delete .assert_called_once ()
58
+ mock_cancel .assert_not_called ()
59
+ # Cancel will be called if job run is in progress and force_delete is set.
60
+ run .lifecycle_state = run .LIFECYCLE_STATE_IN_PROGRESS
61
+ run .delete (force_delete = True )
62
+ mock_cancel .assert_called_once ()
You can’t perform that action at this time.
0 commit comments