dengsixing 8 months ago
parent
commit
9496d9eaab

+ 36 - 1
src/main/java/com/fdkankan/modeling/ModelingApplication.java

@@ -1,19 +1,35 @@
 package com.fdkankan.modeling;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.model.utils.CreateObjUtil;
+import com.fdkankan.modeling.constants.SysConstants;
+import com.fdkankan.modeling.entity.BuildLog;
+import com.fdkankan.modeling.service.IBuildLogService;
+import lombok.extern.slf4j.Slf4j;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import java.util.List;
+
 @SpringBootApplication
 @EnableScheduling
 @ComponentScan(basePackages = {"com.fdkankan.*"})
 @MapperScan("com.fdkankan.**.mapper")
 @EnableDiscoveryClient
-public class ModelingApplication {
+@Slf4j
+public class ModelingApplication implements CommandLineRunner {
+
+	@Autowired
+	private IBuildLogService buildLogService;
 
 	public static void main(String[] args) {
 
@@ -24,4 +40,23 @@ public class ModelingApplication {
 
 	}
 
+	@Override
+	public void run(String... args) throws Exception {
+
+//		String lockPath = null;
+//		try {
+//			if(StrUtil.isNotEmpty(SysConstants.hostName)){
+//				List<BuildLog> list = buildLogService.list(new LambdaQueryWrapper<BuildLog>().eq(BuildLog::getHostName, SysConstants.hostName).eq(BuildLog::getStatus, 0).orderByDesc(BuildLog::getId));
+//				if(CollUtil.isNotEmpty(list)){
+//					BuildLog buildLog = list.get(0);
+//					lockPath = buildLog.getDataSource() + "/.lockdirectory";
+//					if(FileUtil.exist(lockPath)){
+//						FileUtil.del(lockPath);
+//					}
+//				}
+//			}
+//		}catch (Exception e){
+//			log.warn("删除上一计算中场景文件锁失败,logPath:{}", lockPath, e);
+//		}
+	}
 }

+ 7 - 0
src/main/java/com/fdkankan/modeling/receiver/RabbitMqListener.java

@@ -1,6 +1,7 @@
 package com.fdkankan.modeling.receiver;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ModelingBuildStatus;
@@ -129,6 +130,12 @@ public class RabbitMqListener {
             return;
         }
 
+        //进入计算之前,判断算法文件锁是否存在,如果存在,则删除
+        String lockPath = buildSceneMessage.getPath() + "/.lockdirectory";
+        if(FileUtil.exist(lockPath)){
+            FileUtil.del(lockPath);
+        }
+
         BuildLog buildLog = new BuildLog();
         log.info("场景计算开始,队列名:{},id:{},deliveryTag:{},消息体:{}", queueNameService.getQueueName(), messageId,deliveryTag,msg);
         buildLog.setMessageId(messageId);