use of org.quartz.CronTrigger 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.CronTrigger in project OpenOLAT by OpenOLAT.
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.CronTrigger in project archiva by apache.
the class DefaultRepositoryArchivaTaskScheduler method scheduleRepositoryJobs.
private synchronized void scheduleRepositoryJobs(ManagedRepositoryConfiguration repoConfig) throws SchedulerException {
if (repoConfig.getRefreshCronExpression() == null) {
log.warn("Skipping job, no cron expression for {}", repoConfig.getId());
return;
}
if (!repoConfig.isScanned()) {
log.warn("Skipping job, repository scannable has been disabled for {}", repoConfig.getId());
return;
}
// get the cron string for these database scanning jobs
String cronString = repoConfig.getRefreshCronExpression();
if (!cronValidator.validate(cronString)) {
log.warn("Cron expression [{}] for repository [{}] is invalid. Defaulting to hourly.", cronString, repoConfig.getId());
cronString = CRON_HOURLY;
}
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(TASK_QUEUE, repositoryScanningQueue);
jobDataMap.put(TASK_REPOSITORY, repoConfig.getId());
// setup the unprocessed artifact job
JobDetail repositoryJob = JobBuilder.newJob(RepositoryTaskJob.class).withIdentity(REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP).setJobData(jobDataMap).build();
try {
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP).withSchedule(CronScheduleBuilder.cronSchedule(cronString)).build();
jobs.add(REPOSITORY_JOB + ":" + repoConfig.getId());
scheduler.scheduleJob(repositoryJob, trigger);
} catch (RuntimeException e) {
log.error("ParseException in repository scanning cron expression, disabling repository scanning for '{}': {}", repoConfig.getId(), e.getMessage());
}
}
use of org.quartz.CronTrigger in project jforum2 by rafaelsteil.
the class SummaryScheduler method startJob.
/**
* Starts the summary Job. Conditions to start: Is not started yet and is enabled on the file
* SystemGlobasl.properties. The to enable it is "summary.enabled"
* (ConfigKeys.SUMMARY_IS_ENABLED).
*
* @throws SchedulerException
* @throws IOException
*/
public static void startJob() throws SchedulerException {
boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.SUMMARY_IS_ENABLED);
if (!isStarted && isEnabled) {
String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
String cronExpression = SystemGlobals.getValue("org.quartz.context.summary.cron.expression");
scheduler = new StdSchedulerFactory(filename).getScheduler();
Trigger trigger = null;
try {
trigger = new CronTrigger(SummaryJob.class.getName(), "summaryJob", cronExpression);
logger.info("Starting quartz summary expression " + cronExpression);
scheduler.scheduleJob(new JobDetail(SummaryJob.class.getName(), "summaryJob", SummaryJob.class), trigger);
scheduler.start();
} catch (ParseException e) {
e.printStackTrace();
}
}
isStarted = true;
}
use of org.quartz.CronTrigger in project opencast by opencast.
the class AbstractScanner method schedule.
/**
* Schedule the scanning job to execute according to the cron schedule.
*/
public void schedule() {
if (!isEnabled()) {
logger.info(getScannerName() + " is disabled");
return;
}
if (quartz == null) {
logger.warn("No quartz scheduler available to schedule scanner.");
return;
}
logger.info("Schedule " + getScannerName() + " as a cron job ({})", getCronExpression());
try {
final CronTrigger trigger = new CronTrigger();
trigger.setCronExpression(getCronExpression());
trigger.setName(getTriggerName());
trigger.setGroup(getTriggerGroupName());
trigger.setJobName(getJobName());
trigger.setJobGroup(getJobGroup());
if (getQuartz().getTriggersOfJob(getJobName(), getJobGroup()).length == 0) {
getQuartz().scheduleJob(trigger);
} else {
getQuartz().rescheduleJob(getTriggerName(), getTriggerGroupName(), trigger);
}
} catch (ParseException e) {
logger.error("Error scheduling " + getScannerName() + ", the cron expression '{}' could not be parsed: {}", getCronExpression(), e.getMessage());
} catch (Exception e) {
logger.error("Error scheduling " + getScannerName(), e);
}
}
Aggregations