Showing
1 changed file
with
12 additions
and
27 deletions
1 | package com.yoho.datasync.fullsync.quartz; | 1 | package com.yoho.datasync.fullsync.quartz; |
2 | 2 | ||
3 | import com.yoho.datasync.fullsync.service.YohoNowDataSynService; | 3 | import com.yoho.datasync.fullsync.service.YohoNowDataSynService; |
4 | -import com.yoho.quartz.annotation.JobType; | ||
5 | -import com.yoho.quartz.annotation.MisfiredPolicy; | ||
6 | -import com.yoho.quartz.annotation.YhJobDef; | ||
7 | -import com.yoho.quartz.domain.JobProcessResult; | ||
8 | -import com.yoho.quartz.domain.JobResultCode; | ||
9 | -import com.yoho.quartz.job.YhJob; | ||
10 | -import org.apache.commons.lang.exception.ExceptionUtils; | ||
11 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
12 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
13 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
7 | +import org.springframework.beans.factory.annotation.Configurable; | ||
8 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
9 | +import org.springframework.scheduling.annotation.Scheduled; | ||
14 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
15 | 11 | ||
16 | import java.util.Calendar; | 12 | import java.util.Calendar; |
17 | 13 | ||
18 | /** | 14 | /** |
19 | - * Created by shengguo.cai on 2019/3/27. | 15 | + * Created by shengguo.cai on 2019/3/28. |
20 | */ | 16 | */ |
21 | @Component | 17 | @Component |
22 | -@YhJobDef(jobName = "SynNowDataScheduler", desc = "now社区数据同步", cron = "1 1 16 * * ? ", | ||
23 | - misfiredPolicy = MisfiredPolicy.SMART_POLICY, jobType = JobType.CRON, jobGroup = "system") | ||
24 | -public class SynNowDataScheduler implements YhJob { | ||
25 | - private final Logger logger = LoggerFactory.getLogger(SynNowDataScheduler.class); | 18 | +@Configurable |
19 | +@EnableScheduling | ||
20 | +public class SynNowDataTask { | ||
21 | + private final Logger logger = LoggerFactory.getLogger(SynNowDataTask.class); | ||
26 | 22 | ||
27 | @Autowired | 23 | @Autowired |
28 | private YohoNowDataSynService yohoNowDataSynService; | 24 | private YohoNowDataSynService yohoNowDataSynService; |
29 | 25 | ||
30 | - | ||
31 | - @Override | ||
32 | - public JobProcessResult process(String jobcontext) { | 26 | + @Scheduled(cron = "0 0 2 * * ? ") |
27 | + public void reportCurrentByCron(){ | ||
33 | logger.info("enter SynNowDataScheduler....."); | 28 | logger.info("enter SynNowDataScheduler....."); |
34 | - | ||
35 | - JobProcessResult result = new JobProcessResult(); | ||
36 | - result.setJobResultCode(JobResultCode.SUCCESS); | ||
37 | boolean isStop = yohoNowDataSynService.getStop(); | 29 | boolean isStop = yohoNowDataSynService.getStop(); |
38 | logger.info("current switch is {}",isStop); | 30 | logger.info("current switch is {}",isStop); |
39 | if(isStop){ | 31 | if(isStop){ |
40 | logger.info("SynNowDataScheduler clearSwitch is off "); | 32 | logger.info("SynNowDataScheduler clearSwitch is off "); |
41 | - return result; | 33 | + return ; |
42 | } | 34 | } |
43 | - | ||
44 | logger.info("SynNowDataScheduler is runinng ..."); | 35 | logger.info("SynNowDataScheduler is runinng ..."); |
45 | try { | 36 | try { |
46 | //同步昨天一天的数据 | 37 | //同步昨天一天的数据 |
47 | - Calendar calendar =Calendar.getInstance(); | 38 | + Calendar calendar = Calendar.getInstance(); |
48 | calendar.add(Calendar.DATE,-1); | 39 | calendar.add(Calendar.DATE,-1); |
49 | calendar.set(Calendar.HOUR,0); | 40 | calendar.set(Calendar.HOUR,0); |
50 | calendar.set(Calendar.MINUTE,0); | 41 | calendar.set(Calendar.MINUTE,0); |
@@ -61,14 +52,8 @@ public class SynNowDataScheduler implements YhJob { | @@ -61,14 +52,8 @@ public class SynNowDataScheduler implements YhJob { | ||
61 | yohoNowDataSynService.synArticleAttach(begTime,endTime,0,false); | 52 | yohoNowDataSynService.synArticleAttach(begTime,endTime,0,false); |
62 | yohoNowDataSynService.synArticleAttach(begTime,endTime,1,false); | 53 | yohoNowDataSynService.synArticleAttach(begTime,endTime,1,false); |
63 | yohoNowDataSynService.synArticleAttach(begTime,endTime,2,false); | 54 | yohoNowDataSynService.synArticleAttach(begTime,endTime,2,false); |
64 | - result.setJobResultCode(JobResultCode.SUCCESS); | ||
65 | } catch (Exception e) { | 55 | } catch (Exception e) { |
66 | logger.error("SynNowDataScheduler error {}", e); | 56 | logger.error("SynNowDataScheduler error {}", e); |
67 | - result.setJobResultCode(JobResultCode.FAIL); | ||
68 | - result.setDesc(ExceptionUtils.getStackTrace(e)); | ||
69 | - } finally { | ||
70 | - logger.info("SynNowDataScheduler end , result is {}", result); | ||
71 | - return result; | ||
72 | } | 57 | } |
73 | } | 58 | } |
74 | } | 59 | } |
-
Please register or login to post a comment