diff --git a/src/speckle_automate/automation_context.py b/src/speckle_automate/automation_context.py index 32ec0149..5b28f726 100644 --- a/src/speckle_automate/automation_context.py +++ b/src/speckle_automate/automation_context.py @@ -290,6 +290,10 @@ def mark_run_failed(self, status_message: str) -> None: """Mark the current run a failure.""" self._mark_run(AutomationStatus.FAILED, status_message) + def mark_run_exception(self, status_message: str) -> None: + """Mark the current run a failure.""" + self._mark_run(AutomationStatus.EXCEPTION, status_message) + def mark_run_success(self, status_message: Optional[str]) -> None: """Mark the current run a success with an optional message.""" self._mark_run(AutomationStatus.SUCCEEDED, status_message) diff --git a/src/speckle_automate/runner.py b/src/speckle_automate/runner.py index 417393c4..71a27aaa 100644 --- a/src/speckle_automate/runner.py +++ b/src/speckle_automate/runner.py @@ -132,7 +132,10 @@ def execute_automate_function( # if we've gotten this far, the execution should technically be completed as expected # thus exiting with 0 is the schemantically correct thing to do - exit(0) + exit_code = ( + 1 if automation_context.run_status == AutomationStatus.EXCEPTION else 0 + ) + exit(exit_code) else: raise NotImplementedError(f"Command: '{command}' is not supported.") @@ -175,6 +178,7 @@ def run_function( if automation_context.run_status not in [ AutomationStatus.FAILED, AutomationStatus.SUCCEEDED, + AutomationStatus.EXCEPTION, ]: automation_context.mark_run_success( "WARNING: Automate assumed a success status," @@ -183,7 +187,7 @@ def run_function( except Exception: trace = traceback.format_exc() print(trace) - automation_context.mark_run_failed( + automation_context.mark_run_exception( "Function error. Check the automation run logs for details." ) finally: diff --git a/src/speckle_automate/schema.py b/src/speckle_automate/schema.py index 95802635..6e0b5649 100644 --- a/src/speckle_automate/schema.py +++ b/src/speckle_automate/schema.py @@ -63,6 +63,7 @@ class AutomationStatus(str, Enum): RUNNING = "RUNNING" FAILED = "FAILED" SUCCEEDED = "SUCCEEDED" + EXCEPTION = "EXCEPTION" class ObjectResultLevel(str, Enum):