ruanwenjun commented on code in PR #12264:
URL: https://github.com/apache/dolphinscheduler/pull/12264#discussion_r992920496


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessInstanceServiceImpl.java:
##########
@@ -320,8 +320,11 @@ public Result queryProcessInstanceList(User loginUser, 
long projectCode, long pr
         }
 
         for (ProcessInstance processInstance : processInstances) {
-            processInstance.setDuration(
-                    DateUtils.format2Duration(processInstance.getStartTime(), 
processInstance.getEndTime()));
+            // if processInstance is running, the endTime should be the 
current time
+            String duration = processInstance.getState() != null && 
processInstance.getState().isFinished() ?
+                    DateUtils.format2Duration(processInstance.getStartTime(), 
processInstance.getEndTime()) :
+                    DateUtils.format2Duration(processInstance.getStartTime(), 
new Date());

Review Comment:
   Can we move these code in a utils, 
`WorkflowUtils.getWorkflowInstanceDuration(ProcessInstance processInstance)`?



##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/DateUtils.java:
##########
@@ -353,6 +353,9 @@ public static String format2Duration(Date start, Date end) {
         if (end == null) {
             end = new Date();
         }
+        if (start.after(end)) {

Review Comment:
   This is an unexpected case, we need to log a warning here.



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