lideyin 5 жил өмнө
parent
commit
6f273ed25f

+ 18 - 10
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessBaiduFacelivenessTask.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
 
 import java.util.List;
 
+import org.apache.logging.log4j.ThreadContext;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
@@ -48,20 +49,27 @@ public class ProcessBaiduFacelivenessTask implements ApplicationRunner {
 
         for (ExamCaptureQueueEntity offeredQueueEntity : examCaptureQueueList) {
             while (true) {
-                boolean offerSuccess = concurrentTask.offerElement(offeredQueueEntity);
-                if (offerSuccess) {
-                    offeredQueueEntity.setProcessBatchNum(processBatchNum);
-                    examCaptureQueueRepo.save(offeredQueueEntity);
+                try{
+                    ThreadContext.put("TRACE_ID", "Q_" + offeredQueueEntity.getId());
+                    ThreadContext.put("CALLER", "BAIDU_TASK");
+                    boolean offerSuccess = concurrentTask.offerElement(offeredQueueEntity);
+                    if (offerSuccess) {
+                        offeredQueueEntity.setProcessBatchNum(processBatchNum);
+                        examCaptureQueueRepo.save(offeredQueueEntity);
+
+                        captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum
+                                + "] 向工作队列中添加数据成功:fileUrl=" + offeredQueueEntity.getFileUrl());
+                        break;
+                    }
 
                     captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum
-                            + "] 向工作队列中添加数据成功:fileUrl=" + offeredQueueEntity.getFileUrl());
-                    break;
-                }
+                            + "] 向工作队列中添加数据失败,30秒后重试:fileUrl=" + offeredQueueEntity.getFileUrl());
 
-                captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum
-                        + "] 向工作队列中添加数据失败,30秒后重试:fileUrl=" + offeredQueueEntity.getFileUrl());
+                    Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
+                }finally {
+                    ThreadContext.clearAll();
+                }
 
-                Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
             }
         }
         return examCaptureQueueList.size();

+ 19 - 11
examcloud-core-oe-face-starter/src/main/java/cn/com/qmth/examcloud/core/oe/student/face/starter/config/ProcessFaceCompareQueueTask.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
 
 import java.util.List;
 
+import org.apache.logging.log4j.ThreadContext;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
@@ -50,21 +51,28 @@ public class ProcessFaceCompareQueueTask implements ApplicationRunner {
 
         for (ExamCaptureQueueEntity offeredQueueEntity : examCaptureQueueList) {
             while (true) {
-                boolean offerSuccess = concurrentTask.offerElement(offeredQueueEntity);
-                // 如果向队列中添加数据成功,则更新标识
-                if (offerSuccess) {
-                    offeredQueueEntity.setProcessBatchNum(processBatchNum);
-                    examCaptureQueueRepo.save(offeredQueueEntity);
+                try{
+                    ThreadContext.put("TRACE_ID", "Q_" + offeredQueueEntity.getId());
+                    ThreadContext.put("CALLER", "FACEPP_TASK");
+                    boolean offerSuccess = concurrentTask.offerElement(offeredQueueEntity);
+                    // 如果向队列中添加数据成功,则更新标识
+                    if (offerSuccess) {
+                        offeredQueueEntity.setProcessBatchNum(processBatchNum);
+                        examCaptureQueueRepo.save(offeredQueueEntity);
+
+                        captureLog.debug("[PROCESS_FACEPP." + processBatchNum
+                                + "] 向工作队列中添加数据成功:fileUrl=" + offeredQueueEntity.getFileUrl());
+                        break;
+                    }
 
                     captureLog.debug("[PROCESS_FACEPP." + processBatchNum
-                            + "] 向工作队列中添加数据成功:fileUrl=" + offeredQueueEntity.getFileUrl());
-                    break;
-                }
+                            + "] 向工作队列中添加数据失败,30秒后重试:fileUrl=" + offeredQueueEntity.getFileUrl());
 
-                captureLog.debug("[PROCESS_FACEPP." + processBatchNum
-                        + "] 向工作队列中添加数据失败,30秒后重试:fileUrl=" + offeredQueueEntity.getFileUrl());
+                    Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
+                }finally {
+                    ThreadContext.clearAll();
+                }
 
-                Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
             }
         }
         return examCaptureQueueList.size();