This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch duration
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit 1bbb8e6904211f773bca02ae19aaac095995e149
Author: benjobs <[email protected]>
AuthorDate: Tue Feb 6 13:32:11 2024 +0800

    [Bug] job running duration bug fixed.
---
 .../console/core/bean/AlertTemplate.java           | 46 ++++++++++++++--------
 .../console/core/controller/AlertController.java   |  2 +-
 .../core/service/alert/AlertServiceTest.java       |  4 +-
 3 files changed, 33 insertions(+), 19 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertTemplate.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertTemplate.java
index d1cd6df2b..b102c0e11 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertTemplate.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/bean/AlertTemplate.java
@@ -28,7 +28,6 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.io.Serializable;
-import java.util.Date;
 import java.util.TimeZone;
 
 @Getter
@@ -51,12 +50,7 @@ public class AlertTemplate implements Serializable {
   private boolean atAll = false;
 
   private static AlertTemplate of(Application application) {
-    long duration;
-    if (application.getEndTime() == null) {
-      duration = System.currentTimeMillis() - 
application.getStartTime().getTime();
-    } else {
-      duration = application.getEndTime().getTime() - 
application.getStartTime().getTime();
-    }
+
     AlertTemplate template = new AlertTemplate();
     template.setJobName(application.getJobName());
 
@@ -68,15 +62,35 @@ public class AlertTemplate implements Serializable {
       template.setLink(null);
     }
 
-    template.setStartTime(
-        DateUtils.format(
-            application.getStartTime(), DateUtils.fullFormat(), 
TimeZone.getDefault()));
-    template.setEndTime(
-        DateUtils.format(
-            application.getEndTime() == null ? new Date() : 
application.getEndTime(),
-            DateUtils.fullFormat(),
-            TimeZone.getDefault()));
-    template.setDuration(DateUtils.toDuration(duration));
+    // duration
+    if (application.getStartTime() != null) {
+      // 1) startTime
+      template.setStartTime(
+          DateUtils.format(
+              application.getStartTime(), DateUtils.fullFormat(), 
TimeZone.getDefault()));
+
+      if (application.getEndTime() != null) {
+        long duration = application.getEndTime().getTime() - 
application.getStartTime().getTime();
+        if (duration > 0) {
+          template.setEndTime(
+              DateUtils.format(
+                  application.getEndTime(), DateUtils.fullFormat(), 
TimeZone.getDefault()));
+          template.setDuration(DateUtils.toDuration(duration));
+        } else {
+          template.setStartTime("-");
+          template.setEndTime("-");
+          template.setDuration("-");
+        }
+      } else {
+        template.setEndTime("-");
+        template.setDuration("-");
+      }
+    } else {
+      template.setStartTime("-");
+      template.setEndTime("-");
+      template.setDuration("-");
+    }
+
     boolean needRestart = application.isNeedRestartOnFailed() && 
application.getRestartCount() > 0;
     template.setRestart(needRestart);
     if (needRestart) {
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/AlertController.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/AlertController.java
index aebd46e2d..aa50d1f05 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/AlertController.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/controller/AlertController.java
@@ -125,7 +125,7 @@ public class AlertController {
     alertTemplate.setStartTime(
         DateUtils.format(date, DateUtils.fullFormat(), TimeZone.getDefault()));
     alertTemplate.setEndTime(DateUtils.format(date, DateUtils.fullFormat(), 
TimeZone.getDefault()));
-    alertTemplate.setDuration("");
+    alertTemplate.setDuration("-");
     boolean alert =
         
alertService.alert(AlertConfigWithParams.of(alertConfigService.getById(id)), 
alertTemplate);
     return RestResponse.success(alert);
diff --git 
a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
 
b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
index 233bdb242..77a2f3df6 100644
--- 
a/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
+++ 
b/streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/alert/AlertServiceTest.java
@@ -82,7 +82,7 @@ class AlertServiceTest {
     alertTemplate.setStartTime(
         DateUtils.format(date, DateUtils.fullFormat(), TimeZone.getDefault()));
     alertTemplate.setEndTime(DateUtils.format(date, DateUtils.fullFormat(), 
TimeZone.getDefault()));
-    alertTemplate.setDuration("");
+    alertTemplate.setDuration("-");
   }
 
   void initConfigForSendEmail() {
@@ -110,7 +110,7 @@ class AlertServiceTest {
     alertTemplate.setStartTime(
         DateUtils.format(date, DateUtils.fullFormat(), TimeZone.getDefault()));
     alertTemplate.setEndTime(DateUtils.format(date, DateUtils.fullFormat(), 
TimeZone.getDefault()));
-    alertTemplate.setDuration("");
+    alertTemplate.setDuration("-");
   }
 
   @Test

Reply via email to