From 230cbeba3768d791ebc11d4375c64f7ddfb2dd1f Mon Sep 17 00:00:00 2001 From: qiushengjie Date: Tue, 19 Sep 2023 12:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=A4=96=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ms-biz/src/main/java/com/ms/api/biz/MoveService.java | 4 ++-- .../main/java/com/ms/api/common/TaskBaseService.java | 1 + .../main/java/com/ms/api/service/QueueService.java | 4 ++++ .../com/ms/api/service/impl/QueueServiceImpl.java | 4 ++-- .../ms/api/task/CheckMaterialBizWaitTaskService.java | 8 ++++++-- .../java/com/ms/api/task/MoveUnlockTaskService.java | 11 ++++++++--- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java index 05baf29d..3edb04cb 100644 --- a/ms-biz/src/main/java/com/ms/api/biz/MoveService.java +++ b/ms-biz/src/main/java/com/ms/api/biz/MoveService.java @@ -1355,7 +1355,7 @@ public class MoveService { public int unlockMoveProductPublishQueue() { log.info("start unlock process publish"); String tableName = "move_product_publish_queue"; - int lockSec = 5 * 60; + int lockSec = 10 * 60; DateTime deadTime = DateUtil.offsetSecond(new Date(), -lockSec); String where = String.format(" WHERE locked > 0 AND gmt_locked < '%s' ", DateUtil.formatDateTime(deadTime)); List> queueList = queueMapper.select(tableName, where); @@ -1416,7 +1416,7 @@ public class MoveService { public int unlockMoveProductPublishToPicQueue() { log.info("start unlock process publish to pic"); String tableName = "move_product_publish_to_pic_queue"; - int lockSec = 5 * 60; + int lockSec = 10 * 60; DateTime deadTime = DateUtil.offsetSecond(new Date(), -lockSec); String where = String.format(" WHERE locked > 0 AND gmt_locked < '%s' ", DateUtil.formatDateTime(deadTime)); List> queueList = queueMapper.select(tableName, where); diff --git a/ms-biz/src/main/java/com/ms/api/common/TaskBaseService.java b/ms-biz/src/main/java/com/ms/api/common/TaskBaseService.java index f56b32e1..0f8b9958 100644 --- a/ms-biz/src/main/java/com/ms/api/common/TaskBaseService.java +++ b/ms-biz/src/main/java/com/ms/api/common/TaskBaseService.java @@ -84,6 +84,7 @@ public abstract class TaskBaseService implements TaskHandler { String threadInfo = getThreadPoolInfo(); log.info(threadInfo); + log.info("开始执行任务"); Object getTaskRet = getTask(); diff --git a/ms-biz/src/main/java/com/ms/api/service/QueueService.java b/ms-biz/src/main/java/com/ms/api/service/QueueService.java index f8f3ab31..83d23786 100644 --- a/ms-biz/src/main/java/com/ms/api/service/QueueService.java +++ b/ms-biz/src/main/java/com/ms/api/service/QueueService.java @@ -10,5 +10,9 @@ public interface QueueService { int unlockTimeoutSolidRedisQueue(String tableName, int heartbeatExpiredSeconds, String status); + int unlockSolidRedisDeadQueue(String tableName, int heartbeatExpiredSeconds, String status); + + int unlockSolidRedisSkipQueue(String queueName, String status); + int unlockTimeoutQueue(String tableName, int heartbeatExpiredSeconds, String status); } diff --git a/ms-biz/src/main/java/com/ms/api/service/impl/QueueServiceImpl.java b/ms-biz/src/main/java/com/ms/api/service/impl/QueueServiceImpl.java index 3efd5c8f..61739102 100644 --- a/ms-biz/src/main/java/com/ms/api/service/impl/QueueServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/api/service/impl/QueueServiceImpl.java @@ -53,7 +53,7 @@ public class QueueServiceImpl implements QueueService { return c1 + c2; } - private int unlockSolidRedisSkipQueue(String queueName, String status) { + public int unlockSolidRedisSkipQueue(String queueName, String status) { log.info(String.format("unlockSolidRedisSkipQueue start %s", queueName)); String queueRedisKey = RedisKeyConst.getQueueRedisKey(queueName, false); List redisIds = redisTemplate.opsForList().range(queueRedisKey, 0, -1); @@ -114,7 +114,7 @@ public class QueueServiceImpl implements QueueService { return allQueueList.size(); } - private int unlockSolidRedisDeadQueue(String tableName, int heartbeatExpiredSeconds, String status) { + public int unlockSolidRedisDeadQueue(String tableName, int heartbeatExpiredSeconds, String status) { DateTime deadTime = DateUtil.offsetSecond(new Date(), -heartbeatExpiredSeconds); String where = String.format(" WHERE locked > 0 AND gmt_last_heartbeat < '%s' ", DateUtil.formatDateTime(deadTime)); if (StrUtil.isNotBlank(status)) { diff --git a/ms-biz/src/main/java/com/ms/api/task/CheckMaterialBizWaitTaskService.java b/ms-biz/src/main/java/com/ms/api/task/CheckMaterialBizWaitTaskService.java index 66f13c5b..16f5e3a4 100644 --- a/ms-biz/src/main/java/com/ms/api/task/CheckMaterialBizWaitTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/CheckMaterialBizWaitTaskService.java @@ -1,5 +1,6 @@ package com.ms.api.task; +import cn.hutool.core.util.ObjectUtil; import com.ms.api.common.TaskBaseService; import com.ms.api.consts.StatusConst; import com.ms.api.service.MaterialBizQueueService; @@ -90,7 +91,6 @@ public class CheckMaterialBizWaitTaskService extends TaskBaseService { startQueueId = queueIds.stream().max(Integer::compareTo).orElse(0); List waitQueueIds = materialBizToMaterialService.getMaterialBizToMaterialStatus(queueIds); - log.info("waitQueueIds: " + waitQueueIds); queueIds.forEach((queueId) -> { MaterialBizQueue materialBizQueue = materialBizQueueService.selectByPrimaryKey((long)queueId); if (!waitQueueIds.contains(queueId.longValue())) { @@ -100,8 +100,12 @@ public class CheckMaterialBizWaitTaskService extends TaskBaseService { return; } + int tryTimes = materialBizQueue.getTryTimes() + 1; + if(tryTimes > 127){ + tryTimes = 127; + } materialBizQueue.setGmtExec(Date.from(new Date().toInstant().plusSeconds(30))); - materialBizQueue.setTryTimes(materialBizQueue.getTryTimes() + 1); + materialBizQueue.setTryTimes(tryTimes); materialBizQueue.setGmtModified(new Date()); materialBizQueueService.updateByPrimaryKeySelective(materialBizQueue); }); diff --git a/ms-biz/src/main/java/com/ms/api/task/MoveUnlockTaskService.java b/ms-biz/src/main/java/com/ms/api/task/MoveUnlockTaskService.java index ad35cf82..ecbdf398 100644 --- a/ms-biz/src/main/java/com/ms/api/task/MoveUnlockTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/MoveUnlockTaskService.java @@ -32,7 +32,7 @@ public class MoveUnlockTaskService extends TaskBaseService { * 同时开启任务处理数量 */ public int getCorePoolSiz() { - return 3; + return 1; } /** @@ -57,7 +57,7 @@ public class MoveUnlockTaskService extends TaskBaseService { } @Async("moveUnlockTaskPool") - @Scheduled(fixedRate = 1000) + @Scheduled(fixedRate = 30000) @Override public void runTask() { super.runTask(); @@ -82,8 +82,13 @@ public class MoveUnlockTaskService extends TaskBaseService { log.info("start moveUnlockTask"); moveService.unlockMoveProductPublishToPicQueue(); moveService.unlockMoveProductPublishQueue(); + + // 审核状态队列 int heartBeatSec = 5 * 60; - unlockTimeoutQueue.unlockTimeoutSolidRedisQueue("material_audit_status_queue",heartBeatSec,""); + String tableName = "material_audit_status_queue"; + unlockTimeoutQueue.unlockSolidRedisDeadQueue(tableName, heartBeatSec, ""); +// unlockTimeoutQueue.unlockSolidRedisSkipQueue(tableName, ""); + unlockTimeoutQueue.unlockTimeoutQueue("material_biz_queue",heartBeatSec,""); log.info("end move unlock service"); return null;