Java Code Examples for org.quartz.Scheduler#checkExists()
The following examples show how to use
org.quartz.Scheduler#checkExists() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobServiceImpl.java From griffin with Apache License 2.0 | 8 votes |
private JobDetail addJobDetail(TriggerKey triggerKey, AbstractJob job) throws SchedulerException { Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(triggerKey.getName(), triggerKey.getGroup()); JobDetail jobDetail; Boolean isJobKeyExist = scheduler.checkExists(jobKey); if (isJobKeyExist) { jobDetail = scheduler.getJobDetail(jobKey); } else { jobDetail = newJob(JobInstance.class).storeDurably().withIdentity (jobKey).build(); } setJobDataMap(jobDetail, job); scheduler.addJob(jobDetail, isJobKeyExist); return jobDetail; }
Example 2
Source File: JobServiceImpl.java From spring-boot-quartz-demo with MIT License | 6 votes |
/** * Check job exist with given name */ @Override public boolean isJobWithNamePresent(String jobName) { try { String groupKey = "SampleGroup"; JobKey jobKey = new JobKey(jobName, groupKey); Scheduler scheduler = schedulerFactoryBean.getScheduler(); if (scheduler.checkExists(jobKey)){ return true; } } catch (SchedulerException e) { System.out.println("SchedulerException while checking job with name and group exist:"+e.getMessage()); e.printStackTrace(); } return false; }
Example 3
Source File: JobInstance.java From griffin with Apache License 2.0 | 6 votes |
private JobDetail addJobDetail(TriggerKey tk, String pJobName) throws SchedulerException, IOException { Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(tk.getName(), tk.getGroup()); JobDetail jobDetail; Boolean isJobKeyExist = scheduler.checkExists(jobKey); if (isJobKeyExist) { jobDetail = scheduler.getJobDetail(jobKey); } else { jobDetail = newJob(SparkSubmitJob.class) .storeDurably() .withIdentity(jobKey) .build(); } setJobDataMap(jobDetail, pJobName); scheduler.addJob(jobDetail, isJobKeyExist); return jobDetail; }
Example 4
Source File: JobServiceImpl.java From griffin with Apache License 2.0 | 6 votes |
@Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } }
Example 5
Source File: CallMonitor.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Cancel the reconnect job. */ public void shutdownReconnectJob() { Scheduler sched = null; try { sched = StdSchedulerFactory.getDefaultScheduler(); JobKey jobKey = jobKey("Reconnect", "FritzBox"); if (sched.checkExists(jobKey)) { logger.debug("Found reconnection job. Shutting down..."); sched.deleteJob(jobKey); } } catch (SchedulerException e) { logger.warn("Error shutting down reconnect job: {}", e.getLocalizedMessage()); } }
Example 6
Source File: ScheduleUtils.java From supplierShop with MIT License | 5 votes |
/** * 创建定时任务 */ public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException { Class<? extends Job> jobClass = getQuartzJobClass(job); // 构建job信息 Long jobId = job.getJobId(); String jobGroup = job.getJobGroup(); JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); // 表达式调度构建器 CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); // 按新的cronExpression表达式构建一个新的trigger CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) .withSchedule(cronScheduleBuilder).build(); // 放入参数,运行时的方法可以获取 jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); // 判断是否存在 if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { // 防止创建时存在数据问题 先移除,然后在执行创建操作 scheduler.deleteJob(getJobKey(jobId, jobGroup)); } scheduler.scheduleJob(jobDetail, trigger); // 暂停任务 if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) { scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); } }
Example 7
Source File: CallMonitor.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Reset the connection to fbox periodically. */ public void setupReconnectJob() { try { // String cronPattern = "0 0 0 * * ?"; //every day // String cronPattern = "0 * * * * ?"; //every minute String cronPattern = "0 0 0/2 * * ?"; // every 2 hrs Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobKey jobKey = jobKey("Reconnect", "FritzBox"); TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox"); if (sched.checkExists(jobKey)) { logger.debug("reconnection job already exists"); } else { CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronPattern); JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build(); CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled reconnection job to FritzBox: {}", cronPattern); } } catch (SchedulerException e) { logger.warn("Could not create daily reconnection job", e); } }
Example 8
Source File: SchedulerUtil.java From OpenFalcon-SuitAgent with Apache License 2.0 | 5 votes |
/** * 执行计划任务 * @param job * @param trigger * @return * @throws SchedulerException */ public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException { ScheduleJobResult scheduleJobResult = new ScheduleJobResult(); //判断是否满足计划任务的创建条件 if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){ scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED); //不满足计划任务的创建条件,返回scheduleJobResult值类 return scheduleJobResult; } scheduleJobResult.setJobDetail(job); scheduleJobResult.setTrigger(trigger); //开始分配计划任务 Scheduler scheduler = SchedulerFactory.getScheduler(); //开始判断是否存在相同的计划任务 if(scheduler.checkExists(job.getKey())){ log.info("存在相同的计划任务:{}",job.getKey()); scheduler.deleteJob(job.getKey()); scheduleJobResult.setJobKey(job.getKey()); scheduleJobResult.setTriggerKey(trigger.getKey()); scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST); scheduler.scheduleJob(job,trigger); scheduler.start(); }else{ scheduler.scheduleJob(job,trigger); scheduler.start(); scheduleJobResult.setJobKey(job.getKey()); scheduleJobResult.setTriggerKey(trigger.getKey()); scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS); } //计划任务分配成功 return scheduleJobResult; }
Example 9
Source File: SchedulerUtil.java From SuitAgent with Apache License 2.0 | 5 votes |
/** * 执行计划任务 * @param job * @param trigger * @return * @throws SchedulerException */ public static ScheduleJobResult executeScheduleJob(JobDetail job, Trigger trigger) throws SchedulerException { ScheduleJobResult scheduleJobResult = new ScheduleJobResult(); //判断是否满足计划任务的创建条件 if(job.getKey() == null || trigger.getKey() == null || job.getJobDataMap() == null){ scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.FAILED); //不满足计划任务的创建条件,返回scheduleJobResult值类 return scheduleJobResult; } scheduleJobResult.setJobDetail(job); scheduleJobResult.setTrigger(trigger); //开始分配计划任务 Scheduler scheduler = SchedulerFactory.getScheduler(); //开始判断是否存在相同的计划任务 if(scheduler.checkExists(job.getKey())){ log.info("存在相同的计划任务:{}",job.getKey()); scheduler.deleteJob(job.getKey()); scheduleJobResult.setJobKey(job.getKey()); scheduleJobResult.setTriggerKey(trigger.getKey()); scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.ISEXIST); scheduler.scheduleJob(job,trigger); scheduler.start(); }else{ scheduler.scheduleJob(job,trigger); scheduler.start(); scheduleJobResult.setJobKey(job.getKey()); scheduleJobResult.setTriggerKey(trigger.getKey()); scheduleJobResult.setScheduleJobStatus(ScheduleJobStatus.SUCCESS); } //计划任务分配成功 return scheduleJobResult; }
Example 10
Source File: BatchJobOperatorImpl.java From griffin with Apache License 2.0 | 5 votes |
private void pauseJob(String group, String name) throws SchedulerException { if (StringUtils.isEmpty(group) || StringUtils.isEmpty(name)) { return; } Scheduler scheduler = factory.getScheduler(); JobKey jobKey = new JobKey(name, group); if (!scheduler.checkExists(jobKey)) { LOGGER.warn("Job({},{}) does not exist.", jobKey.getGroup(), jobKey .getName()); throw new GriffinException.NotFoundException (JOB_KEY_DOES_NOT_EXIST); } scheduler.pauseJob(jobKey); }
Example 11
Source File: BatchJobOperatorImpl.java From griffin with Apache License 2.0 | 5 votes |
public void deleteJob(String group, String name) throws SchedulerException { Scheduler scheduler = factory.getScheduler(); JobKey jobKey = new JobKey(name, group); if (!scheduler.checkExists(jobKey)) { LOGGER.info("Job({},{}) does not exist.", jobKey.getGroup(), jobKey .getName()); return; } scheduler.deleteJob(jobKey); }
Example 12
Source File: DaemonTaskScheduler.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
private void scheduleJob(final Scheduler scheduler, final JobDetail jobDetail, final String triggerIdentity, final String cron) { try { if (!scheduler.checkExists(jobDetail.getKey())) { scheduler.scheduleJob(jobDetail, createTrigger(triggerIdentity, cron)); } scheduler.start(); RUNNING_SCHEDULERS.putIfAbsent(scheduler.getSchedulerName(), scheduler); } catch (final SchedulerException ex) { throw new JobSystemException(ex); } }
Example 13
Source File: ScheduleUtils.java From RuoYi-Vue with MIT License | 5 votes |
/** * 创建定时任务 */ public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException { Class<? extends Job> jobClass = getQuartzJobClass(job); // 构建job信息 Long jobId = job.getJobId(); String jobGroup = job.getJobGroup(); JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); // 表达式调度构建器 CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder); // 按新的cronExpression表达式构建一个新的trigger CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) .withSchedule(cronScheduleBuilder).build(); // 放入参数,运行时的方法可以获取 jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); // 判断是否存在 if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { // 防止创建时存在数据问题 先移除,然后在执行创建操作 scheduler.deleteJob(getJobKey(jobId, jobGroup)); } scheduler.scheduleJob(jobDetail, trigger); // 暂停任务 if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) { scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); } }
Example 14
Source File: FritzboxBinding.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String ip = Objects.toString(config.get("ip"), null); if (StringUtils.isNotBlank(ip)) { if (!ip.equals(FritzboxBinding.ip)) { // only do something if the ip has changed FritzboxBinding.ip = ip; conditionalDeActivate(); // schedule a daily reconnection as sometimes the FritzBox // stops sending data // and thus blocks the monitor thread try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); JobKey jobKey = jobKey("Reconnect", "FritzBox"); TriggerKey triggerKey = triggerKey("Reconnect", "FritzBox"); if (sched.checkExists(jobKey)) { logger.debug("Daily reconnection job already exists"); } else { CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronSchedule); JobDetail job = newJob(ReconnectJob.class).withIdentity(jobKey).build(); CronTrigger trigger = newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder) .build(); sched.scheduleJob(job, trigger); logger.debug("Scheduled a daily reconnection to FritzBox on {}:{}", ip, MONITOR_PORT); } } catch (SchedulerException e) { logger.warn("Could not create daily reconnection job", e); } } } String password = Objects.toString(config.get("password"), null); if (StringUtils.isNotBlank(password)) { FritzboxBinding.password = password; } String username = Objects.toString(config.get("user"), null); if (StringUtils.isNotBlank(username)) { FritzboxBinding.username = username; } } }
Example 15
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 2 votes |
/** * 核查Trigger在scheduler是否存在 * 存在true * 不存在false * * @param scheduler * @param triggerName * @param triggerGroup * @return * @throws SchedulerException */ public static boolean checkTriggerExists(String triggerName, String triggerGroup, Scheduler scheduler) throws SchedulerException { TriggerKey triggerKey = getTriggerKey(triggerName, triggerGroup); return scheduler.checkExists(triggerKey); }
Example 16
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 2 votes |
/** * 核查Trigger在scheduler是否存在 * * @param trigger * @param scheduler * @return * @throws SchedulerException */ public static boolean checkTriggerExists(Trigger trigger, Scheduler scheduler) throws SchedulerException { return scheduler.checkExists(trigger.getKey()); }
Example 17
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 2 votes |
/** * 核查Job在scheduler是否存在 * @param jobDetail * @param scheduler * @throws SchedulerException */ public static void checkJobExists(JobDetail jobDetail, Scheduler scheduler) throws SchedulerException { scheduler.checkExists(jobDetail.getKey()); }