Java Code Examples for org.quartz.Scheduler#deleteJob()
The following examples show how to use
org.quartz.Scheduler#deleteJob() .
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: 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 2
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 3
Source File: ScheduleUtils.java From ruoyiplus with MIT License | 5 votes |
/** * 删除定时任务 */ public static void deleteScheduleJob(Scheduler scheduler, Long jobId) { try { scheduler.deleteJob(getJobKey(jobId)); } catch (SchedulerException e) { log.error("deleteScheduleJob 异常:", e); } }
Example 4
Source File: ScheduleUtils.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 5 votes |
/** * 删除定时任务 */ public static void deleteScheduleJob(Scheduler scheduler, Long jobId) { try { scheduler.deleteJob(getJobKey(jobId)); } catch (SchedulerException e) { log.error("deleteScheduleJob 异常:", e); } }
Example 5
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 5 votes |
/** * 删除Job和下面所有Trigger * @param jobDetail * @param scheduler * @throws SchedulerException */ public static void removeJob(JobDetail jobDetail, Scheduler scheduler) throws SchedulerException { // 暂停 pauseJob(jobDetail, scheduler); // 移除 scheduler.deleteJob(jobDetail.getKey()); }
Example 6
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 7
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 8
Source File: QuartzManagerUtils.java From kafka-eagle with Apache License 2.0 | 5 votes |
/** Remove job. */ public static void removeJob(String jobName) { try { Scheduler sched = schedulerFactory.getScheduler(); TriggerKey triggerKey = TriggerKey.triggerKey("ke_trigger_name_" + new Date().getTime(), "ke_trigger_group_" + new Date().getTime()); sched.pauseTrigger(triggerKey); sched.unscheduleJob(triggerKey); sched.deleteJob(JobKey.jobKey(jobName, KE_JOB_GROUP_NAME)); } catch (Exception e) { throw new RuntimeException(e); } }
Example 9
Source File: SchedulerServiceSupplier.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
/** * Delete job. * * @param jobName the job name * @param jobGroupName the job group name * * @return the string */ public String deleteJob(String jobName, String jobGroupName) { StringBuffer servreponse = new StringBuffer(); try { Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); servreponse.append("<EXECUTION_OUTCOME "); scheduler.deleteJob(jobName, jobGroupName); servreponse.append("outcome=\"perform\"/>"); } catch (SchedulerException e) { SpagoBITracer.critical(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "deleteJob", "Error while deleting job", e); servreponse.append("outcome=\"fault\"/>"); } return servreponse.toString(); }
Example 10
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 11
Source File: TaskInstanceEntity.java From fixflow with Apache License 2.0 | 5 votes |
public TokenEntity removeTimeOutTask() { if (getNode().getBoundaryEventRefs().size() > 0) { TokenEntity tokenEntity = this.getToken(); String parentTokenId = tokenEntity.getParent().getId(); try { Scheduler scheduler = Context.getProcessEngineConfiguration().getSchedulerFactory().getScheduler(); Map<String, TokenEntity> tokenBrothers = tokenEntity.getParent().getChildren(); int colseTokenBrothersNum = 0; for (String tokenBrotherKey : tokenBrothers.keySet()) { if (!tokenBrotherKey.equals(tokenEntity.getId())) { scheduler.deleteJob(JobKey.jobKey(tokenBrothers.get(tokenBrotherKey).getId(), "FixTimeOutTask_" + parentTokenId)); tokenBrothers.get(tokenBrotherKey).end(); colseTokenBrothersNum = colseTokenBrothersNum + 1; break; } } if (colseTokenBrothersNum == (tokenBrothers.keySet().size() - 1)) { tokenEntity.getParent().terminationChildToken(); return tokenEntity.getParent(); } } catch (SchedulerException e) { e.printStackTrace(); throw new FixFlowException("流程在离开节点 " + this.getId() + " 的时候发生错误! 错误信息: " + e.toString(), e); } } return null; }
Example 12
Source File: FHTBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private void unscheduleJob(JobKey jobKey) { if (jobKey == null) { return; } try { Scheduler sched = StdSchedulerFactory.getDefaultScheduler(); sched.deleteJob(jobKey); } catch (SchedulerException e) { logger.error("Error while unscheduling time update job", e); } }
Example 13
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 14
Source File: QuartzUtils.java From quartz-web with Apache License 2.0 | 4 votes |
public static void removeJob(String jobName, String jobGroup, Scheduler scheduler) throws SchedulerException { // 暂停 pauseJob(jobName, jobGroup, scheduler); scheduler.deleteJob(getJobKey(jobName, jobGroup)); }
Example 15
Source File: JobTrigger.java From spring-cloud-shop with MIT License | 2 votes |
/** * 删除定时任务 * * @param scheduler scheduler * @param jobName jobName * @param jobGroup jobGroup */ public static void deleteJob(Scheduler scheduler, String jobName, String jobGroup) throws SchedulerException { log.info("删除定时任务 jobName = {}, jobGroup = {}", jobName, jobGroup); scheduler.deleteJob(getJobKey(jobName, jobGroup)); }
Example 16
Source File: ScheduleJobService.java From frameworkAggregate with Apache License 2.0 | 2 votes |
/** * 删除一个job * * @param scheduleJob * @throws SchedulerException */ public void deleteJob(ScheduleJob scheduleJob) throws SchedulerException { Scheduler scheduler = schedulerFactoryBean.getScheduler(); JobKey jobKey = JobKey.jobKey(scheduleJob.getJobName(), scheduleJob.getJobGroup()); scheduler.deleteJob(jobKey); }