|
@@ -15,16 +15,17 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 处理考试过程中抓拍照片比对任务
|
|
|
+ * 处理人脸抓拍照片比对任务
|
|
|
*/
|
|
|
@Component
|
|
|
public class FaceVerifyJobHandler {
|
|
@@ -41,9 +42,6 @@ public class FaceVerifyJobHandler {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
FaceApiParam param = this.parseJobParam(jobParam);
|
|
|
|
|
|
- // 补偿机制:定期重置“错误次数”为0
|
|
|
- this.resetExamCaptureQueueErrorNum(param.getMaxErrorNum());
|
|
|
-
|
|
|
// 根据任务调度策略,推荐50
|
|
|
final int batchSize = 50;
|
|
|
|
|
@@ -119,28 +117,6 @@ public class FaceVerifyJobHandler {
|
|
|
todoQueues.clear();
|
|
|
}
|
|
|
|
|
|
- private void resetExamCaptureQueueErrorNum(int maxErrorNum) {
|
|
|
- final String lockKey = CacheConstants.LOCK_FACE_COMPARE_RESET;
|
|
|
- try {
|
|
|
- long startTime = System.currentTimeMillis();
|
|
|
- SequenceLockHelper.getLockSimple(lockKey);
|
|
|
-
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(new Date());
|
|
|
- c.add(Calendar.HOUR_OF_DAY, -6);// N个小时前的时间
|
|
|
- String beforeCreationTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime());
|
|
|
-
|
|
|
- int resetCount = examCaptureQueueRepo.resetExamCaptureQueueErrorNum(maxErrorNum, beforeCreationTime);
|
|
|
-
|
|
|
- long cost = System.currentTimeMillis() - startTime;
|
|
|
- log.warn("【人脸比对任务】 重置错误次数为0!影响条数:{} maxErrorNum:{} cost:{}ms", resetCount, maxErrorNum, cost);
|
|
|
- } catch (Exception e) {
|
|
|
- // ignore
|
|
|
- } finally {
|
|
|
- SequenceLockHelper.releaseLockSimple(lockKey);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private FaceApiParam parseJobParam(String jobParam) {
|
|
|
JsonNode jsonParams = new JsonMapper().getNode(jobParam);
|
|
|
if (jsonParams == null) {
|
|
@@ -151,13 +127,15 @@ public class FaceVerifyJobHandler {
|
|
|
|
|
|
JsonNode maxThreadNum = jsonParams.get("maxThreadNum");
|
|
|
if (maxThreadNum != null) {
|
|
|
- // 最大数不超过20
|
|
|
- param.setMaxThreadNum(Math.min(maxThreadNum.asInt(2), 20));
|
|
|
+ // 限制:最小值为1,最大值20
|
|
|
+ int x = Math.max(maxThreadNum.asInt(), 1);
|
|
|
+ param.setMaxThreadNum(Math.min(x, 20));
|
|
|
}
|
|
|
|
|
|
JsonNode maxErrorNum = jsonParams.get("maxErrorNum");
|
|
|
if (maxErrorNum != null) {
|
|
|
- param.setMaxErrorNum(maxErrorNum.asInt(10));
|
|
|
+ // 限制:最小值为1
|
|
|
+ param.setMaxErrorNum(Math.max(maxErrorNum.asInt(), 1));
|
|
|
}
|
|
|
|
|
|
JsonNode useBaiduApi = jsonParams.get("useBaiduApi");
|