标签:failed const constant ash 内容 modify nta 任务 状态
1 /** 2 * @ProjectName: BSP 海康威视大数据服务平台 3 * @Copyright: 2015 HangZhou Hikvision System Technology Co., Ltd. All Right Reserved. 4 * @address: http://www.hikvision.com 5 * @date: 2017年04月26日 11:30 6 * @Description: 本内容仅限于杭州海康威视数字技术股份有限公司内部使用,禁止转发. 7 */ 8 package com.hikvision.bsp.facecloud.task; 9 10 import com.hikvision.bsp.facecloud.config.SpringContextHolder; 11 import com.hikvision.facecloud.constant.FaceCloudConstant; 12 import com.hikvision.bsp.facecloud.domain.FaceCrashTaskJob; 13 import com.hikvision.bsp.facecloud.domain.FaceSimilarCheckEntity; 14 import com.hikvision.bsp.facecloud.queue.FaceCrashTaskQueue; 15 import com.hikvision.bsp.facecloud.service.IFaceSimilarCheckService; 16 import com.hikvision.bsp.facecloud.utils.DateUtil; 17 18 import java.util.*; 19 20 /** 21 * <p>静态库查重碰撞任务定时提交类</p> 22 * 23 * @author jianghongkang 2017年04月26日 11:30 24 * @version V1.0 25 * @modificationHistory=========================逻辑或功能性重大变更记录 26 * @modify by user: {修改人} ${date} 27 * @modify by reason: {方法名}:{原因} 28 */ 29 public class FaceSimilarCheckTimerTask { 30 31 private static final long daySpan = 24 * 60 * 60 * 1000; 32 33 private String taskId; 34 private int priority; 35 private Date beginDate; 36 private Date endDate; 37 38 private Timer t ; 39 40 public FaceSimilarCheckTimerTask(String taskId, int priority, String beginDate, String endDate) { 41 this.taskId = taskId; 42 this.priority = priority; 43 this.beginDate = DateUtil.getDayTime(beginDate); 44 this.endDate = DateUtil.getDayTime(endDate); 45 } 46 47 public void createTimeTask() { 48 Date timerBegin = beginDate; 49 long currentTime = System.currentTimeMillis(); 50 if (currentTime > endDate.getTime()) { 51 timerBegin = new Date(beginDate.getTime() + daySpan); 52 } 53 54 TimerTask task = new TimerTask() { 55 @Override 56 public void run() { 57 IFaceSimilarCheckService checkService = (IFaceSimilarCheckService) SpringContextHolder.getSpringContext() 58 .getBean("faceSimilarCheckService"); 59 List<FaceSimilarCheckEntity> entityList = checkService.getFaceCheckEntityByTaskId(taskId); 60 if (entityList != null && entityList.size() > 0) { 61 FaceSimilarCheckEntity entity = entityList.get(0); 62 int status = entity.getStatus(); 63 if ((status == FaceCloudConstant.FaceCheck.TASK_FINISHED) 64 || (status == FaceCloudConstant.FaceCheck.TASK_FAILED && 65 entity.getFails() >= FaceCloudConstant.FaceCheck.TASK_FAILED_THRESHOLD) 66 //暂停、删除状态 67 || status < FaceCloudConstant.FaceCheck.TASK_FAILED) { 68 //任务状态为完成、失败超过三次、暂停、删除情况时取消定时任务 69 closeTimer(); 70 return; 71 } 72 } 73 //添加任务到执行任务队列 74 FaceCrashTaskJob job = new FaceCrashTaskJob(); 75 job.setTaskId(taskId); 76 job.setPriority(priority); 77 job.setTaskType(FaceCloudConstant.FaceCheck.FACE_CRASH_TASK); 78 job.setIncrePriority(true); 79 if (!FaceCrashTaskQueue.getInstance().isContainTaskId(taskId)) { 80 FaceCrashTaskQueue.getInstance().addTask(job); 81 } 82 } 83 }; 84 t = new Timer(); 85 t.scheduleAtFixedRate(task, timerBegin, daySpan); 86 } 87 88 //取消定时任务 89 public void closeTimer() { 90 if (t != null) { 91 t.cancel(); 92 } 93 } 94 95 96 }
标签:failed const constant ash 内容 modify nta 任务 状态
原文地址:https://www.cnblogs.com/xjatj/p/9293584.html