wenjin272 commented on code in PR #32: URL: https://github.com/apache/flink-agents/pull/32#discussion_r2163714721
########## python/flink_agents/runtime/local_runner.py: ########## @@ -0,0 +1,204 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################# +import logging +import uuid +from collections import deque +from typing import Any, Dict + +from typing_extensions import override + +from flink_agents.api.event import Event, InputEvent, OutputEvent +from flink_agents.api.runner_context import RunnerContext +from flink_agents.api.workflow import Workflow +from flink_agents.plan.workflow_plan import WorkflowPlan +from flink_agents.runtime.workflow_runner import WorkflowRunner + +logging.basicConfig( + level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" +) +logger = logging.getLogger(__name__) + + +class LocalRunnerContext(RunnerContext): + """Implementation of WorkflowRunnerContext for local workflow execution. + + Attributes: + ---------- + __workflow_plan : WorkflowPlan + Internal workflow plan for this context. + __key : Any + Unique identifier for the context, correspond to the key in flink KeyedStream. + events : deque[Event] + Queue of events to be processed in this context. + outputs : deque[Any] + Queue of outputs generated by workflow execution. + """ + + __workflow_plan: WorkflowPlan + __key: Any + events: deque[Event] + outputs: deque[Any] + + def __init__(self, workflow_plan: WorkflowPlan, key: Any) -> None: + """Initialize a new session with the given workflow and key. + + Parameters + ---------- + workflow : Workflow + Workflow plan used for this context. + key : Any + Unique context identifier, which is corresponding to the key in flink + KeyedStream when agents receive DataStream as input. + """ + self.__workflow_plan = workflow_plan + self.__key = key + self.events = deque() + self.outputs = deque() + + @property + def key(self) -> Any: + """Get the unique identifier for this context. + + Returns: + ------- + Any + The unique identifier for this context. + """ + return self.__key + + @override + def send_event(self, event: Event) -> None: + """Send an event to the context's event queue and log it. + + Parameters + ---------- + event : Event + The event to be added to the queue. + """ + logger.info("key: %s, send_event: %s", self.__key, event) + self.events.append(event) + + def add_output(self, output: Any) -> None: Review Comment: I move the output list from context to runner, and remove the add/clear/get output method in context. -- 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]
