下发任务超时触发任务超时并重新给终端分配任务
parent
b71224ed9b
commit
25ec97a03c
@ -0,0 +1,26 @@
|
|||||||
|
package com.docus.server;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.listener.ChannelTopic;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RedisListenerConfig {
|
||||||
|
@Autowired
|
||||||
|
private RedisConnectionFactory redisConnectionFactory;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ChannelTopic expiredTopic() {
|
||||||
|
return new ChannelTopic("__keyevent@0__:expired"); // 选择0号数据库
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisMessageListenerContainer redisMessageListenerContainer() {
|
||||||
|
RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
|
||||||
|
redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
|
||||||
|
return redisMessageListenerContainer;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.docus.server.common;
|
||||||
|
|
||||||
|
import com.docus.server.service.impl.RedisKeyExpirationService;
|
||||||
|
import org.springframework.data.redis.connection.Message;
|
||||||
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||||
|
|
||||||
|
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||||
|
super(listenerContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisKeyExpirationService redisKeyExpirationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开启notify-keyspace-events Ex的配置
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onMessage(Message message, byte[] pattern) {
|
||||||
|
|
||||||
|
String expireKey = message.toString();
|
||||||
|
if (validExpireKey(expireKey)) {
|
||||||
|
redisKeyExpirationService.expired(expireKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validExpireKey(String expireKey) {
|
||||||
|
return expireKey.startsWith("schCollectorRecord:noRetryTask:expireKey:")
|
||||||
|
|| expireKey.startsWith("schCollectorRecord:isRetryTask:expireKey:");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package com.docus.server.service.impl;
|
||||||
|
|
||||||
|
import com.docus.core.util.DateUtil;
|
||||||
|
import com.docus.log.annotation.TrackGroup;
|
||||||
|
import com.docus.server.common.process.ChannelProcessor;
|
||||||
|
import com.docus.server.entity.scheduling.management.SchCollectRecord;
|
||||||
|
import com.docus.server.entity.scheduling.management.SchCollectRecordRetryLog;
|
||||||
|
import com.docus.server.enums.StateEnum;
|
||||||
|
import com.docus.server.enums.SubStateEnum;
|
||||||
|
import com.docus.server.infrastructure.dao.ISchCollectRecordDao;
|
||||||
|
import com.docus.server.infrastructure.dao.ISchCollectRecordRetryLogDao;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RedisKeyExpirationService {
|
||||||
|
@Resource
|
||||||
|
private ISchCollectRecordDao iSchCollectRecordDao;
|
||||||
|
@Resource
|
||||||
|
private ISchCollectRecordRetryLogDao iSchCollectRecordRetryLogDao;
|
||||||
|
|
||||||
|
@TrackGroup(group = "RedisKeyExpirationService-expired", processor = ChannelProcessor.class)
|
||||||
|
public void expired(String expireKey) {
|
||||||
|
|
||||||
|
if (expireKey.startsWith("schCollectorRecord:noRetryTask:expireKey:")) {
|
||||||
|
System.out.println("expireKey过期了===" + expireKey);
|
||||||
|
|
||||||
|
String recordId = expireKey.substring(expireKey.lastIndexOf(":") + 1);
|
||||||
|
|
||||||
|
SchCollectRecord collectRecord = iSchCollectRecordDao.findById(recordId);
|
||||||
|
collectRecord.setTaskExecState(StateEnum.FAIL);
|
||||||
|
//超时作废
|
||||||
|
collectRecord.setSubTaskExecState(SubStateEnum.CANCEL);
|
||||||
|
collectRecord.setUpdateTime(DateUtil.now());
|
||||||
|
collectRecord.setLastTaskErrorMsg("任务超时,触发任务作废");
|
||||||
|
iSchCollectRecordDao.updateById(collectRecord);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (expireKey.startsWith("schCollectorRecord:isRetryTask:expireKey:")) {
|
||||||
|
System.out.println("expireKey过期了===" + expireKey);
|
||||||
|
|
||||||
|
String logRecordId = expireKey.substring(expireKey.lastIndexOf(":") + 1);
|
||||||
|
|
||||||
|
SchCollectRecordRetryLog recordRetryLog = iSchCollectRecordRetryLogDao.findById(logRecordId);
|
||||||
|
recordRetryLog.setTaskExecState(StateEnum.FAIL);
|
||||||
|
recordRetryLog.setSubTaskExecState(SubStateEnum.CANCEL);
|
||||||
|
recordRetryLog.setUpdateTime(DateUtil.now());
|
||||||
|
recordRetryLog.setLastTaskErrorMsg("任务超时,触发任务作废");
|
||||||
|
iSchCollectRecordRetryLogDao.updateById(recordRetryLog);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue