|
@@ -2,8 +2,6 @@ package cn.com.qmth.examcloud.core.oe.student.face.starter.config;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.ApplicationArguments;
|
|
|
import org.springframework.boot.ApplicationRunner;
|
|
@@ -26,15 +24,53 @@ import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
|
|
|
@Order(201)
|
|
|
public class ProcessBaiduFacelivenessTask implements ApplicationRunner {
|
|
|
|
|
|
- private static final Logger log = LoggerFactory.getLogger(ProcessBaiduFacelivenessTask.class);
|
|
|
+ private static ExamCloudLog captureLog = ExamCloudLogFactory
|
|
|
+ .getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
|
|
|
|
|
|
@Autowired
|
|
|
ExamCaptureQueueRepo examCaptureQueueRepo;
|
|
|
|
|
|
- private static ExamCloudLog captureLog = ExamCloudLogFactory
|
|
|
- .getLog("PROCESS_EXAM_CAPTURE_TASK_LOGGER");
|
|
|
+ private void process(ConcurrentTask<ExamCaptureQueueEntity> concurrentTask,
|
|
|
+ String processBatchNum) {
|
|
|
+
|
|
|
+ // 如果队列没满,则从数据库中查数据并插入
|
|
|
+ List<ExamCaptureQueueEntity> examCaptureQueueList = examCaptureQueueRepo
|
|
|
+ .findNeedFacelivenessDetectExamCaptureQueuesLimit(
|
|
|
+ PropertyHolder.getInt("$capture.queue.limit", 100), processBatchNum);
|
|
|
+
|
|
|
+ if (null == examCaptureQueueList || examCaptureQueueList.isEmpty()) {
|
|
|
+ captureLog
|
|
|
+ .debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum + "] 抓拍队列中没有取到数据,2秒后重试");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum + "] 抓拍队列中的数据条数为:"
|
|
|
+ + examCaptureQueueList.size());
|
|
|
+
|
|
|
+ for (ExamCaptureQueueEntity offeredQueueEntity : examCaptureQueueList) {
|
|
|
+ while (true) {
|
|
|
+ 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
|
|
|
+ + "] 向工作队列中添加数据失败,30秒后重试:fileUrl=" + offeredQueueEntity.getFileUrl());
|
|
|
+
|
|
|
+ Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) {
|
|
|
|
|
|
- private void start() {
|
|
|
ConcurrentTask<ExamCaptureQueueEntity> concurrentTask = new ConcurrentTask<ExamCaptureQueueEntity>();
|
|
|
concurrentTask.setMaxActiveThreadSize(
|
|
|
PropertyHolder.getInt("$capture.thread.maxActiveThreadSize", 100));
|
|
@@ -45,59 +81,26 @@ public class ProcessBaiduFacelivenessTask implements ApplicationRunner {
|
|
|
String processBatchNum = "B_" + System.currentTimeMillis();
|
|
|
|
|
|
captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum + "] 启动百度处理服务...");
|
|
|
- while (true) {
|
|
|
- try {
|
|
|
- // 如果队列没满,则从数据库中查数据并插入
|
|
|
- List<ExamCaptureQueueEntity> examCaptureQueueList = examCaptureQueueRepo
|
|
|
- .findNeedFacelivenessDetectExamCaptureQueuesLimit(
|
|
|
- PropertyHolder.getInt("$capture.queue.limit", 100),
|
|
|
- processBatchNum);
|
|
|
- // 如果队列中没取到数据,则2秒钟后再取
|
|
|
- if (null == examCaptureQueueList || examCaptureQueueList.isEmpty()) {
|
|
|
- captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum
|
|
|
- + "] 抓拍队列中没有取到数据,2秒后重试");
|
|
|
-
|
|
|
- Util.sleep(PropertyHolder.getInt("$capture.queue.read.sleepSeconds.", 2));
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- captureLog.debug("[PROCESS_BAIDUFACELIVENESS." + processBatchNum + "] 抓拍队列中的数据条数为:"
|
|
|
- + examCaptureQueueList.size());
|
|
|
|
|
|
- for (ExamCaptureQueueEntity offeredQueueEntity : examCaptureQueueList) {
|
|
|
- while (true) {
|
|
|
- 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
|
|
|
- + "] 向工作队列中添加数据失败,30秒后重试:fileUrl="
|
|
|
- + offeredQueueEntity.getFileUrl());
|
|
|
-
|
|
|
- Util.sleep(PropertyHolder.getInt("$capture.queue.offer.sleepSeconds.", 30));
|
|
|
+ Thread thread = new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ process(concurrentTask, processBatchNum);
|
|
|
+ Util.sleep(PropertyHolder.getInt("$capture.queue.read.sleepSeconds.", 2));
|
|
|
+ } catch (Exception e) {
|
|
|
+ captureLog.error("[PROCESS_FACEPP." + processBatchNum + "] 百度活体检测出异常,3秒后重试",
|
|
|
+ e);
|
|
|
+ Util.sleep(3);
|
|
|
}
|
|
|
}
|
|
|
- Util.sleep(4);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("300002", "启动百度活体检测队列出现异常", e);
|
|
|
- captureLog.error(
|
|
|
- "[PROCESS_BAIDUFACELIVENESS." + processBatchNum + "] 百度活体检测出出异常,3秒后重试", e);
|
|
|
- Util.sleep(3);
|
|
|
+
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
- @Override
|
|
|
- public void run(ApplicationArguments args) {
|
|
|
- new Thread(() -> {
|
|
|
- start();
|
|
|
- }).start();
|
|
|
+ thread.setDaemon(true);
|
|
|
+ thread.start();
|
|
|
}
|
|
|
|
|
|
}
|