caishunfeng commented on code in PR #11204:
URL: https://github.com/apache/dolphinscheduler/pull/11204#discussion_r952127706
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/DependentExecute.java:
##########
@@ -129,51 +140,87 @@ private DependResult
calculateResultForTasks(DependentItem dependentItem,
/**
* depend type = depend_all
- *
- * @return
*/
- private DependResult dependResultByProcessInstance(ProcessInstance
processInstance) {
- if (!processInstance.getState().isFinished()) {
- return DependResult.WAITING;
- }
+ private DependResult dependResultByProcessInstance(ProcessInstance
processInstance, DateInterval dateInterval) {
Review Comment:
Please add some comments.
##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml:
##########
@@ -246,4 +246,29 @@
where instance.process_instance_id = #{processInstanceId}
and que.status = #{status}
</select>
+ <select id="queryLastTaskInstance"
resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
+ select
+ <include refid="baseSql"/>
+ from t_ds_task_instance
+ where task_code=#{taskCode}
+ <if test="startTime!=null and endTime != null">
+ and start_time <![CDATA[ >= ]]> #{startTime} and start_time
<![CDATA[ <= ]]> #{endTime}
+ </if>
+ order by end_time desc limit 1
+ </select>
+ <select id="queryLastTaskInstanceList"
resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
Review Comment:
```suggestion
<select id="queryTaskInstanceListByTime"
resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
```
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/DependentExecute.java:
##########
@@ -129,51 +140,87 @@ private DependResult
calculateResultForTasks(DependentItem dependentItem,
/**
* depend type = depend_all
- *
- * @return
*/
- private DependResult dependResultByProcessInstance(ProcessInstance
processInstance) {
- if (!processInstance.getState().isFinished()) {
- return DependResult.WAITING;
- }
+ private DependResult dependResultByProcessInstance(ProcessInstance
processInstance, DateInterval dateInterval) {
if (processInstance.getState().isSuccess()) {
+ List<ProcessTaskRelation> taskRelations =
processService.findRelationByCode(processInstance.getProcessDefinitionCode(),
+ processInstance.getProcessDefinitionVersion());
+ if (!taskRelations.isEmpty()) {
+ List<TaskDefinitionLog> taskDefinitionLogs =
processService.genTaskDefineList(taskRelations);
+ Map<Long, String> definiteTask =
taskDefinitionLogs.stream().filter(log ->
!log.getTaskType().equals(TaskConstants.TASK_TYPE_SUB_PROCESS)
Review Comment:
Why filter these logic tasks?
##########
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/utils/DependentExecute.java:
##########
@@ -129,51 +140,87 @@ private DependResult
calculateResultForTasks(DependentItem dependentItem,
/**
* depend type = depend_all
- *
- * @return
*/
- private DependResult dependResultByProcessInstance(ProcessInstance
processInstance) {
- if (!processInstance.getState().isFinished()) {
- return DependResult.WAITING;
- }
+ private DependResult dependResultByProcessInstance(ProcessInstance
processInstance, DateInterval dateInterval) {
if (processInstance.getState().isSuccess()) {
+ List<ProcessTaskRelation> taskRelations =
processService.findRelationByCode(processInstance.getProcessDefinitionCode(),
+ processInstance.getProcessDefinitionVersion());
+ if (!taskRelations.isEmpty()) {
+ List<TaskDefinitionLog> taskDefinitionLogs =
processService.genTaskDefineList(taskRelations);
+ Map<Long, String> definiteTask =
taskDefinitionLogs.stream().filter(log ->
!log.getTaskType().equals(TaskConstants.TASK_TYPE_SUB_PROCESS)
+ ||
!log.getTaskType().equals(TaskConstants.TASK_TYPE_DEPENDENT)
+ ||
!log.getTaskType().equals(TaskConstants.TASK_TYPE_CONDITIONS))
+ .filter(log -> log.getFlag().equals(Flag.YES))
+ .collect(Collectors.toMap(TaskDefinition::getCode,
TaskDefinitionLog::getName));
+ if (!definiteTask.isEmpty()) {
+ List<TaskInstance> taskInstanceList =
processService.findLastTaskInstanceListInterval(definiteTask.keySet(),
dateInterval);
+ if (taskInstanceList.isEmpty()) {
+ logger.warn("Cannot find the task instance: {}",
JSONUtils.toJsonString(definiteTask));
+ return DependResult.FAILED;
+ }
+ Map<Long, TaskInstance> taskInstanceMap = new HashMap<>();
+ for (TaskInstance instance : taskInstanceList) {
+ taskInstanceMap.compute(instance.getTaskCode(), (k, v)
-> {
+ if (v == null) {
+ v = instance;
+ } else {
+ if (v.getId() < instance.getId()) {
+ v = instance;
+ }
+ }
+ return v;
+ });
+ definiteTask.remove(instance.getTaskCode());
+ }
Review Comment:
What is the point of this part?
--
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]