|
@@ -13,6 +13,9 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -39,42 +42,106 @@ public class Fd720Listener {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
log.warn("run Fd720Listener id: " + param);
|
|
|
- cmdPano(param);
|
|
|
+ processPano(param);
|
|
|
log.warn("end Fd720Listener id: "+ param);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void cmdPano(Long id) {
|
|
|
- log.info("start task cmdPano");
|
|
|
-// FodderEntity entity = fodderMapper.selectByPrimaryKey(id);
|
|
|
+ /**
|
|
|
+ * 切图会超时控制
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void processPano(Long id) {
|
|
|
+
|
|
|
+ log.warn("run processPano : " + id);
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
FodderEntity entity = fodderMapper.findById(id);
|
|
|
if (entity == null) {
|
|
|
log.error("场景不存在: " + id);
|
|
|
// 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
|
|
|
return;
|
|
|
}
|
|
|
+ String panoPath = entity.getFilePath();
|
|
|
+ String sceneCode = entity.getSceneCode();
|
|
|
+ String cmd = CmdConstant.PANO_KRPANO + panoPath;
|
|
|
+
|
|
|
+
|
|
|
+ // 超时处理机制
|
|
|
+ final ExecutorService exec = Executors.newFixedThreadPool(1);
|
|
|
+ Callable<String> call = new Callable<String>() {
|
|
|
+ @Override
|
|
|
+ public String call() throws Exception {
|
|
|
+ CmdUtils.callLine(cmd, 200);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
|
+ log.warn("end processListener : "+ id);
|
|
|
+ return "执行完成";
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 超时回调
|
|
|
+ Future<String> future = exec.submit(call);
|
|
|
try {
|
|
|
-
|
|
|
- // 切图
|
|
|
- long start = System.currentTimeMillis();
|
|
|
- String panoPath = entity.getFilePath();
|
|
|
- String sceneCode = entity.getSceneCode();
|
|
|
- String cmd = CmdConstant.PANO_KRPANO + panoPath;
|
|
|
- log.info("cmd: " + cmd);
|
|
|
- CmdUtils.cmdPano(cmd);
|
|
|
- long end = System.currentTimeMillis();
|
|
|
- log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
|
- uploadOss(sceneCode);
|
|
|
+ String obj = future.get(3, TimeUnit.MINUTES); //任务处理超时时间设为 3分钟
|
|
|
entity.setStatus(3);
|
|
|
- } catch (Exception e) {
|
|
|
+ // 上传切图
|
|
|
+ uploadOss(sceneCode);
|
|
|
+ log.info("任务成功返回: " + obj);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(trace));
|
|
|
+ log.error("超时了 1");
|
|
|
+ // 异常日志要打印,不然不会出现在日志文件中,只会出现在控制台
|
|
|
+ log.error(trace.toString());
|
|
|
entity.setStatus(2);
|
|
|
+ future.cancel(true);
|
|
|
+ } catch (TimeoutException e) {
|
|
|
e.printStackTrace();
|
|
|
+ StringWriter trace=new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(trace));
|
|
|
+ log.error("超时了 2");
|
|
|
+ log.error(trace.toString());
|
|
|
+ entity.setStatus(2);
|
|
|
+ future.cancel(true);
|
|
|
} finally {
|
|
|
fodderMapper.updateByPrimaryKey(entity);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+// public void cmdPano(Long id) {
|
|
|
+// log.info("start task cmdPano");
|
|
|
+//// FodderEntity entity = fodderMapper.selectByPrimaryKey(id);
|
|
|
+// FodderEntity entity = fodderMapper.findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// log.error("场景不存在: " + id);
|
|
|
+// // 直接结束,抛异常的话,会造成死循环,产生大量日志,而且队列也跑不下去
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// try {
|
|
|
+//
|
|
|
+// // 切图
|
|
|
+// long start = System.currentTimeMillis();
|
|
|
+// String panoPath = entity.getFilePath();
|
|
|
+// String sceneCode = entity.getSceneCode();
|
|
|
+// String cmd = CmdConstant.PANO_KRPANO + panoPath;
|
|
|
+//// log.info("cmd: " + cmd);
|
|
|
+// CmdUtils.cmdPano(cmd);
|
|
|
+// long end = System.currentTimeMillis();
|
|
|
+// log.info("切图完成耗时: {} s" ,(end-start)/1000);
|
|
|
+// uploadOss(sceneCode);
|
|
|
+// entity.setStatus(3);
|
|
|
+// } catch (Exception e) {
|
|
|
+// entity.setStatus(2);
|
|
|
+// e.printStackTrace();
|
|
|
+// } finally {
|
|
|
+// fodderMapper.updateByPrimaryKey(entity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 上传切图目录
|
|
|
*/
|