Search in sources :

Example 1 with CronParser

use of com.cronutils.parser.CronParser in project archiva by apache.

the class AbstractRepository method setSchedulingDefinition.

@Override
public void setSchedulingDefinition(String cronExpression) {
    CronParser parser = new CronParser(CRON_DEFINITION);
    parser.parse(cronExpression).validate();
    this.schedulingDefinition = cronExpression;
}
Also used : CronParser(com.cronutils.parser.CronParser)

Example 2 with CronParser

use of com.cronutils.parser.CronParser 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);
}
Also used : CronDefinition(com.cronutils.model.definition.CronDefinition) Cron(com.cronutils.model.Cron) CronParser(com.cronutils.parser.CronParser)

Example 3 with CronParser

use of com.cronutils.parser.CronParser 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);
    }
}
Also used : ExecutionTime(com.cronutils.model.time.ExecutionTime) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) ZonedDateTime(java.time.ZonedDateTime) CronDefinition(com.cronutils.model.definition.CronDefinition) CronType(com.cronutils.model.CronType) CronParser(com.cronutils.parser.CronParser)

Example 4 with CronParser

use of com.cronutils.parser.CronParser in project OpenGrok by OpenGrok.

the class SuggesterConfig method setRebuildCronConfig.

public void setRebuildCronConfig(final String rebuildCronConfig) {
    if (rebuildCronConfig != null) {
        // check cron format
        CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX));
        // throws IllegalArgumentException if invalid
        parser.parse(rebuildCronConfig);
    }
    this.rebuildCronConfig = rebuildCronConfig;
}
Also used : CronParser(com.cronutils.parser.CronParser)

Example 5 with CronParser

use of com.cronutils.parser.CronParser 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();
}
Also used : ExecutionTime(com.cronutils.model.time.ExecutionTime) ZonedDateTime(java.time.ZonedDateTime) CronDefinition(com.cronutils.model.definition.CronDefinition) Duration(java.time.Duration) CronParser(com.cronutils.parser.CronParser)

Aggregations

CronParser (com.cronutils.parser.CronParser)5 CronDefinition (com.cronutils.model.definition.CronDefinition)3 ExecutionTime (com.cronutils.model.time.ExecutionTime)2 ZonedDateTime (java.time.ZonedDateTime)2 Cron (com.cronutils.model.Cron)1 CronType (com.cronutils.model.CronType)1 Duration (java.time.Duration)1 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)1