|
@@ -62,37 +62,44 @@ public class SqlSynJob implements Job {
|
|
|
private JobBean job = null;
|
|
|
/** 任务缓存服务 */
|
|
|
private CacheBeanService cacheBeanService;
|
|
|
+ private JobService jobService = null;
|
|
|
+
|
|
|
+ private void initServices(ApplicationContext appCtx) {
|
|
|
+ this.taskService = appCtx.getBean(TaskService.class);
|
|
|
+ this.taskSqlService = appCtx.getBean(TaskSqlService.class);
|
|
|
+ this.dataSourceService = appCtx.getBean(DataSourceService.class);
|
|
|
+ this.cacheBeanService = appCtx.getBean(CacheBeanService.class);
|
|
|
+ this.jobService = appCtx.getBean(JobService.class);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
|
long start = System.currentTimeMillis();
|
|
|
- job = (JobBean) context.getJobDetail().getJobDataMap().get(JobService.PARAM_JOB);
|
|
|
+ SchedulerContext schCtx = null;
|
|
|
+ try {
|
|
|
+ schCtx = context.getScheduler().getContext();
|
|
|
+ } catch (SchedulerException e) {
|
|
|
+ log.error("get scheduler error:{}", e.getMessage());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ initServices((ApplicationContext) schCtx.get("applicationContext"));
|
|
|
+ String jobId = context.getJobDetail().getJobDataMap().getString(JobService.PARAM_JOB);
|
|
|
+ job = jobService.findOne(jobId);
|
|
|
if (null == job) {
|
|
|
throw new IllegalArgumentException("未找到执行任务信息!");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(job.getCode())) {
|
|
|
throw new IllegalArgumentException("job code不可为空!");
|
|
|
}
|
|
|
- try {
|
|
|
- SchedulerContext schCtx = context.getScheduler().getContext();
|
|
|
- ApplicationContext appCtx = (ApplicationContext) schCtx.get("applicationContext");
|
|
|
- this.taskService = appCtx.getBean(TaskService.class);
|
|
|
- this.taskSqlService = appCtx.getBean(TaskSqlService.class);
|
|
|
- this.dataSourceService = appCtx.getBean(DataSourceService.class);
|
|
|
- this.cacheBeanService = appCtx.getBean(CacheBeanService.class);
|
|
|
- List<TaskBean> tasks = taskService.selectByJobCode(job.getCode());
|
|
|
- for (TaskBean t : tasks) {
|
|
|
- // SQL 同步任务
|
|
|
- if (TaskBean.TYPE_SQL.equals(t.getType())) {
|
|
|
- doTaskSqlBeans(t);
|
|
|
- }
|
|
|
+
|
|
|
+ List<TaskBean> tasks = taskService.selectByJobCode(job.getCode());
|
|
|
+ for (TaskBean t : tasks) {
|
|
|
+ // SQL 同步任务
|
|
|
+ if (TaskBean.TYPE_SQL.equals(t.getType())) {
|
|
|
+ doTaskSqlBeans(t);
|
|
|
}
|
|
|
- } catch (SchedulerException e1) {
|
|
|
- e1.printStackTrace();
|
|
|
- } finally {
|
|
|
- long cost = System.currentTimeMillis() - start;
|
|
|
- log.info("任务执行完成,耗时:{}", cost);
|
|
|
}
|
|
|
+ log.info("任务执行完成,耗时:{}", System.currentTimeMillis() - start);
|
|
|
}
|
|
|
|
|
|
/**
|