3.2K Star 34.2K Fork 24.4K

若依 / RuoYi-Vue

 / 详情

定时任务运行过程中自己就停止了

待办的
创建于  
2024-05-14 11:36

定时任务跑着跑着自己就停了,程序也没报错,重启后台就又可以开始执行了
1.这个是定时任务调用目标字符串的方法

@Component("DownloadVehicleData")
public class DownloadVehicleData {

    /**
     * @Description: 下载防盗码数据
     * @Author: WZX
     * @Date: 2024/1/17
     */
    public void downloadKeyCodeData() throws Exception {
        keyCodeService.downloadKeyCodeData();
    }
}

2.这个是具体的实现的内容的代码

@Override
    @Transactional(rollbackFor = Exception.class)
    public void downloadKeyCodeData() throws Exception {
        String maxUpdateTime = serviceKeyCodeMapper.selectMaxUpdateTime();
        // 如果本地数据为空,就从系统参数中获取
        if (maxUpdateTime == null) {
            maxUpdateTime = configService.selectConfigByKey("keyCodeUpdateTime");
        }
        // 创建log
        LogUtils logUtils = new LogUtils(logPath + "/keyCodeData/", "keyCode-" + maxUpdateTime.replace(" ", "-").replace(":", "-"));
        try {
            String factoryCode = configService.selectConfigByKey("factoryCode");
            if (factoryCode == null) {
                throw new Exception("未维护工厂代号!");
            }
            JSONObject param = new JSONObject();
            param.put("pageSize", 50);
            param.put("startTime", maxUpdateTime);
            // 设置序列化特性,格式化输出
            SerializerFeature[] features = {SerializerFeature.PrettyFormat};
            // 格式化日期
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            logUtils.writeData("[" + format.format(new Date()) + "]:密文入参数据:");
            logUtils.writeData(JSON.toJSONString(param, features));
            ServiceExternalInterfaceInfo externalInterfaceInfo = externalInterfaceInfoService.selectByFactoryCodeAndKey(factoryCode, "keyCode-cipherData");
            if (externalInterfaceInfo == null) {
                throw new Exception("未维护工厂:" + factoryCode + "的明文Api信息");
            }
            JSONObject result = HttpRequest.sendPost(param, externalInterfaceInfo.getUrl(), externalInterfaceInfo.getAppKey(), externalInterfaceInfo.getSign());
            logUtils.writeData("[" + format.format(new Date()) + "]:密文出参数据:");
            logUtils.writeData(JSON.toJSONString(result, features));
            int size = result.getJSONArray("rows").size();
            if (size != 0) {
                JSONArray keyCodeArray = result.getJSONArray("rows");
                getKeyCodeMenu(keyCodeArray, logUtils, factoryCode);
            } else {
                interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "查询不到updateTime为:" + maxUpdateTime + "以后的防盗码密文数据");
                logUtils.writeData("查询不到updateTime为:" + maxUpdateTime + "以后的密文数据");
            }
            ServiceKeyCode serviceKeyCode = new ServiceKeyCode();
            serviceKeyCode.setStatus(0);
            List<ServiceKeyCode> serviceKeyCodes = serviceKeyCodeMapper.selectKeyCodeList(serviceKeyCode);
            if (serviceKeyCodes != null && serviceKeyCodes.size() > 0) {
                for (ServiceKeyCode keyCode : serviceKeyCodes) {
                    String vin = keyCode.getVin();
                    interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "vin为" + vin + "的防盗码明文数据为空,重新获取");
                    logger.info("vin为" + vin + "的明文数据为空,重新获取");
                    keyCode = selectDeCrYPtdData(vin, logUtils, factoryCode, keyCode);
                    if (keyCode.getStatus() == 1) {
                        interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.green, FunctionConstants.KeyCode, "vin为" + vin + "的防盗码明文数据重新获取成功");
                        logger.info("vin为" + vin + "的明文数据重新获取成功");
                        serviceKeyCodeMapper.updateKeyCode(keyCode);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("下载数据异常,{}", e.getMessage());
            interfaceOutputUtils.print(InterfaceOutputConstants.bottom, InterfaceOutputConstants.red, FunctionConstants.KeyCode, e.getMessage());
            dingUtils.sendMessage("下载数据异常:" + e.getMessage(), DingMsgTypeConstant.FAIL);
        } finally {
            logUtils.close();
        }
    }

3.定时任务的执行策略是 立即执行,禁止并发
大佬帮我看看这是咋回事

评论 (6)

sherlock 创建了任务

找到问题麻烦踢我一下

你也是这个问题嘛

解决了吗,我也是这个问题

解决了吗,我也遇到这个问题了。今天一看所有定时任务都在凌晨两点多之后没有日志了

注释掉那个ScheduleConfig以后,感觉稳定了一些

我这也有这问题,跑着跑着就不跑了

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(4)
4767090 vhukze 1578973993
JavaScript
1
https://gitee.com/y_project/RuoYi-Vue.git
git@gitee.com:y_project/RuoYi-Vue.git
y_project
RuoYi-Vue
RuoYi-Vue

搜索帮助

Bbcd6f05 5694891 0cc6727d 5694891