Search in sources :

Example 1 with CronType

use of com.cronutils.model.CronType 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)

Aggregations

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