use of org.quartz.SchedulerException in project ddf by codice.
the class WorkspaceQueryServiceImpl method setCronString.
/**
* @param cronString cron string (must be non-null)
*/
@SuppressWarnings("unused")
public void setCronString(String cronString) {
notNull(cronString, "cronString must be non-null");
notNull(scheduler, "scheduler must be non-null");
notNull(jobDetail, "jobDetail must be non-null");
try {
scheduler.deleteJob(jobDetail.getKey());
LOGGER.debug("Scheduling job {}", jobDetail);
CronTrigger trigger = newTrigger().withIdentity(TRIGGER_NAME).startNow().withSchedule(cronSchedule(cronString)).build();
scheduler.scheduleJob(jobDetail, trigger);
LOGGER.debug("Setting cron string : {}", cronString);
} catch (SchedulerException e) {
LOGGER.warn("Unable to update scheduler with cron string: cron=[{}]", cronString, e);
}
}
use of org.quartz.SchedulerException in project ddf by codice.
the class ScheduledCommandTaskTest method testNewTaskScheduleException.
@Test
public void testNewTaskScheduleException() throws Exception {
when(scheduler.scheduleJob(any(JobDetail.class), any(Trigger.class))).thenThrow(new SchedulerException());
scheduledCommandTask.newTask();
}
use of org.quartz.SchedulerException in project ddf by codice.
the class ScheduledCommandTask method newTask.
@Override
public void newTask() {
LOGGER.trace("Creating new Task.");
long identifier = System.currentTimeMillis();
this.jobKey = new JobKey("job" + identifier, jobClass.getSimpleName());
this.triggerKey = new TriggerKey("trigger" + identifier, jobClass.getSimpleName());
JobDetail jobDetail = createJob();
Trigger trigger = createTrigger();
if (trigger == null) {
return;
}
try {
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
LOGGER.info("Error with scheduling of task.", e);
}
}
use of org.quartz.SchedulerException in project midpoint by Evolveum.
the class TaskManagerQuartzImpl method onTaskDelete.
@Override
public void onTaskDelete(String oid, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(DOT_INTERFACE + "onTaskDelete");
result.addParam("oid", oid);
LOGGER.trace("onTaskDelete called for oid = " + oid);
JobKey jobKey = TaskQuartzImplUtil.createJobKeyForTaskOid(oid);
try {
if (executionManager.getQuartzScheduler().checkExists(jobKey)) {
// removes triggers as well
executionManager.getQuartzScheduler().deleteJob(jobKey);
}
} catch (SchedulerException e) {
String message = "Quartz shadow job cannot be removed; oid = " + oid;
LoggingUtils.logUnexpectedException(LOGGER, message, e);
result.recordFatalError(message);
}
result.recordSuccessIfUnknown();
}
use of org.quartz.SchedulerException in project midpoint by Evolveum.
the class TaskSynchronizer method synchronizeTask.
/**
* Task should be refreshed when entering this method.
*
* @return true if task info in Quartz was updated
*/
public boolean synchronizeTask(TaskQuartzImpl task, OperationResult parentResult) {
if (!task.isPersistent()) {
// transient tasks are not scheduled via Quartz!
return false;
}
boolean changed = false;
String message = "";
OperationResult result = parentResult.createSubresult(TaskSynchronizer.class.getName() + ".synchronizeTask");
result.addArbitraryObjectAsParam("task", task);
try {
LOGGER.trace("Synchronizing task {}; isRecreateQuartzTrigger = {}", task, task.isRecreateQuartzTrigger());
Scheduler scheduler = taskManager.getExecutionManager().getQuartzScheduler();
String oid = task.getOid();
JobKey jobKey = TaskQuartzImplUtil.createJobKeyForTask(task);
TriggerKey standardTriggerKey = TaskQuartzImplUtil.createTriggerKeyForTask(task);
boolean waitingOrClosedOrSuspended = task.getExecutionStatus() == TaskExecutionStatus.WAITING || task.getExecutionStatus() == TaskExecutionStatus.CLOSED || task.getExecutionStatus() == TaskExecutionStatus.SUSPENDED;
if (!scheduler.checkExists(jobKey) && !waitingOrClosedOrSuspended) {
String m1 = "Quartz job does not exist for a task, adding it. Task = " + task;
message += "[" + m1 + "] ";
LOGGER.trace(" - " + m1);
scheduler.addJob(TaskQuartzImplUtil.createJobDetailForTask(task), false);
changed = true;
}
// WAITING and CLOSED tasks should have no triggers; SUSPENDED tasks should have no extra triggers
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
boolean standardTriggerExists = triggers.stream().anyMatch(t -> t.getKey().equals(standardTriggerKey));
if (waitingOrClosedOrSuspended) {
for (Trigger trigger : triggers) {
if (task.getExecutionStatus() != TaskExecutionStatus.SUSPENDED || !trigger.getKey().equals(standardTriggerKey)) {
String m1 = "Removing Quartz trigger " + trigger.getKey() + " for WAITING/CLOSED/SUSPENDED task " + task;
message += "[" + m1 + "] ";
LOGGER.trace(" - " + m1);
scheduler.unscheduleJob(trigger.getKey());
changed = true;
} else {
// For SUSPENDED tasks, we keep the standard trigger untouched. We want to preserve original
// scheduled time. (This might or might not be what the user wants ... but it has been so for so
// many years, so let's not change it now.)
//
// It's harmless to keep the standard trigger, because:
// 1) If a trigger is mistakenly alive, JobExecutor will take care of it.
// 2) If a trigger has wrong parameters, this will be corrected on task resume.
}
}
} else if (task.getExecutionStatus() == TaskExecutionStatus.RUNNABLE) {
Trigger triggerToBe;
try {
triggerToBe = TaskQuartzImplUtil.createTriggerForTask(task);
} catch (ParseException e) {
String message2 = "Cannot create a trigger for a task " + this + " because of a cron expression parsing exception";
LoggingUtils.logUnexpectedException(LOGGER, message2, e);
result.recordFatalError(message2, e);
// TODO: implement error handling correctly
throw new SystemException("Cannot a trigger for a task because of a cron expression parsing exception", e);
}
if (triggerToBe == null) {
if (standardTriggerExists) {
// TODO what about non-standard triggers?
// These may be legal here (e.g. for a manually-run recurring task waiting to get a chance to run)
String m1 = "Removing standard Quartz trigger for RUNNABLE task that should not have it; task = " + task;
message += "[" + m1 + "] ";
LOGGER.trace(" - " + m1);
scheduler.unscheduleJob(TriggerKey.triggerKey(oid));
changed = true;
}
} else {
// if the trigger should exist and it does not...
if (!standardTriggerExists) {
String m1 = "Creating standard trigger for a RUNNABLE task " + task;
LOGGER.trace(" - " + m1);
message += "[" + m1 + "] ";
scheduler.scheduleJob(triggerToBe);
changed = true;
} else {
// we have to compare trigger parameters with the task's ones
Trigger triggerAsIs = scheduler.getTrigger(standardTriggerKey);
if (task.isRecreateQuartzTrigger() || TaskQuartzImplUtil.triggerDataMapsDiffer(triggerAsIs, triggerToBe)) {
String m1 = "Existing trigger has incompatible parameters or was explicitly requested to be recreated; recreating it. Task = " + task;
LOGGER.trace(" - " + m1);
message += "[" + m1 + "] ";
scheduler.rescheduleJob(standardTriggerKey, triggerToBe);
changed = true;
} else {
String m1 = "Existing trigger is OK, leaving it as is; task = " + task;
LOGGER.trace(" - " + m1);
message += "[" + m1 + "] ";
Trigger.TriggerState state = scheduler.getTriggerState(standardTriggerKey);
if (state == Trigger.TriggerState.PAUSED) {
String m2 = "However, the trigger is paused, resuming it; task = " + task;
LOGGER.trace(" - " + m2);
message += "[" + m2 + "] ";
scheduler.resumeTrigger(standardTriggerKey);
changed = true;
}
}
}
}
}
} catch (Exception e) {
// todo make this more specific (originally here was SchedulerException but e.g. for negative repeat intervals here we get unchecked IllegalArgumentException...)
String message2 = "Cannot synchronize repository/Quartz Job Store information for task " + task;
LoggingUtils.logUnexpectedException(LOGGER, message2, e);
result.recordFatalError(message2, e);
}
if (result.isUnknown()) {
result.computeStatus();
result.recordStatus(result.getStatus(), message);
}
return changed;
}
Aggregations