use of org.quartz.TriggerKey in project PublicCMS-preview by sanluan.
the class ScheduledTask method create.
/**
* 创建任务计划
*
* @param site
* @param id
* @param cronExpression
*/
public void create(SysSite site, Integer id, String cronExpression) {
if (CommonUtils.notEmpty(id) && CommonUtils.notEmpty(cronExpression)) {
Date startTime = CommonUtils.getDate();
String taskName = getTaskName(id);
TriggerKey triggerKey = TriggerKey.triggerKey(taskName);
try {
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(site.getId() % 60 + BLANK_SPACE + cronExpression);
if (null == trigger) {
JobDetail jobDetail = JobBuilder.newJob(ScheduledJob.class).withIdentity(taskName).build();
jobDetail.getJobDataMap().put(ID, id);
trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).startNow().build();
scheduler.scheduleJob(jobDetail, trigger);
} else {
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).startNow().build();
scheduler.rescheduleJob(triggerKey, trigger);
}
} catch (SchedulerException e) {
sysTaskService.updateStatus(id, TASK_STATUS_ERROR);
logTaskService.save(new LogTask(site.getId(), id, startTime, CommonUtils.getDate(), false, e.getMessage()));
}
}
}
use of org.quartz.TriggerKey in project jeesuite-libs by vakinge.
the class AbstractJob method init.
public void init() {
triggerName = jobName + "Trigger";
triggerKey = new TriggerKey(triggerName, group);
JobConfig jobConfg = new JobConfig(group, jobName, cronExpr);
// 从持久化配置合并
if (JobContext.getContext().getConfigPersistHandler() != null) {
JobContext.getContext().getConfigPersistHandler().merge(jobConfg);
}
JobContext.getContext().getRegistry().register(jobConfg);
logger.info("Initialized Job_{} OK!!", jobName);
}
use of org.quartz.TriggerKey in project cdap by caskdata.
the class TimeScheduler method resumeProgramSchedule.
public void resumeProgramSchedule(ProgramSchedule schedule) throws NotFoundException, SchedulerException {
try {
Collection<TriggerKey> triggerKeys = getGroupedTriggerKeys(schedule);
// Must assert all trigger keys exist before processing each trigger key
assertTriggerKeysExist(triggerKeys);
for (TriggerKey triggerKey : triggerKeys) {
if (triggerKey.getGroup().equals(PAUSED_NEW_TRIGGERS_GROUP)) {
Trigger neverScheduledTrigger = scheduler.getTrigger(triggerKey);
TriggerBuilder<? extends Trigger> triggerBuilder = neverScheduledTrigger.getTriggerBuilder();
// move this key from TimeScheduler#PAUSED_NEW_TRIGGERS_GROUP to the Key#DEFAULT_GROUP group
// (when no group name is provided default is used)
Trigger resumedTrigger = triggerBuilder.withIdentity(triggerKey.getName()).build();
scheduler.rescheduleJob(neverScheduledTrigger.getKey(), resumedTrigger);
triggerKey = resumedTrigger.getKey();
}
scheduler.resumeTrigger(triggerKey);
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(e);
}
}
use of org.quartz.TriggerKey in project cdap by caskdata.
the class TimeScheduler method suspendProgramSchedule.
public void suspendProgramSchedule(ProgramSchedule schedule) throws NotFoundException, SchedulerException {
try {
Collection<TriggerKey> triggerKeys = getGroupedTriggerKeys(schedule);
// Must assert all trigger keys exist before processing each trigger key
assertTriggerKeysExist(triggerKeys);
for (TriggerKey triggerKey : triggerKeys) {
scheduler.pauseTrigger(triggerKey);
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(e);
}
}
use of org.quartz.TriggerKey in project cdap by caskdata.
the class LogPrintingJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
LOG.info("Received Trigger at {}", context.getScheduledFireTime().toString());
JobDataMap triggerMap = context.getTrigger().getJobDataMap();
JobDataMap map = context.getMergedJobDataMap();
String[] keys = map.getKeys();
TriggerKey triggerKey = context.getTrigger().getKey();
if (triggerKey.getName().equalsIgnoreCase("g2")) {
Preconditions.checkArgument(triggerMap.getString(KEY).equals(VALUE));
} else {
Preconditions.checkArgument(!triggerMap.containsKey(KEY));
}
Preconditions.checkArgument(keys != null);
Preconditions.checkArgument(keys.length > 0);
LOG.info("Number of parameters {}", keys.length);
for (String key : keys) {
LOG.info("Parameter key: {}, value: {}", key, map.get(key));
}
} catch (Throwable e) {
throw Throwables.propagate(e);
}
throw new JobExecutionException("exception");
}
Aggregations