|
|
@ -349,7 +349,7 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
|
|
|
|
|
|
|
|
private boolean taskStateChangeHandler(StateEvent stateEvent) { |
|
|
|
private boolean taskStateChangeHandler(StateEvent stateEvent) { |
|
|
|
TaskInstance task = processService.findTaskInstanceById(stateEvent.getTaskInstanceId()); |
|
|
|
TaskInstance task = processService.findTaskInstanceById(stateEvent.getTaskInstanceId()); |
|
|
|
if (stateEvent.getExecutionStatus().typeIsFinished()) { |
|
|
|
if (task.getState().typeIsFinished()) { |
|
|
|
taskFinished(task); |
|
|
|
taskFinished(task); |
|
|
|
} else if (activeTaskProcessorMaps.containsKey(stateEvent.getTaskInstanceId())) { |
|
|
|
} else if (activeTaskProcessorMaps.containsKey(stateEvent.getTaskInstanceId())) { |
|
|
|
ITaskProcessor iTaskProcessor = activeTaskProcessorMaps.get(stateEvent.getTaskInstanceId()); |
|
|
|
ITaskProcessor iTaskProcessor = activeTaskProcessorMaps.get(stateEvent.getTaskInstanceId()); |
|
|
@ -372,6 +372,18 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
task.getState()); |
|
|
|
task.getState()); |
|
|
|
if (task.taskCanRetry()) { |
|
|
|
if (task.taskCanRetry()) { |
|
|
|
addTaskToStandByList(task); |
|
|
|
addTaskToStandByList(task); |
|
|
|
|
|
|
|
if (!task.retryTaskIntervalOverTime()) { |
|
|
|
|
|
|
|
logger.info("failure task will be submitted: process id: {}, task instance id: {} state:{} retry times:{} / {}, interval:{}", |
|
|
|
|
|
|
|
processInstance.getId(), |
|
|
|
|
|
|
|
task.getId(), |
|
|
|
|
|
|
|
task.getState(), |
|
|
|
|
|
|
|
task.getRetryTimes(), |
|
|
|
|
|
|
|
task.getMaxRetryTimes(), |
|
|
|
|
|
|
|
task.getRetryInterval()); |
|
|
|
|
|
|
|
this.addTimeoutCheck(task); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
submitStandByTask(); |
|
|
|
|
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
ProcessInstance processInstance = processService.findProcessInstanceById(this.processInstance.getId()); |
|
|
|
ProcessInstance processInstance = processService.findProcessInstanceById(this.processInstance.getId()); |
|
|
@ -650,18 +662,20 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addTimeoutCheck(TaskInstance taskInstance) { |
|
|
|
private void addTimeoutCheck(TaskInstance taskInstance) { |
|
|
|
|
|
|
|
if (taskTimeoutCheckList.containsKey(taskInstance.getId())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
TaskDefinition taskDefinition = processService.findTaskDefinition( |
|
|
|
TaskDefinition taskDefinition = processService.findTaskDefinition( |
|
|
|
taskInstance.getTaskCode(), |
|
|
|
taskInstance.getTaskCode(), |
|
|
|
taskInstance.getTaskDefinitionVersion() |
|
|
|
taskInstance.getTaskDefinitionVersion() |
|
|
|
); |
|
|
|
); |
|
|
|
taskInstance.setTaskDefine(taskDefinition); |
|
|
|
taskInstance.setTaskDefine(taskDefinition); |
|
|
|
if (TimeoutFlag.OPEN == taskDefinition.getTimeoutFlag()) { |
|
|
|
if (TimeoutFlag.OPEN == taskDefinition.getTimeoutFlag() || taskInstance.taskCanRetry()) { |
|
|
|
this.taskTimeoutCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (taskInstance.isDependTask() || taskInstance.isSubProcess()) { |
|
|
|
|
|
|
|
this.taskTimeoutCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
this.taskTimeoutCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (taskInstance.isDependTask() || taskInstance.isSubProcess()) { |
|
|
|
|
|
|
|
this.taskTimeoutCheckList.put(taskInstance.getId(), taskInstance); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1131,7 +1145,9 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
private void addTaskToStandByList(TaskInstance taskInstance) { |
|
|
|
private void addTaskToStandByList(TaskInstance taskInstance) { |
|
|
|
logger.info("add task to stand by list: {}", taskInstance.getName()); |
|
|
|
logger.info("add task to stand by list: {}", taskInstance.getName()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
readyToSubmitTaskQueue.put(taskInstance); |
|
|
|
if (!readyToSubmitTaskQueue.contains(taskInstance)) { |
|
|
|
|
|
|
|
readyToSubmitTaskQueue.put(taskInstance); |
|
|
|
|
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("add task instance to readyToSubmitTaskQueue error, taskName: {}", taskInstance.getName(), e); |
|
|
|
logger.error("add task instance to readyToSubmitTaskQueue error, taskName: {}", taskInstance.getName(), e); |
|
|
|
} |
|
|
|
} |
|
|
@ -1191,36 +1207,12 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
this.addStateEvent(stateEvent); |
|
|
|
this.addStateEvent(stateEvent); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean workFlowFinish() { |
|
|
|
public boolean workFlowFinish() { |
|
|
|
return this.processInstance.getState().typeIsFinished(); |
|
|
|
return this.processInstance.getState().typeIsFinished(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* whether the retry interval is timed out |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param taskInstance task instance |
|
|
|
|
|
|
|
* @return Boolean |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private boolean retryTaskIntervalOverTime(TaskInstance taskInstance) { |
|
|
|
|
|
|
|
if (taskInstance.getState() != ExecutionStatus.FAILURE) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (taskInstance.getId() == 0 |
|
|
|
|
|
|
|
|| |
|
|
|
|
|
|
|
taskInstance.getMaxRetryTimes() == 0 |
|
|
|
|
|
|
|
|| |
|
|
|
|
|
|
|
taskInstance.getRetryInterval() == 0) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
long failedTimeInterval = DateUtils.differSec(now, taskInstance.getEndTime()); |
|
|
|
|
|
|
|
// task retry does not over time, return false
|
|
|
|
|
|
|
|
return taskInstance.getRetryInterval() * SEC_2_MINUTES_TIME_UNIT < failedTimeInterval; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* handling the list of tasks to be submitted |
|
|
|
* handling the list of tasks to be submitted |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -1252,12 +1244,16 @@ public class WorkflowExecuteThread implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
DependResult dependResult = getDependResultForTask(task); |
|
|
|
DependResult dependResult = getDependResultForTask(task); |
|
|
|
if (DependResult.SUCCESS == dependResult) { |
|
|
|
if (DependResult.SUCCESS == dependResult) { |
|
|
|
if (retryTaskIntervalOverTime(task)) { |
|
|
|
if (task.retryTaskIntervalOverTime()) { |
|
|
|
|
|
|
|
int originalId = task.getId(); |
|
|
|
TaskInstance taskInstance = submitTaskExec(task); |
|
|
|
TaskInstance taskInstance = submitTaskExec(task); |
|
|
|
if (taskInstance == null) { |
|
|
|
if (taskInstance == null) { |
|
|
|
this.taskFailedSubmit = true; |
|
|
|
this.taskFailedSubmit = true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
removeTaskFromStandbyList(task); |
|
|
|
removeTaskFromStandbyList(task); |
|
|
|
|
|
|
|
if (taskInstance.getId() != originalId) { |
|
|
|
|
|
|
|
activeTaskProcessorMaps.remove(originalId); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (DependResult.FAILED == dependResult) { |
|
|
|
} else if (DependResult.FAILED == dependResult) { |
|
|
|