Skip to content

Commit 94d9900

Browse files
committed
fix: use event_id in queue
1 parent 0c38e9a commit 94d9900

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

drive_flow/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ async def invoke_event(
8888
max_async_events: Optional[int] = None,
8989
) -> dict[str, Any]:
9090
this_run_ctx: dict[str, InvokeInterCache] = {}
91-
queue: list[Tuple[BaseEvent, EventInput]] = [(event, event_input)]
91+
queue: list[Tuple[str, EventInput]] = [(event.id, event_input)]
9292

93-
async def run_event(current_event: BaseEvent, current_event_input: Any):
93+
async def run_event(current_event_id: str, current_event_input: Any):
94+
current_event = self.get_event_from_id(current_event_id)
95+
assert current_event is not None, f"Event {current_event_id} not found"
9496
result = await current_event.solo_run(current_event_input, global_ctx)
9597
this_run_ctx[current_event.id] = {
9698
"result": result,
@@ -106,7 +108,7 @@ async def run_event(current_event: BaseEvent, current_event_input: Any):
106108
results=this_group_returns,
107109
behavior=ReturnBehavior.GOTO,
108110
)
109-
queue.append((group_marker, build_input_goto))
111+
queue.append((group_marker.id, build_input_goto))
110112
elif result.behavior == ReturnBehavior.ABORT:
111113
return
112114
else:
@@ -146,7 +148,7 @@ async def run_event(current_event: BaseEvent, current_event_input: Any):
146148
build_input = EventInput(
147149
group_name=group.name, results=this_group_returns
148150
)
149-
queue.append((cand_event, build_input))
151+
queue.append((cand_event.id, build_input))
150152

151153
tasks = set()
152154
try:

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ In this example, The return of `hello` event will trigger `world` event.
6969

7070
To make an event function, there are few elements:
7171

72-
* Input Signature: must be `(event: EventInput, global_ctx)`. `EventInput` is the returns of the listening groups. `global_ctx` is set by you when invoking events, it can be anything and default to `None`
72+
* Input Signature: must be `(event: EventInput, global_ctx)`. `EventInput` is the returns of the listening groups. `global_ctx` is set by you when invoking events, it can be anything and default to `None`.
73+
74+
This [example](./examples/3_use_event_output.py) shows how to get returns from `EventInput` .
7375
* Make sure you decorate the function with `@default_drive.make_event` or `@default_drive.listen_group([EVENT,...])`
7476

7577
Then, run your workflow from any event:
@@ -78,7 +80,7 @@ Then, run your workflow from any event:
7880
await default_drive.invoke_event(EVENT, EVENT_INPUT, GLOBAL_CTX)
7981
```
8082

81-
Check out [examples](./examples) for more use cases and features!
83+
Check out [examples](./examples) for more detailed usages and features!
8284

8385
## Features
8486

0 commit comments

Comments
 (0)