use of org.quartz.CronExpression in project JSpiderCluster by xiyuan-fengyu.
the class OnTimeTask method updateCron.
public boolean updateCron(String newCron) {
if (CronExpression.isValidExpression(newCron)) {
try {
cron = new CronExpression(newCron);
cronStr = newCron;
beforeExcute();
return true;
} catch (Exception e) {
return false;
}
} else {
return false;
}
}
use of org.quartz.CronExpression in project plugin-vm by ligoj.
the class VmResource method writeSchedules.
/**
* Write all schedules.
*/
private void writeSchedules(final OutputStream output, Collection<VmSchedule> schedules, final Map<Integer, VmExecution> lastExecutions) throws IOException {
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252"));
final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss");
final Date now = DateUtils.newCalendar().getTime();
writer.write("subscription;project;projectKey;projectName;node;cron;operation;lastDateHMS;lastTimestamp;lastOperation;vm;lastTrigger;lastSucceed;lastStatusText;lastErrorText;nextDateHMS;nextTimestamp");
for (final VmSchedule schedule : schedules) {
// The last execution of the related schedule
final VmExecution execution = lastExecutions.get(schedule.getSubscription().getId());
writeCommon(writer, schedule.getSubscription());
writer.write(';');
writer.write(schedule.getCron());
writer.write(';');
writer.write(schedule.getOperation().name());
if (execution == null) {
writer.write(";;;;;;;;");
} else {
// Last execution
writeExecutionStatus(writer, execution, df);
}
// Next execution
try {
final Date next = new CronExpression(schedule.getCron()).getNextValidTimeAfter(now);
writer.write(';');
writer.write(df.format(next));
writer.write(';');
writer.write(String.valueOf(next.getTime()));
} catch (final ParseException pe) {
// Non blocking error
log.error("Invalid CRON expression {}", schedule.getCron());
writer.write(";ERROR;ERROR");
}
}
// Ensure buffer is flushed
writer.flush();
}
use of org.quartz.CronExpression in project openolat by klemens.
the class ReminderModuleTest method testCronJob_everyHeightHours.
@Test
public void testCronJob_everyHeightHours() throws ParseException {
reminderModule.setScheduler("8", "6:30");
sleep(1000);
String cron = reminderModule.getCronExpression();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 5);
CronExpression cronExpression = new CronExpression(cron);
Date d1 = cronExpression.getNextValidTimeAfter(cal.getTime());
Calendar triggerCal = Calendar.getInstance();
triggerCal.setTime(d1);
Assert.assertEquals(6, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
Date d2 = cronExpression.getNextValidTimeAfter(d1);
triggerCal.setTime(d2);
Assert.assertEquals(14, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
Date d3 = cronExpression.getNextValidTimeAfter(d2);
triggerCal.setTime(d3);
Assert.assertEquals(22, triggerCal.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, triggerCal.get(Calendar.MINUTE));
}
use of org.quartz.CronExpression in project pentaho-platform by pentaho.
the class QuartzScheduler method setTimezone.
/**
* Update cronTrigger's timezone based on the info from caller
*
* @param cronTrigger the cron trigger to update
* @param timezone the timezone to set
*/
void setTimezone(CronTrigger cronTrigger, String timezone) throws SchedulerException {
try {
CronExpression cronEx = new CronExpression(cronTrigger.getCronExpression());
cronEx.setTimeZone(TimeZone.getTimeZone(timezone));
cronTrigger.setCronExpression(cronEx);
} catch (ParseException e) {
throw new SchedulerException(Messages.getInstance().getString("ComplexJobTrigger.ERROR_0001_InvalidCronExpression"), // $NON-NLS-1$
e);
}
}
use of org.quartz.CronExpression in project alfresco-repository by Alfresco.
the class LocalTransformServiceRegistryConfigTest method testAdditionAndRemovalOfTEngines.
@Test
public void testAdditionAndRemovalOfTEngines() throws Exception {
CronExpression origCronExpression = registry.getCronExpression();
CronExpression origInitialAndOnErrorCronExpression = registry.getInitialAndOnErrorCronExpression();
String origPipelineConfigDir = registry.getPipelineConfigDir();
try {
readConfigCount = 0;
// every 2 seconds rather than 10 seconds
registry.setInitialAndOnErrorCronExpression(new CronExpression(("0/2 * * ? * * *")));
// every 4 seconds rather than every hour
registry.setCronExpression(new CronExpression(("0/4 * * ? * * *")));
// Sleep until a 6 second boundary, in order to make testing clearer.
// It avoids having to work out schedule offsets and extra quick runs that can otherwise take place.
Thread.sleep(4000 - System.currentTimeMillis() % 4000);
startMs = System.currentTimeMillis();
registry.setMockSuccessReadingConfig(false);
registry.afterPropertiesSet();
TransformServiceRegistryImpl.Data data = registry.getData();
// 1 seconds
Thread.sleep(1000);
data = registry.assertDataChanged(data, "There should have been a read after a few milliseconds that fails");
// 3 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 2 seconds that fails");
// 5 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 4 seconds that fails");
// 7 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 6 seconds that fails");
// Should switch to normal 4s schedule after the next read, so the read at 12 seconds will be on that schedule.
// It is always possible that another quick one gets scheduled almost straight away after the next read.
registry.setMockSuccessReadingConfig(true);
// 9 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 8 seconds that succeeds");
// 11 seconds
Thread.sleep(2000);
data = registry.assertDataUnchanged(data, "There really should not have been a read until 12 seconds");
// 13 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 12 seconds that succeeds");
// Should switch back to initial/error schedule after failure
registry.setMockSuccessReadingConfig(false);
// 17 seconds
Thread.sleep(4000);
data = registry.assertDataChanged(data, "There should have been a read after 16 seconds that fails");
// 19 seconds
Thread.sleep(2000);
data = registry.assertDataChanged(data, "There should have been a read after 18 seconds");
} finally {
registry.setMockSuccessReadingConfig(true);
registry.setCronExpression(origCronExpression);
registry.setInitialAndOnErrorCronExpression(origInitialAndOnErrorCronExpression);
registry.setPipelineConfigDir(origPipelineConfigDir);
}
}
Aggregations