use of org.quartz.Trigger.TriggerState in project jaffa-framework by jaffa-projects.
the class QuartzSchedulerHelper method jobAndTriggerToTask.
/**
* Molds the input Job and Trigger into a Task.
*/
private ScheduledTask jobAndTriggerToTask(final JobDetail jobDetail, final List<? extends Trigger> triggers) throws FrameworkException {
// Obtain the Task from the JobDataMap of the Job
ScheduledTask task = jobDataMapToTask(jobDetail.getJobDataMap());
// Obtain the Trigger Details
if (triggers != null && 0 < triggers.size()) {
final Trigger trigger = triggers.get(0);
task.setNextDue(trigger.getNextFireTime() != null ? new DateTime(trigger.getNextFireTime()) : null);
task.setLastRunOn(trigger.getPreviousFireTime() != null ? new DateTime(trigger.getPreviousFireTime()) : null);
}
// Determine the Status
ScheduledTask.TaskStatusEnumeration status;
try {
final TriggerState triggerState = scheduler.getTriggerState(TriggerKey.triggerKey(task.getScheduledTaskId(), JOB_GROUP));
switch(triggerState) {
case BLOCKED:
status = ScheduledTask.TaskStatusEnumeration.BLOCKED;
break;
case COMPLETE:
status = ScheduledTask.TaskStatusEnumeration.COMPLETE;
break;
case ERROR:
status = ScheduledTask.TaskStatusEnumeration.ERROR;
break;
case NORMAL:
status = ScheduledTask.TaskStatusEnumeration.NORMAL;
break;
case PAUSED:
status = ScheduledTask.TaskStatusEnumeration.PAUSED;
break;
default:
status = ScheduledTask.TaskStatusEnumeration.UNKNOWN;
break;
}
} catch (SchedulerException e) {
LOGGER.error("Error in determing the trigger state. Will assume UNKNOWN status for " + task.getScheduledTaskId(), e);
status = ScheduledTask.TaskStatusEnumeration.UNKNOWN;
}
task.setStatus(status);
return task;
}
use of org.quartz.Trigger.TriggerState in project xxl-job by xuxueli.
the class XxlJobDynamicScheduler method fillJobInfo.
// ---------------------- schedule util ----------------------
/**
* fill job info
*
* @param jobInfo
*/
public static void fillJobInfo(XxlJobInfo jobInfo) {
// TriggerKey : name + group
String group = String.valueOf(jobInfo.getJobGroup());
String name = String.valueOf(jobInfo.getId());
TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
try {
Trigger trigger = scheduler.getTrigger(triggerKey);
TriggerState triggerState = scheduler.getTriggerState(triggerKey);
// parse params
if (trigger != null && trigger instanceof CronTriggerImpl) {
String cronExpression = ((CronTriggerImpl) trigger).getCronExpression();
jobInfo.setJobCron(cronExpression);
}
if (triggerState != null) {
jobInfo.setJobStatus(triggerState.name());
}
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
}
use of org.quartz.Trigger.TriggerState in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManager method getTask.
/**
* Returns task by given key
*
* @param jobKey
* @return task dto
*/
@SuppressWarnings("unchecked")
private Task getTask(JobKey jobKey) {
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
// job does not exists
return null;
}
Task task = new Task();
// task setting
task.setId(jobKey.getName());
// app context is needed here
SchedulableTaskExecutor<?> taskExecutor = (SchedulableTaskExecutor<?>) context.getAutowireCapableBeanFactory().createBean(jobDetail.getJobClass());
task.setTaskType((Class<? extends SchedulableTaskExecutor<?>>) AutowireHelper.getTargetClass(taskExecutor));
task.setDescription(jobDetail.getDescription());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
task.setInstanceId(jobDataMap.getString(SchedulableTaskExecutor.PARAMETER_INSTANCE_ID));
task.setModified((ZonedDateTime) jobDataMap.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
task.setTriggers(new ArrayList<>());
// task properties
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
task.getParameters().put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString());
}
task.setDisabled(taskExecutor.isDisabled());
if (!task.isDisabled()) {
task.setSupportsDryRun(taskExecutor.supportsDryRun());
task.setFormDefinition(taskExecutor.getFormDefinition());
task.setRecoverable(taskExecutor.isRecoverable());
} else {
LOG.warn("Task [{}] is disabled and cannot be executed, remove schedule for this task to hide this warning.", task.getTaskType().getSimpleName());
}
// scheduled triggers - native
for (Trigger trigger : scheduler.getTriggersOfJob(jobKey)) {
TriggerState state = scheduler.getTriggerState(trigger.getKey());
if (trigger instanceof CronTrigger) {
task.getTriggers().add(new CronTaskTrigger(task.getId(), (CronTrigger) trigger, TaskTriggerState.convert(state)));
} else if (trigger instanceof SimpleTrigger) {
task.getTriggers().add(new SimpleTaskTrigger(task.getId(), (SimpleTrigger) trigger, TaskTriggerState.convert(state)));
} else {
LOG.warn("Job '{}' ({}) has registered trigger of unsupported type {}", jobKey, jobDetail.getJobClass(), trigger);
}
}
// dependent tasks
dependentTaskTriggerRepository.findByDependentTaskId(jobKey.getName()).forEach(dependentTask -> {
task.getTriggers().add(new DependentTaskTrigger(task.getId(), dependentTask.getId(), dependentTask.getInitiatorTaskId()));
});
return task;
} catch (org.quartz.SchedulerException ex) {
if (ex.getCause() instanceof ClassNotFoundException) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
return null;
}
throw new CoreException(ex);
} catch (BeansException | IllegalArgumentException ex) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
return null;
}
}
Aggregations