Skip to content

Commit

Permalink
Fix batch events (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Jun 4, 2024
1 parent 39886bf commit c2695d2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions griptapecli/core/skatepark.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,27 @@ def get_run(structure_run_id: str) -> StructureRun:
@app.post(
"/api/structure-runs/{structure_run_id}/events", status_code=status.HTTP_201_CREATED
)
def create_run_event(structure_run_id: str, event_value: dict) -> Event:
logger.info(f"Creating event for run: {structure_run_id}")
event = Event(value=event_value)
current_run = state.runs[structure_run_id]
current_run.run.events.append(event)

if event.value.get("type") == "FinishStructureRunEvent":
current_run.run.output = event.value.get("output_task_output")
_check_run_process(current_run)

return event
def create_run_event(
structure_run_id: str, event_value: dict | list[dict]
) -> Event | list[Event]:
if isinstance(event_value, dict):
event_values = [event_value]
else:
event_values = event_value

events = []
for event_value in event_values:
logger.info(f"Creating event for run: {structure_run_id}")
event = Event(value=event_value)
events.append(event)
current_run = state.runs[structure_run_id]
current_run.run.events.append(event)

if event.value.get("type") == "FinishStructureRunEvent":
current_run.run.output = event.value.get("output_task_output")
_check_run_process(current_run)

return events


@app.get(
Expand Down

0 comments on commit c2695d2

Please sign in to comment.