| | |
| | | public CronTrigger getCronTrigger (Integer jobId){ |
| | | try { |
| | | return (CronTrigger) this.scheduler.getTrigger(getTriggerKey(jobId)) ; |
| | | } catch (SchedulerException e){ |
| | | throw new RuntimeException("getCronTrigger Fail",e) ; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | // throw new RuntimeException("createJob Fail",e) ; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | JobDetail jobDetail = JobBuilder.newJob(QuartzRecord.class) |
| | | .withIdentity(getJobKey(quartzJob.getId())).build() ; |
| | | |
| | | |
| | | // 构建Cron调度器 |
| | | CronScheduleBuilder scheduleBuilder = CronScheduleBuilder |
| | | .cronSchedule(quartzJob.getCronExpres()) |
| | | .withMisfireHandlingInstructionDoNothing() ; |
| | | |
| | | // 任务触发器 |
| | | CronTrigger trigger = TriggerBuilder.newTrigger() |
| | | .withIdentity(getTriggerKey(quartzJob.getId())) |
| | |
| | | scheduler.scheduleJob(jobDetail,trigger) ; |
| | | // 状态校验 |
| | | checkStop(quartzJob) ; |
| | | } catch (SchedulerException e){ |
| | | throw new RuntimeException("createJob Fail",e) ; |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | // throw new RuntimeException("createJob Fail",e) ; |
| | | } |
| | | } |
| | | |
| | |
| | | scheduler.rescheduleJob(triggerKey, trigger); |
| | | // 状态校验 |
| | | checkStop(quartzJob) ; |
| | | } catch (SchedulerException e) { |
| | | throw new RuntimeException("updateJob Fail",e) ; |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | // throw new RuntimeException("createJob Fail",e) ; |
| | | } |
| | | } |
| | | |
| | |
| | | JobDataMap dataMap = new JobDataMap() ; |
| | | dataMap.put(QuartzJob.JOB_PARAM_KEY,quartzJob); |
| | | this.scheduler.triggerJob(getJobKey(quartzJob.getId()),dataMap); |
| | | } catch (SchedulerException e){ |
| | | throw new RuntimeException("run Fail",e) ; |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | // throw new RuntimeException("createJob Fail",e) ; |
| | | } |
| | | } |
| | | |
| | |
| | | if(quartzJob.getState() != JobState.JOB_RUN.getStatus()){ |
| | | this.scheduler.pauseJob(getJobKey(quartzJob.getId())); |
| | | } |
| | | } catch (SchedulerException e){ |
| | | throw new RuntimeException("pauseJob Fail",e) ; |
| | | } catch (Exception e){ |
| | | e.printStackTrace(); |
| | | // throw new RuntimeException("createJob Fail",e) ; |
| | | } |
| | | } |
| | | |