From 88e8c86fa69bad60c1180c7dfaae2e4ee36eb4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Fri, 7 Jun 2024 11:13:15 +0200 Subject: [PATCH] feat: add excetion outcome reporting to functions --- src/speckle_automate/automation_context.py | 4 ++++ src/speckle_automate/runner.py | 8 ++++++-- src/speckle_automate/schema.py | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) 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):