Skip to content

Commit

Permalink
Merge pull request #340 from specklesystems/gergo/automateExceptionOu…
Browse files Browse the repository at this point in the history
…tcome

feat: add excetion outcome reporting to functions
  • Loading branch information
gjedlicska authored Jun 7, 2024
2 parents d6843b9 + 88e8c86 commit 3b5421a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/speckle_automate/automation_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/speckle_automate/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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,"
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/speckle_automate/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AutomationStatus(str, Enum):
RUNNING = "RUNNING"
FAILED = "FAILED"
SUCCEEDED = "SUCCEEDED"
EXCEPTION = "EXCEPTION"


class ObjectResultLevel(str, Enum):
Expand Down

0 comments on commit 3b5421a

Please sign in to comment.