|
|
@ -2944,7 +2944,12 @@ public class ProcessServiceImpl implements ProcessService { |
|
|
|
// Create a waiting taskGroupQueue, after acquire resource, we can update the status to ACQUIRE_SUCCESS
|
|
|
|
// Create a waiting taskGroupQueue, after acquire resource, we can update the status to ACQUIRE_SUCCESS
|
|
|
|
TaskGroupQueue taskGroupQueue = this.taskGroupQueueMapper.queryByTaskId(taskId); |
|
|
|
TaskGroupQueue taskGroupQueue = this.taskGroupQueueMapper.queryByTaskId(taskId); |
|
|
|
if (taskGroupQueue == null) { |
|
|
|
if (taskGroupQueue == null) { |
|
|
|
taskGroupQueue = insertIntoTaskGroupQueue(taskId, taskName, groupId, processId, priority, |
|
|
|
taskGroupQueue = insertIntoTaskGroupQueue( |
|
|
|
|
|
|
|
taskId, |
|
|
|
|
|
|
|
taskName, |
|
|
|
|
|
|
|
groupId, |
|
|
|
|
|
|
|
processId, |
|
|
|
|
|
|
|
priority, |
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE); |
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
logger.info("The task queue is already exist, taskId: {}", taskId); |
|
|
|
logger.info("The task queue is already exist, taskId: {}", taskId); |
|
|
@ -2956,7 +2961,9 @@ public class ProcessServiceImpl implements ProcessService { |
|
|
|
this.taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
this.taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
} |
|
|
|
} |
|
|
|
// check if there already exist higher priority tasks
|
|
|
|
// 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()); |
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE.getCode()); |
|
|
|
if (CollectionUtils.isNotEmpty(highPriorityTasks)) { |
|
|
|
if (CollectionUtils.isNotEmpty(highPriorityTasks)) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -2977,20 +2984,27 @@ public class ProcessServiceImpl implements ProcessService { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean robTaskGroupResource(TaskGroupQueue taskGroupQueue) { |
|
|
|
public boolean robTaskGroupResource(TaskGroupQueue taskGroupQueue) { |
|
|
|
TaskGroup taskGroup = taskGroupMapper.selectById(taskGroupQueue.getGroupId()); |
|
|
|
// set the default max size to avoid dead loop
|
|
|
|
int affectedCount = taskGroupMapper.updateTaskGroupResource(taskGroup.getId(), |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
taskGroupQueue.getId(), |
|
|
|
TaskGroup taskGroup = taskGroupMapper.selectById(taskGroupQueue.getGroupId()); |
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE.getCode()); |
|
|
|
if (taskGroup.getGroupSize() <= taskGroup.getUseSize()) { |
|
|
|
if (affectedCount > 0) { |
|
|
|
logger.info("The current task Group is full, taskGroup: {}", taskGroup); |
|
|
|
logger.info("Success rob taskGroup, taskInstanceId: {}, taskGroupId: {}", taskGroupQueue.getTaskId(), |
|
|
|
return false; |
|
|
|
taskGroupQueue.getId()); |
|
|
|
} |
|
|
|
taskGroupQueue.setStatus(TaskGroupQueueStatus.ACQUIRE_SUCCESS); |
|
|
|
int affectedCount = taskGroupMapper.robTaskGroupResource(taskGroup.getId(), |
|
|
|
this.taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
taskGroup.getUseSize(), |
|
|
|
this.taskGroupQueueMapper.updateInQueue(Flag.NO.getCode(), taskGroupQueue.getId()); |
|
|
|
taskGroupQueue.getId(), |
|
|
|
return true; |
|
|
|
TaskGroupQueueStatus.WAIT_QUEUE.getCode()); |
|
|
|
|
|
|
|
if (affectedCount > 0) { |
|
|
|
|
|
|
|
logger.info("Success rob taskGroup, taskInstanceId: {}, taskGroupId: {}", taskGroupQueue.getTaskId(), |
|
|
|
|
|
|
|
taskGroupQueue.getId()); |
|
|
|
|
|
|
|
taskGroupQueue.setStatus(TaskGroupQueueStatus.ACQUIRE_SUCCESS); |
|
|
|
|
|
|
|
this.taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
|
|
|
|
this.taskGroupQueueMapper.updateInQueue(Flag.NO.getCode(), taskGroupQueue.getId()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
logger.info("Failed to rob taskGroup, taskInstanceId: {}, taskGroupId: {}", taskGroupQueue.getTaskId(), |
|
|
|
logger.info("Failed to rob taskGroup, taskGroupQueue: {}", taskGroupQueue); |
|
|
|
taskGroupQueue.getId()); |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3071,23 +3085,24 @@ public class ProcessServiceImpl implements ProcessService { |
|
|
|
taskGroupQueueMapper.updateById(taskGroupQueue); |
|
|
|
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 |
|
|
|
@Override |
|
|
|
public TaskGroupQueue insertIntoTaskGroupQueue(Integer taskId, |
|
|
|
public TaskGroupQueue insertIntoTaskGroupQueue(Integer taskInstanceId, |
|
|
|
String taskName, Integer groupId, |
|
|
|
String taskName, |
|
|
|
Integer processId, Integer priority, TaskGroupQueueStatus status) { |
|
|
|
Integer taskGroupId, |
|
|
|
TaskGroupQueue taskGroupQueue = new TaskGroupQueue(taskId, taskName, groupId, processId, priority, status); |
|
|
|
Integer workflowInstanceId, |
|
|
|
taskGroupQueue.setCreateTime(new Date()); |
|
|
|
Integer taskGroupPriority, |
|
|
|
taskGroupQueue.setUpdateTime(new Date()); |
|
|
|
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); |
|
|
|
taskGroupQueueMapper.insert(taskGroupQueue); |
|
|
|
return taskGroupQueue; |
|
|
|
return taskGroupQueue; |
|
|
|
} |
|
|
|
} |
|
|
|