letaoj commented on code in PR #138:
URL: https://github.com/apache/flink-agents/pull/138#discussion_r2331294836


##########
runtime/src/main/java/org/apache/flink/agents/runtime/operator/ActionExecutionOperator.java:
##########
@@ -301,20 +309,47 @@ private void processActionTaskForKey(Object key) throws 
Exception {
 
         // 2. Invoke the action task.
         createAndSetRunnerContext(actionTask);
-        ActionTask.ActionTaskResult actionTaskResult = actionTask.invoke();
-        for (Event actionOutputEvent : actionTaskResult.getOutputEvents()) {
+
+        boolean isFinished = false;
+        List<Event> outputEvents;
+        Optional<ActionTask> generatedActionTaskOpt;
+        ActionState actionState = actionStateStore.get(key, actionTask.action);
+        if (actionState != null) {
+            isFinished = actionState.getGeneratedActionTask().isPresent();
+            outputEvents = actionState.getOutputEvents();
+            generatedActionTaskOpt = actionState.getGeneratedActionTask();
+            for (MemoryUpdate memoryUpdate : actionState.getMemoryUpdates()) {
+                actionTask
+                        .getRunnerContext()
+                        .getShortTermMemory()
+                        .set(memoryUpdate.getPath(), memoryUpdate.getValue());
+            }
+        } else {
+            initActionState(key, actionTask.action, actionTask.event);
+            ActionTask.ActionTaskResult actionTaskResult = actionTask.invoke();
+            persistTaskResult(
+                    key,
+                    actionTask.action,
+                    actionTask.getRunnerContext().getShortTermMemory(),
+                    actionTaskResult);
+            isFinished = actionTaskResult.isFinished();
+            outputEvents = actionTaskResult.getOutputEvents();
+            generatedActionTaskOpt = actionTaskResult.getGeneratedActionTask();
+        }
+
+        for (Event actionOutputEvent : outputEvents) {
             processEvent(key, actionOutputEvent);
         }
 
         boolean currentInputEventFinished = false;
-        if (actionTaskResult.isFinished()) {
+        if (isFinished) {
             builtInMetrics.markActionExecuted(actionTask.action.getName());
             currentInputEventFinished = !currentKeyHasMoreActionTask();
         } else {
-            // If the action task not finished, we should get a new action 
task to execute continue.
-            Optional<ActionTask> generatedActionTaskOpt = 
actionTaskResult.getGeneratedActionTask();
+            // If the action task is not finished, we should get a new action 
task to continue the
+            // execution.
             checkNotNull(
-                    generatedActionTaskOpt.isPresent(),
+                    generatedActionTaskOpt.get(),

Review Comment:
   this is a potential bug that was fixed in this PR, isPresent() returns 
true/false and will never by null. By doing a get on optional, it will return 
the actual value in the optional so that we can properly check the nullity



-- 
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]

Reply via email to