|
15 | 15 | import os
|
16 | 16 | from uuid import uuid4
|
17 | 17 |
|
| 18 | +from google.api_core import exceptions |
| 19 | + |
18 | 20 | from google.cloud import aiplatform, aiplatform_v1beta1
|
19 | 21 | from google.cloud import bigquery
|
20 | 22 | from google.cloud import storage
|
@@ -175,22 +177,27 @@ def teardown_hyperparameter_tuning_job(shared_state, job_client):
|
175 | 177 | def teardown_training_pipeline(shared_state, pipeline_client):
|
176 | 178 | yield
|
177 | 179 |
|
178 |
| - pipeline_client.cancel_training_pipeline( |
179 |
| - name=shared_state["training_pipeline_name"] |
180 |
| - ) |
| 180 | + try: |
| 181 | + pipeline_client.cancel_training_pipeline( |
| 182 | + name=shared_state["training_pipeline_name"] |
| 183 | + ) |
181 | 184 |
|
182 |
| - # Waiting for training pipeline to be in CANCELLED state |
183 |
| - timeout = shared_state["cancel_batch_prediction_job_timeout"] |
184 |
| - helpers.wait_for_job_state( |
185 |
| - get_job_method=pipeline_client.get_training_pipeline, |
186 |
| - name=shared_state["training_pipeline_name"], |
187 |
| - timeout=timeout, |
188 |
| - ) |
| 185 | + # Waiting for training pipeline to be in CANCELLED state |
| 186 | + timeout = shared_state["cancel_batch_prediction_job_timeout"] |
| 187 | + helpers.wait_for_job_state( |
| 188 | + get_job_method=pipeline_client.get_training_pipeline, |
| 189 | + name=shared_state["training_pipeline_name"], |
| 190 | + timeout=timeout, |
| 191 | + ) |
189 | 192 |
|
190 |
| - # Delete the training pipeline |
191 |
| - pipeline_client.delete_training_pipeline( |
192 |
| - name=shared_state["training_pipeline_name"] |
193 |
| - ) |
| 193 | + except exceptions.FailedPrecondition: |
| 194 | + pass # If pipeline failed, ignore and skip directly to deletion |
| 195 | + |
| 196 | + finally: |
| 197 | + # Delete the training pipeline |
| 198 | + pipeline_client.delete_training_pipeline( |
| 199 | + name=shared_state["training_pipeline_name"] |
| 200 | + ) |
194 | 201 |
|
195 | 202 |
|
196 | 203 | @pytest.fixture()
|
|
0 commit comments