Hisoka-X commented on code in PR #9689:
URL: https://github.com/apache/seatunnel/pull/9689#discussion_r2271936893


##########
docs/zh/concept/event-listener.md:
##########
@@ -112,3 +112,125 @@ seatunnel:
 ### Spark 引擎
 
 您可以定义 `org.apache.seatunnel.api.event.EventHandler` 接口并添加到类路径,SPI会自动加载。
+
+## JobStateEvent 事件监听

Review Comment:
   Could you help to list all event we already supported?



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/PhysicalPlan.java:
##########
@@ -347,10 +349,18 @@ private synchronized void stateProcess() {
             case SAVEPOINT_DONE:
             case FINISHED:
                 stopJobStateProcess();
-                jobEndFuture.complete(new JobResult(getJobStatus(), 
errorBySubPlan.get()));
+                jobMaster
+                        .getCoordinatorService()
+                        .getEventProcessor()
+                        .process(
+                                new JobStateEvent(
+                                        jobImmutableInformation.getJobId(),
+                                        
jobImmutableInformation.getJobConfig().getName(),
+                                        jobStatus));
+                jobEndFuture.complete(new JobResult(jobStatus, 
errorBySubPlan.get()));

Review Comment:
   Let's `complete` first, then process event. Avoid job status delays caused 
by user-implemented process code. 



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/event/JobStateEvent.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package org.apache.seatunnel.engine.server.event;
+
+import org.apache.seatunnel.api.event.Event;
+import org.apache.seatunnel.api.event.EventType;
+import org.apache.seatunnel.engine.core.job.JobStatus;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@ToString
+public class JobStateEvent implements Event {

Review Comment:
   move to `seatunnel-engine-common`?



##########
seatunnel-engine/seatunnel-engine-server/src/test/java/org/apache/seatunnel/engine/server/event/JobStateEventTest.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.apache.seatunnel.engine.server.event;
+
+import org.apache.seatunnel.api.event.EventHandler;
+import org.apache.seatunnel.api.event.EventType;
+import org.apache.seatunnel.common.utils.ReflectionUtils;
+import org.apache.seatunnel.engine.core.job.JobStatus;
+import org.apache.seatunnel.engine.server.AbstractSeaTunnelServerTest;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static 
org.apache.seatunnel.engine.server.checkpoint.CheckpointErrorRestoreEndTest.STREAM_CONF_WITH_ERROR_PATH;
+import static org.awaitility.Awaitility.await;
+
+public class JobStateEventTest extends AbstractSeaTunnelServerTest {
+
+    @Test
+    public void testJobStateEvent() {
+
+        JobEventProcessor eventProcessor =
+                (JobEventProcessor) 
server.getCoordinatorService().getEventProcessor();
+
+        AtomicInteger accessCounter = new AtomicInteger(0);
+        EventHandler eventHandler =
+                event -> {
+                    if (event.getEventType() != EventType.JOB_STATUS) {
+                        return;
+                    }
+                    JobStatus status = ((JobStateEvent) event).getJobStatus();

Review Comment:
   check jobid, job name and createtime?



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