This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev-2.1.3
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev-2.1.3 by this push:
new 0a4f1e701 [Bug] job running duration bug fixed. (#3536)
0a4f1e701 is described below
commit 0a4f1e701483d11416bd467fdbc9190ece9a59a4
Author: benjobs <[email protected]>
AuthorDate: Tue Feb 6 13:43:46 2024 +0800
[Bug] job running duration bug fixed. (#3536)
Co-authored-by: benjobs <[email protected]>
---
.../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