Skip to content

Commit

Permalink
feat: rework function for category based error marking
Browse files Browse the repository at this point in the history
  • Loading branch information
gjedlicska committed Nov 11, 2023
1 parent 00874c2 commit 8bea536
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""This module contains the business logic of the function.
use the automation_context module to wrap your function in an Autamate context helper
Use the automation_context module to wrap your function in an Autamate context helper
"""

import time

from pydantic import Field
from speckle_automate import (
AutomateBase,
Expand Down Expand Up @@ -48,27 +46,22 @@ def automate_function(
# the context provides a conveniet way, to receive the triggering version
version_root_object = automate_context.receive_version()

sleep_cycles = 10
for i in range(sleep_cycles):
print(f"sleeping {i}/{sleep_cycles}")
time.sleep(5)

count = 0
for b in flatten_base(version_root_object):
if b.speckle_type == function_inputs.forbidden_speckle_type:
if not b.id:
raise ValueError("Cannot operate on objects without their id's.")

automate_context.attach_error_to_objects(
category="Forbidden speckle_type",
object_ids=b.id,
message="This project should not contain the type: "
f"{b.speckle_type}",
)
count += 1
objects_with_forbidden_speckle_type = [
b
for b in flatten_base(version_root_object)
if b.speckle_type == function_inputs.forbidden_speckle_type
]
count = len(objects_with_forbidden_speckle_type)

if count > 0:
# this is how a run is marked with a failure cause
automate_context.attach_error_to_objects(
category="Forbidden speckle_type"
" ({function_inputs.forbidden_speckle_type})",
object_ids=[o.id for o in objects_with_forbidden_speckle_type if o.id],
message="This project should not contain the type: "
f"{function_inputs.forbidden_speckle_type}",
)
automate_context.mark_run_failed(
"Automation failed: "
f"Found {count} object that have one of the forbidden speckle types: "
Expand Down

0 comments on commit 8bea536

Please sign in to comment.