|
|
package com.yoho.datasync.fullsync.quartz;
|
|
|
|
|
|
import com.yoho.datasync.fullsync.service.YohoNowDataSynService;
|
|
|
import com.yoho.quartz.annotation.JobType;
|
|
|
import com.yoho.quartz.annotation.MisfiredPolicy;
|
|
|
import com.yoho.quartz.annotation.YhJobDef;
|
|
|
import com.yoho.quartz.domain.JobProcessResult;
|
|
|
import com.yoho.quartz.domain.JobResultCode;
|
|
|
import com.yoho.quartz.job.YhJob;
|
|
|
import org.apache.commons.lang.exception.ExceptionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Configurable;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
/**
|
|
|
* Created by shengguo.cai on 2019/3/27.
|
|
|
* Created by shengguo.cai on 2019/3/28.
|
|
|
*/
|
|
|
@Component
|
|
|
@YhJobDef(jobName = "SynNowDataScheduler", desc = "now社区数据同步", cron = "1 1 16 * * ? ",
|
|
|
misfiredPolicy = MisfiredPolicy.SMART_POLICY, jobType = JobType.CRON, jobGroup = "system")
|
|
|
public class SynNowDataScheduler implements YhJob {
|
|
|
private final Logger logger = LoggerFactory.getLogger(SynNowDataScheduler.class);
|
|
|
@Configurable
|
|
|
@EnableScheduling
|
|
|
public class SynNowDataTask {
|
|
|
private final Logger logger = LoggerFactory.getLogger(SynNowDataTask.class);
|
|
|
|
|
|
@Autowired
|
|
|
private YohoNowDataSynService yohoNowDataSynService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public JobProcessResult process(String jobcontext) {
|
|
|
@Scheduled(cron = "0 0 2 * * ? ")
|
|
|
public void reportCurrentByCron(){
|
|
|
logger.info("enter SynNowDataScheduler.....");
|
|
|
|
|
|
JobProcessResult result = new JobProcessResult();
|
|
|
result.setJobResultCode(JobResultCode.SUCCESS);
|
|
|
boolean isStop = yohoNowDataSynService.getStop();
|
|
|
logger.info("current switch is {}",isStop);
|
|
|
if(isStop){
|
|
|
logger.info("SynNowDataScheduler clearSwitch is off ");
|
|
|
return result;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
logger.info("SynNowDataScheduler is runinng ...");
|
|
|
try {
|
|
|
//同步昨天一天的数据
|
|
|
Calendar calendar =Calendar.getInstance();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.add(Calendar.DATE,-1);
|
|
|
calendar.set(Calendar.HOUR,0);
|
|
|
calendar.set(Calendar.MINUTE,0);
|
...
|
...
|
@@ -61,14 +52,8 @@ public class SynNowDataScheduler implements YhJob { |
|
|
yohoNowDataSynService.synArticleAttach(begTime,endTime,0,false);
|
|
|
yohoNowDataSynService.synArticleAttach(begTime,endTime,1,false);
|
|
|
yohoNowDataSynService.synArticleAttach(begTime,endTime,2,false);
|
|
|
result.setJobResultCode(JobResultCode.SUCCESS);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("SynNowDataScheduler error {}", e);
|
|
|
result.setJobResultCode(JobResultCode.FAIL);
|
|
|
result.setDesc(ExceptionUtils.getStackTrace(e));
|
|
|
} finally {
|
|
|
logger.info("SynNowDataScheduler end , result is {}", result);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|