Java Code Examples for org.quartz.TriggerBuilder#startAt()
The following examples show how to use
org.quartz.TriggerBuilder#startAt() .
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: AbstractQuartzTaskManager.java From micro-integrator with Apache License 2.0 | 6 votes |
private Trigger getTriggerFromInfo(String taskName, String taskGroup, TaskInfo.TriggerInfo triggerInfo) throws TaskException { TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().withIdentity(taskName, taskGroup); if (triggerInfo.getStartTime() == null) { triggerBuilder = triggerBuilder.startNow(); } else { triggerBuilder = triggerBuilder.startAt(triggerInfo.getStartTime()); } if (triggerInfo.getEndTime() != null) { triggerBuilder.endAt(triggerInfo.getEndTime()); } Trigger trigger; if (triggerInfo.getCronExpression() != null) { trigger = triggerBuilder.withSchedule(this.getCronScheduleBuilder(triggerInfo)).build(); } else { if (triggerInfo.getRepeatCount() == 0) { /* only once executed */ trigger = triggerBuilder.build(); } else { trigger = triggerBuilder.withSchedule(this.getSimpleScheduleBuilder(triggerInfo)).build(); } } return trigger; }
Example 2
Source File: QuartzUtil.java From FoxBPM with Apache License 2.0 | 6 votes |
/** * 创建复杂触发器 * * @param jobName * 作业名 * @param groupName * 组名 * @param cronExpression * cron表达式 * @param startTime * 开始时间 * @param endTime * 结束时间 * @return */ public final static Trigger createCronTrigger(ListenerExecutionContext executionContext, String cronExpression, Date startTime, Date endTime) { TriggerBuilder<CronTrigger> triggerBuilder = newTrigger().withIdentity(GuidUtil.CreateGuid(), executionContext.getProcessInstanceId()).withSchedule(cronSchedule(cronExpression)); if (startTime != null) { triggerBuilder.startAt(startTime); } if (endTime != null) { triggerBuilder.endAt(endTime); } CronTrigger trigger = triggerBuilder.build(); return trigger; }
Example 3
Source File: QuartzUtil.java From fixflow with Apache License 2.0 | 6 votes |
/** * 创建复杂触发器 * @param jobName 作业名 * @param groupName 组名 * @param cronExpression cron表达式 * @param startTime 开始时间 * @param endTime 结束时间 * @return */ public static Trigger createCronTrigger(ExecutionContext executionContext, String cronExpression,Date startTime,Date endTime) { TriggerBuilder<CronTrigger> triggerBuilder=newTrigger() .withIdentity(GuidUtil.CreateGuid(), executionContext.getProcessDefinition().getId()) .withSchedule(cronSchedule(cronExpression)); if(startTime!=null){ triggerBuilder.startAt(startTime); } if(endTime!=null){ triggerBuilder.endAt(endTime); } CronTrigger trigger = triggerBuilder .build(); return trigger; }
Example 4
Source File: ScheduledJob.java From SensorWebClient with GNU General Public License v2.0 | 5 votes |
public Trigger createTrigger(JobKey jobKey) { TriggerBuilder tb = newTrigger() .forJob(jobKey) .withIdentity(getTriggerName()); if (getCronExpression() != null) { tb.withSchedule(cronSchedule(getCronExpression())); } if (isTriggerAtStartup()) { tb.startAt(futureDate(5, DateBuilder.IntervalUnit.SECOND)); } return tb.build(); }
Example 5
Source File: TriggerServiceStrategy.java From quartz-web with Apache License 2.0 | 4 votes |
public JSONResult addTrigger(String schedulerName, String jobName, String jobGroup, String triggerName, String triggerGroup, String cronExpression, String description, String priority, Date startDate, Date endDate, Map<String, Object> dataMap) { try { Assert.notEmpty(schedulerName, "schedulerName can not be empty"); Assert.notEmpty(jobName, "jobName can not be empty"); Assert.notEmpty(jobGroup, "jobGroup can not be empty"); Assert.notEmpty(triggerName, "triggerName can not be empty"); Assert.notEmpty(triggerGroup, "triggerGroup can not be empty"); Assert.isCronExpression(cronExpression, "cronExpression is error"); TriggerBuilder<Trigger> triggerTriggerBuilder = TriggerBuilder.newTrigger(); triggerTriggerBuilder = triggerTriggerBuilder.withIdentity(triggerName, triggerGroup); if (!StringUtils.isEmpty(description)) { triggerTriggerBuilder = triggerTriggerBuilder.withDescription(description); } if (!StringUtils.isEmpty(priority) && StringUtils.isInteger(priority)) { Assert.isInteger(priority, "priority must be int"); triggerTriggerBuilder.withPriority(Integer.parseInt(priority)); } if (startDate != null) { triggerTriggerBuilder.startAt(startDate); } if (endDate != null) { triggerTriggerBuilder.endAt(endDate); } //jobDataMap if (dataMap != null && dataMap.size() > 0) { JobDataMap jobDataMap = new JobDataMap(); for (Map.Entry<String, Object> dataKey : dataMap.entrySet()) { if (!StringUtils.isEmpty(dataKey.getKey())) { jobDataMap.put(dataKey.getKey(), dataKey.getValue()); } } triggerTriggerBuilder.usingJobData(jobDataMap); } triggerTriggerBuilder.forJob(jobName, jobGroup); CronTrigger trigger = triggerTriggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) .build(); //JobDetail jobDetail = QuartzWebManager.getJob(schedulerName, jobName, jobGroup); // 存在更新不存在,添加 if (!QuartzWebManager.checkTriggerExists(schedulerName, triggerName, triggerGroup)) { QuartzWebManager.addTriggerForJob(schedulerName, trigger); } else { QuartzWebManager.updateTriggerForJob(schedulerName, trigger); } return JSONResult.build(JSONResult.RESULT_CODE_SUCCESS, "ok"); } catch (Exception e) { e.printStackTrace(); return JSONResult.build(JSONResult.RESULT_CODE_ERROR, e.getMessage()); } }
Example 6
Source File: JobManagerImpl.java From syncope with Apache License 2.0 | 4 votes |
private void registerJob( final String jobName, final Job jobInstance, final String cronExpression, final Date startAt, final Map<String, Object> jobMap) throws SchedulerException { if (isRunning(new JobKey(jobName, Scheduler.DEFAULT_GROUP))) { LOG.debug("Job {} already running, cancel", jobName); return; } // 0. unregister job unregisterJob(jobName); // 1. Job bean ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance); // 2. JobDetail bean JobBuilder jobDetailBuilder = JobBuilder.newJob(jobInstance.getClass()). withIdentity(jobName). usingJobData(new JobDataMap(jobMap)); // 3. Trigger if (cronExpression == null && startAt == null) { // Jobs added with no trigger must be durable scheduler.getScheduler().addJob(jobDetailBuilder.storeDurably().build(), true); } else { TriggerBuilder<?> triggerBuilder; if (cronExpression == null) { triggerBuilder = TriggerBuilder.newTrigger(). withIdentity(JobNamer.getTriggerName(jobName)). startAt(startAt); } else { triggerBuilder = TriggerBuilder.newTrigger(). withIdentity(JobNamer.getTriggerName(jobName)). withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)); if (startAt == null) { triggerBuilder = triggerBuilder.startNow(); } else { triggerBuilder = triggerBuilder.startAt(startAt); } } scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build()); } }