Skip to content

Commit b0894e8

Browse files
committed
Add exit_code property for job run.
1 parent ab9193e commit b0894e8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ads/jobs/builders/infrastructure/dsc_job.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import inspect
1010
import logging
1111
import os
12+
import re
1213
import time
1314
import traceback
1415
import uuid
@@ -582,6 +583,25 @@ def logging(self) -> OCILog:
582583
id=self.log_id, log_group_id=self.log_details.log_group_id, **auth
583584
)
584585

586+
@property
587+
def exit_code(self):
588+
"""The exit code of the job run from the lifecycle details.
589+
Note that,
590+
None will be returned if the job run is not finished or failed without exit code.
591+
0 will be returned if job run succeeded.
592+
"""
593+
if self.lifecycle_state == self.LIFECYCLE_STATE_SUCCEEDED:
594+
return 0
595+
if not self.lifecycle_details:
596+
return None
597+
match = re.search(r"exit code (\d+)", self.lifecycle_details)
598+
if not match:
599+
return None
600+
try:
601+
return int(match.group(1))
602+
except Exception:
603+
return None
604+
585605
@staticmethod
586606
def _format_log(message: str, date_time: datetime.datetime) -> dict:
587607
"""Formats a message as log record with datetime.

0 commit comments

Comments
 (0)