Skip to content

Commit

Permalink
feat: add excetion outcome reporting to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Jun 7, 2024
1 parent d6843b9 commit 88e8c86
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)

Check warning on line 295 in src/speckle_automate/automation_context.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/automation_context.py#L295

Added line #L295 was not covered by tests

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 = (

Check warning on line 135 in src/speckle_automate/runner.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/runner.py#L135

Added line #L135 was not covered by tests
1 if automation_context.run_status == AutomationStatus.EXCEPTION else 0
)
exit(exit_code)

Check warning on line 138 in src/speckle_automate/runner.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/runner.py#L138

Added line #L138 was not covered by tests

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(

Check warning on line 190 in src/speckle_automate/runner.py

View check run for this annotation

Codecov / codecov/patch

src/speckle_automate/runner.py#L190

Added line #L190 was not covered by tests
"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 88e8c86

Please sign in to comment.