use of org.quartz.TriggerKey in project jbpm by kiegroup.
the class DeploymentsAwareStdJDBCDelegate 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 jbpm by kiegroup.
the class DeploymentsAwareStdJDBCDelegate method selectMisfiredTriggersInState.
@Override
public List<TriggerKey> selectMisfiredTriggersInState(Connection conn, String state, long ts) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
List<String> deploymentIds = quartzUtils.getDeployments();
ps = conn.prepareStatement(rtp(quartzUtils.misfiredTriggersQuery(deploymentIds)));
ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
ps.setString(2, state);
int index = 3;
for (String deployment : deploymentIds) {
ps.setString(index++, deployment);
}
rs = ps.executeQuery();
LinkedList<TriggerKey> list = new LinkedList<TriggerKey>();
while (rs.next()) {
String triggerName = rs.getString(COL_TRIGGER_NAME);
String groupName = rs.getString(COL_TRIGGER_GROUP);
list.add(triggerKey(triggerName, groupName));
}
return list;
} finally {
closeResultSet(rs);
closeStatement(ps);
}
}
use of org.quartz.TriggerKey in project openolat by klemens.
the class StatisticsAdminController method refreshUIState.
private void refreshUIState() {
log_.info("refreshUIState: schedulerFactoryBean found");
boolean enabled = false;
String cronExpression = "";
Trigger.TriggerState triggerState;
try {
TriggerKey triggerKey = new TriggerKey("updateStatisticsTrigger", null);
triggerState = scheduler.getTriggerState(triggerKey);
enabled = triggerState != Trigger.TriggerState.NONE && triggerState != Trigger.TriggerState.ERROR;
Trigger trigger = scheduler.getTrigger(triggerKey);
if (trigger == null) {
enabled &= false;
} else {
enabled &= trigger.getJobKey().getName().equals("org.olat.statistics.job.enabled");
if (trigger instanceof CronTrigger) {
log_.info("refreshUIState: org.olat.statistics.job.enabled check, enabled now: " + enabled);
cronExpression = ((CronTrigger) trigger).getCronExpression();
}
}
log_.info("refreshUIState: updateStatisticsTrigger state was " + triggerState + ", enabled now: " + enabled);
} catch (SchedulerException e) {
log_.warn("refreshUIState: Got a SchedulerException while asking for the updateStatisticsTrigger's state", e);
}
StatisticUpdateManager statisticUpdateManager = getStatisticUpdateManager();
if (statisticUpdateManager == null) {
log_.info("refreshUIState: statisticUpdateManager not configured");
enabled = false;
} else {
enabled &= statisticUpdateManager.isEnabled();
log_.info("refreshUIState: statisticUpdateManager configured, enabled now: " + enabled);
}
if (enabled) {
content.contextPut("status", getTranslator().translate("statistics.status.enabled", new String[] { cronExpression }));
} else {
content.contextPut("status", getTranslator().translate("statistics.status.disabled"));
}
content.contextPut("statisticEnabled", enabled);
recalcLastUpdated();
updateStatisticUpdateOngoingFlag();
}
use of org.quartz.TriggerKey in project ovirt-engine by oVirt.
the class SchedulerUtilBaseImpl method triggerJob.
@Override
public void triggerJob(String jobId) {
try {
List<? extends Trigger> existingTriggers = sched.getTriggersOfJob(jobKey(jobId, Scheduler.DEFAULT_GROUP));
if (!existingTriggers.isEmpty()) {
// Note: we assume that every job has exactly one trigger
Trigger oldTrigger = existingTriggers.get(0);
TriggerKey oldTriggerKey = oldTrigger.getKey();
Trigger newTrigger = newTrigger().withIdentity(oldTriggerKey).startAt(getFutureDate(0, TimeUnit.MILLISECONDS)).build();
rescheduleAJob(oldTriggerKey.getName(), oldTriggerKey.getGroup(), newTrigger);
} else {
log.error("failed to trigger a job with id={}, job has no trigger", jobId);
}
} catch (SchedulerException se) {
log.error("failed to trigger a job with id={}: {}", jobId, se.getMessage());
log.debug("Exception", se);
}
}
use of org.quartz.TriggerKey in project cdap by caskdata.
the class DatasetBasedTimeScheduleStore method readSchedulesFromPersistentStore.
// Get schedule information from persistent store
private void readSchedulesFromPersistentStore() throws Exception {
final List<JobDetail> jobs = Lists.newArrayList();
final List<TriggerStatusV2> triggers = Lists.newArrayList();
factory.createExecutor(ImmutableList.of((TransactionAware) table)).execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
Row result = table.get(JOB_KEY);
if (!result.isEmpty()) {
for (byte[] bytes : result.getColumns().values()) {
JobDetail jobDetail = (JobDetail) SerializationUtils.deserialize(bytes);
// If the job detail doesn't contain version id, add one.
jobDetail = addDefaultAppVersionIfNeeded(jobDetail);
LOG.debug("Schedule: Job with key {} found", jobDetail.getKey());
jobs.add(jobDetail);
}
} else {
LOG.debug("Schedule: No Jobs found in Job store");
}
result = table.get(TRIGGER_KEY);
if (!result.isEmpty()) {
for (byte[] bytes : result.getColumns().values()) {
TriggerStatusV2 trigger = (TriggerStatusV2) SerializationUtils.deserialize(bytes);
addDefaultAppVersionIfNeeded(trigger);
if (trigger.state.equals(Trigger.TriggerState.NORMAL) || trigger.state.equals(Trigger.TriggerState.PAUSED)) {
triggers.add(trigger);
LOG.debug("Schedule: trigger with key {} added", trigger.trigger.getKey());
} else {
LOG.debug("Schedule: trigger with key {} and state {} skipped", trigger.trigger.getKey(), trigger.state);
}
}
} else {
LOG.debug("Schedule: No triggers found in job store");
}
}
});
Set<JobKey> jobKeys = new HashSet<>();
for (JobDetail job : jobs) {
super.storeJob(job, true);
jobKeys.add(job.getKey());
}
Set<TriggerKey> triggersWithNoJob = new HashSet<>();
for (TriggerStatusV2 trigger : triggers) {
if (!jobKeys.contains(trigger.trigger.getJobKey())) {
triggersWithNoJob.add(trigger.trigger.getKey());
continue;
}
super.storeTrigger(trigger.trigger, true);
// because the scheduler is actually not started at this point.
if (trigger.state == Trigger.TriggerState.PAUSED) {
super.pauseTrigger(trigger.trigger.getKey());
}
}
for (TriggerKey key : triggersWithNoJob) {
LOG.error(String.format("No Job was found for the Trigger key '%s'." + " Deleting the trigger entry from the store.", key));
executeDelete(key);
}
}
Aggregations