use of com.cronutils.model.definition.CronDefinition in project hive by apache.
the class ScheduledQueryAnalyzer method getDefaultCronBuilder.
private CronBuilder getDefaultCronBuilder() {
CronDefinition definition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronBuilder b = CronBuilder.cron(definition).withYear(always()).withDoM(always()).withMonth(always()).withDoW(questionMark()).withHour(always()).withMinute(always()).withMinute(always()).withSecond(always());
return b;
}
use of com.cronutils.model.definition.CronDefinition in project hive by apache.
the class ObjectStore method computeNextExecutionTime.
private Integer computeNextExecutionTime(String schedule, ZonedDateTime time) throws InvalidInputException {
CronType cronType = CronType.QUARTZ;
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(cronType);
CronParser parser = new CronParser(cronDefinition);
// Get date for last execution
try {
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(schedule));
Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(time);
if (!nextExecution.isPresent()) {
// no valid next execution time.
return null;
}
return (int) nextExecution.get().toEpochSecond();
} catch (IllegalArgumentException iae) {
String message = "Invalid " + cronType + " schedule expression: '" + schedule + "'";
LOG.error(message, iae);
throw new InvalidInputException(message);
}
}
use of com.cronutils.model.definition.CronDefinition in project OpenGrok by OpenGrok.
the class SuggesterServiceImpl method getTimeToNextRebuild.
private Duration getTimeToNextRebuild() {
String cronDefinition = env.getSuggesterConfig().getRebuildCronConfig();
if (cronDefinition == null) {
return null;
}
ZonedDateTime now = ZonedDateTime.now();
CronDefinition def = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
CronParser parser = new CronParser(def);
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(cronDefinition));
Optional<Duration> d = executionTime.timeToNextExecution(now);
if (d.isEmpty()) {
throw new IllegalStateException("Cannot determine time to next execution");
}
return d.get();
}
use of com.cronutils.model.definition.CronDefinition in project kylo by Teradata.
the class FeedOnTimeArrivalMetric method generateCronDescription.
private String generateCronDescription(String cronExp) {
CronDefinition quartzDef = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(quartzDef);
Cron c = parser.parse(cronExp);
return CronDescriptor.instance(Locale.US).describe(c);
}
Aggregations