use of org.quartz.TriggerKey in project dubidubi by lzzzz4.
the class Quartz method removeJob.
public static void removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) {
try {
Scheduler sched = schedulerFactory.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
// 停止触发器
sched.pauseTrigger(triggerKey);
// 移除触发器
sched.unscheduleJob(triggerKey);
// 删除任务
sched.deleteJob(JobKey.jobKey(jobName, jobGroupName));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.quartz.TriggerKey in project ovirt-engine by oVirt.
the class FixedDelayJobListener method jobWasExecuted.
/**
* reschedule the job with a new trigger. The new trigger will fire within a
* fixed time from the method execution.
*
* @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext,
* JobExecutionException)
*/
@Override
public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
// Get the details of the job:
JobDetail jobdetail = context.getJobDetail();
JobDataMap data = jobdetail.getJobDataMap();
// job and if not just exit:
if (!data.containsKey(SchedulerUtilBaseImpl.FIXED_DELAY_VALUE)) {
return;
}
// This Job might already have an unused trigger in place, use it
List<? extends Trigger> triggersOfJob = null;
try {
triggersOfJob = context.getScheduler().getTriggersOfJob(context.getJobDetail().getKey());
} catch (SchedulerException e) {
// ignore
}
if (triggersOfJob != null && triggersOfJob.stream().filter(t -> t instanceof SimpleTrigger).anyMatch(t -> ((SimpleTrigger) t).getTimesTriggered() == 0)) {
logger.debug("Not scheduling {} again as there is still an unfired trigger.", context.getJobDetail().getKey());
return;
} else {
logger.debug("Rescheduling {} as there is no unfired trigger.", context.getJobDetail().getKey());
}
// generate the new trigger time
String configValueName = data.getString(SchedulerUtilBaseImpl.CONFIGURABLE_DELAY_KEY_NAME);
long delay;
if (StringUtils.isEmpty(configValueName)) {
delay = data.getLongValue(SchedulerUtilBaseImpl.FIXED_DELAY_VALUE);
} else {
ConfigValues configDelay = ConfigValues.valueOf(configValueName);
delay = Config.<Integer>getValue(configDelay).longValue();
}
TimeUnit delayUnit = (TimeUnit) data.getWrappedMap().get(SchedulerUtilBaseImpl.FIXED_DELAY_TIME_UNIT);
Date runTime = SchedulerUtilQuartzImpl.getFutureDate(delay, delayUnit);
// generate the new trigger
Trigger oldTrigger = context.getTrigger();
TriggerKey oldTriggerKey = oldTrigger.getKey();
Trigger newTrigger = newTrigger().withIdentity(oldTriggerKey).startAt(runTime).build();
// schedule the new trigger
sched.rescheduleAJob(oldTriggerKey.getName(), oldTriggerKey.getGroup(), newTrigger);
// SchedulerUtilQuartzImpl.getInstance().rescheduleAJob(oldTriggerName,
// oldTriggerGroup, newTrigger);
}
use of org.quartz.TriggerKey in project jbpm by kiegroup.
the class DeploymentsAwarePostgreSQLDelegate method selectTriggerToAcquire.
@Override
public List<TriggerKey> selectTriggerToAcquire(Connection conn, long noLaterThan, long noEarlierThan, int maxCount) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
List<TriggerKey> nextTriggers = new LinkedList<TriggerKey>();
try {
List<String> deploymentIds = quartzUtils.getDeployments();
ps = conn.prepareStatement(rtp(quartzUtils.nextTriggerQuery(deploymentIds)));
// Set max rows to retrieve
if (maxCount < 1)
// we want at least one trigger back.
maxCount = 1;
ps.setMaxRows(maxCount);
// Try to give jdbc driver a hint to hopefully not pull over more than the few rows we actually need.
// Note: in some jdbc drivers, such as MySQL, you must set maxRows before fetchSize, or you get exception!
ps.setFetchSize(maxCount);
ps.setString(1, STATE_WAITING);
ps.setBigDecimal(2, new BigDecimal(String.valueOf(noLaterThan)));
ps.setBigDecimal(3, new BigDecimal(String.valueOf(noEarlierThan)));
int index = 4;
for (String deployment : deploymentIds) {
ps.setString(index++, deployment);
}
rs = ps.executeQuery();
while (rs.next() && nextTriggers.size() <= maxCount) {
nextTriggers.add(triggerKey(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP)));
}
return nextTriggers;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class RedisCenterImpl method unDeployRedisSlowLogCollection.
@Override
public boolean unDeployRedisSlowLogCollection(long appId, String host, int port) {
Assert.isTrue(appId > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_SLOWLOG_TRIGGER_GROUP + appId);
Trigger trigger = schedulerCenter.getTrigger(triggerKey);
if (trigger == null) {
return true;
}
return schedulerCenter.unscheduleJob(triggerKey);
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class RedisCenterImpl method deployRedisCollection.
@Override
public boolean deployRedisCollection(long appId, String host, int port) {
Assert.isTrue(appId > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put(ConstUtils.HOST_KEY, host);
dataMap.put(ConstUtils.PORT_KEY, port);
dataMap.put(ConstUtils.APP_KEY, appId);
JobKey jobKey = JobKey.jobKey(ConstUtils.REDIS_JOB_NAME, ConstUtils.REDIS_JOB_GROUP);
TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_TRIGGER_GROUP + appId);
return schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getMinuteCronByAppId(appId), false);
}
Aggregations