|
|
|
@ -2424,7 +2424,12 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
|
|
// Create a waiting taskGroupQueue, after acquire resource, we can update the status to ACQUIRE_SUCCESS
|
|
|
|
|
TaskGroupQueue taskGroupQueue = this.taskGroupQueueMapper.queryByTaskId(taskId); |
|
|
|
|
if (taskGroupQueue == null) { |
|
|
|
|
taskGroupQueue = insertIntoTaskGroupQueue(taskId, taskName, groupId, processId, priority, |
|
|
|
|
taskGroupQueue = insertIntoTaskGroupQueue( |
|
|
|
|
taskId, |
|
|
|
|
taskName, |
|
|
|
|
groupId, |
|
|
|
|
processId, |
|
|
|
|
priority, |
|
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE); |
|
|
|
|
} else { |
|
|
|
|
logger.info("The task queue is already exist, taskId: {}", taskId); |
|
|
|
@ -2436,7 +2441,9 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
|
|
this.taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
|
} |
|
|
|
|
// check if there already exist higher priority tasks
|
|
|
|
|
List<TaskGroupQueue> highPriorityTasks = taskGroupQueueMapper.queryHighPriorityTasks(groupId, priority, |
|
|
|
|
List<TaskGroupQueue> highPriorityTasks = taskGroupQueueMapper.queryHighPriorityTasks( |
|
|
|
|
groupId, |
|
|
|
|
priority, |
|
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE.getCode()); |
|
|
|
|
if (CollectionUtils.isNotEmpty(highPriorityTasks)) { |
|
|
|
|
return false; |
|
|
|
@ -2457,8 +2464,15 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean robTaskGroupResource(TaskGroupQueue taskGroupQueue) { |
|
|
|
|
// set the default max size to avoid dead loop
|
|
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
|
TaskGroup taskGroup = taskGroupMapper.selectById(taskGroupQueue.getGroupId()); |
|
|
|
|
int affectedCount = taskGroupMapper.updateTaskGroupResource(taskGroup.getId(), |
|
|
|
|
if (taskGroup.getGroupSize() <= taskGroup.getUseSize()) { |
|
|
|
|
logger.info("The current task Group is full, taskGroup: {}", taskGroup); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
int affectedCount = taskGroupMapper.robTaskGroupResource(taskGroup.getId(), |
|
|
|
|
taskGroup.getUseSize(), |
|
|
|
|
taskGroupQueue.getId(), |
|
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE.getCode()); |
|
|
|
|
if (affectedCount > 0) { |
|
|
|
@ -2469,8 +2483,8 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
|
|
this.taskGroupQueueMapper.updateInQueue(Flag.NO.getCode(), taskGroupQueue.getId()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
logger.info("Failed to rob taskGroup, taskInstanceId: {}, taskGroupId: {}", taskGroupQueue.getTaskId(), |
|
|
|
|
taskGroupQueue.getId()); |
|
|
|
|
} |
|
|
|
|
logger.info("Failed to rob taskGroup, taskGroupQueue: {}", taskGroupQueue); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2551,23 +2565,24 @@ public class ProcessServiceImpl implements ProcessService {
|
|
|
|
|
taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* insert into task group queue |
|
|
|
|
* |
|
|
|
|
* @param taskId task id |
|
|
|
|
* @param taskName task name |
|
|
|
|
* @param groupId group id |
|
|
|
|
* @param processId process id |
|
|
|
|
* @param priority priority |
|
|
|
|
* @return inserted task group queue |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public TaskGroupQueue insertIntoTaskGroupQueue(Integer taskId, |
|
|
|
|
String taskName, Integer groupId, |
|
|
|
|
Integer processId, Integer priority, TaskGroupQueueStatus status) { |
|
|
|
|
TaskGroupQueue taskGroupQueue = new TaskGroupQueue(taskId, taskName, groupId, processId, priority, status); |
|
|
|
|
taskGroupQueue.setCreateTime(new Date()); |
|
|
|
|
taskGroupQueue.setUpdateTime(new Date()); |
|
|
|
|
@Override |
|
|
|
|
public TaskGroupQueue insertIntoTaskGroupQueue(Integer taskInstanceId, |
|
|
|
|
String taskName, |
|
|
|
|
Integer taskGroupId, |
|
|
|
|
Integer workflowInstanceId, |
|
|
|
|
Integer taskGroupPriority, |
|
|
|
|
TaskGroupQueueStatus status) { |
|
|
|
|
Date now = new Date(); |
|
|
|
|
TaskGroupQueue taskGroupQueue = TaskGroupQueue.builder() |
|
|
|
|
.taskId(taskInstanceId) |
|
|
|
|
.taskName(taskName) |
|
|
|
|
.groupId(taskGroupId) |
|
|
|
|
.processId(workflowInstanceId) |
|
|
|
|
.priority(taskGroupPriority) |
|
|
|
|
.status(status) |
|
|
|
|
.createTime(now) |
|
|
|
|
.updateTime(now) |
|
|
|
|
.build(); |
|
|
|
|
taskGroupQueueMapper.insert(taskGroupQueue); |
|
|
|
|
return taskGroupQueue; |
|
|
|
|
} |
|
|
|
|