xintongsong commented on code in PR #32:
URL: https://github.com/apache/flink-agents/pull/32#discussion_r2160207355
##########
python/flink_agents/examples/workflow_example.py:
##########
@@ -0,0 +1,31 @@
+from typing import Any
+
+from flink_agents.api.decorators import action
+from flink_agents.api.event import Event, InputEvent, OutputEvent
+from flink_agents.api.workflow import Workflow
+from flink_agents.api.workflow_runner_context import WorkflowRunnerContext
+
+
+class MyEvent(Event): #noqa D101
+ value: Any
+
+class MyWorkflow(Workflow): #noqa D101
+ @action(InputEvent)
+ @staticmethod
+ def first_action(event: Event, ctx: WorkflowRunnerContext): #noqa D102
+ event.input += " first_action"
+ ctx.send_event(MyEvent(value=event.input))
+ ctx.send_event(OutputEvent(output=event.input))
+
+ @action(MyEvent)
+ @staticmethod
+ def second_action(event: Event, ctx: WorkflowRunnerContext): #noqa D102
+ event.value += " second_action"
+ ctx.send_event(OutputEvent(output=event.value))
+
+
+if __name__ == "__main__":
+ workflow = MyWorkflow()
+ session_id = workflow.run(input="input", runner='LocalRunner')
+ for output in workflow.get_outputs(session_id):
+ print(output)
Review Comment:
I'd suggest something like:
```
in_q = Queue()
out_q = (FlinkAgentsExecutionEnvironment
.from_queue(in_q)
.apply(workflow)
.to_queue()
)
FlinkAgentsExecutionEnvironment.execute();
in_q.put(("intput1", "key"))
in_q.put("input2") # automatically generate new unique key
while not out_q.empty():
(key, output) = out_q.get()
print(key, output)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]