|
35 | 35 | from zenml.constants import ( |
36 | 36 | ENV_ZENML_STEP_OPERATOR, |
37 | 37 | ) |
38 | | -from zenml.enums import ArtifactSaveType |
| 38 | +from zenml.enums import ArtifactSaveType, ExecutionStatus |
39 | 39 | from zenml.exceptions import StepInterfaceError |
40 | 40 | from zenml.hooks.hook_validators import load_and_run_hook |
41 | 41 | from zenml.logger import get_logger |
@@ -236,46 +236,55 @@ def run( |
236 | 236 | ) |
237 | 237 | except BaseException as step_exception: # noqa: E722 |
238 | 238 | step_failed = True |
239 | | - |
240 | | - exception_info = ( |
241 | | - exception_utils.collect_exception_information( |
242 | | - step_exception, step_instance |
243 | | - ) |
244 | | - ) |
245 | | - |
246 | | - if ENV_ZENML_STEP_OPERATOR in os.environ: |
247 | | - # We're running in a step operator environment, so we can't |
248 | | - # depend on the step launcher to publish the exception info |
| 239 | + if ( |
| 240 | + isinstance(step_exception, KeyboardInterrupt) |
| 241 | + and heartbeat_worker.is_terminated |
| 242 | + ): |
249 | 243 | Client().zen_store.update_run_step( |
250 | 244 | step_run_id=step_run_info.step_run_id, |
251 | 245 | step_run_update=StepRunUpdate( |
252 | | - exception_info=exception_info, |
| 246 | + status=ExecutionStatus.STOPPING, |
253 | 247 | ), |
254 | 248 | ) |
255 | | - else: |
256 | | - # This will be published by the step launcher |
257 | | - step_exception_info.set(exception_info) |
258 | 249 |
|
259 | | - if not step_run.is_retriable: |
260 | | - if ( |
261 | | - failure_hook_source |
262 | | - := self.configuration.failure_hook_source |
263 | | - ): |
264 | | - logger.info("Detected failure hook. Running...") |
265 | | - with env_utils.temporary_environment( |
266 | | - step_environment |
267 | | - ): |
268 | | - load_and_run_hook( |
269 | | - failure_hook_source, |
270 | | - step_exception=step_exception, |
271 | | - ) |
272 | | - if ( |
273 | | - isinstance(step_exception, KeyboardInterrupt) |
274 | | - and heartbeat_worker.is_terminated |
275 | | - ): |
276 | 250 | raise StepHeartBeatTerminationException( |
277 | 251 | "Remotely stopped step - terminating execution." |
278 | 252 | ) |
| 253 | + else: |
| 254 | + exception_info = ( |
| 255 | + exception_utils.collect_exception_information( |
| 256 | + step_exception, step_instance |
| 257 | + ) |
| 258 | + ) |
| 259 | + |
| 260 | + if ENV_ZENML_STEP_OPERATOR in os.environ: |
| 261 | + # We're running in a step operator environment, so we can't |
| 262 | + # depend on the step launcher to publish the exception info |
| 263 | + Client().zen_store.update_run_step( |
| 264 | + step_run_id=step_run_info.step_run_id, |
| 265 | + step_run_update=StepRunUpdate( |
| 266 | + exception_info=exception_info, |
| 267 | + ), |
| 268 | + ) |
| 269 | + else: |
| 270 | + # This will be published by the step launcher |
| 271 | + step_exception_info.set(exception_info) |
| 272 | + |
| 273 | + if not step_run.is_retriable: |
| 274 | + if ( |
| 275 | + failure_hook_source |
| 276 | + := self.configuration.failure_hook_source |
| 277 | + ): |
| 278 | + logger.info( |
| 279 | + "Detected failure hook. Running..." |
| 280 | + ) |
| 281 | + with env_utils.temporary_environment( |
| 282 | + step_environment |
| 283 | + ): |
| 284 | + load_and_run_hook( |
| 285 | + failure_hook_source, |
| 286 | + step_exception=step_exception, |
| 287 | + ) |
279 | 288 | raise step_exception |
280 | 289 | finally: |
281 | 290 | heartbeat_worker.stop() |
|
0 commit comments