Search in sources :

Example 1 with Schedule

use of pipelite.Schedule in project pipelite by enasequence.

the class ScheduleRunner method executeSchedule.

protected void executeSchedule(ScheduleCron scheduleCron, ProcessEntity processEntity, ExecuteMode executeMode) {
    internalErrorHandler.execute(() -> {
        String pipelineName = processEntity.getPipelineName();
        String processId = processEntity.getProcessId();
        logContext(log.atInfo(), pipelineName, processId).log("Executing scheduled process");
        Schedule schedule = getSchedule(pipelineName);
        if (schedule == null) {
            return;
        }
        Process process = getProcess(processEntity, schedule);
        if (process == null) {
            return;
        }
        setMaximumRetries(process);
        if (executeMode != ExecuteMode.RESUME) {
            scheduleService.startExecution(pipelineName, processId);
        }
        scheduleCron.setLaunchTime(null);
        runProcess(pipelineName, process, (p) -> {
            ScheduleEntity scheduleEntity = scheduleService.getSavedSchedule(pipelineName).get();
            ZonedDateTime nextLaunchTime = CronUtils.launchTime(scheduleCron.getCron(), scheduleEntity.getStartTime());
            internalErrorHandler.execute(() -> scheduleService.endExecution(processEntity, nextLaunchTime));
            scheduleCron.setLaunchTime(nextLaunchTime);
            decreaseMaximumExecutions(pipelineName);
        });
    });
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Schedule(pipelite.Schedule) Process(pipelite.process.Process) ScheduleEntity(pipelite.entity.ScheduleEntity)

Example 2 with Schedule

use of pipelite.Schedule in project pipelite by enasequence.

the class RegisteredPipelineService method registerPipeline.

public void registerPipeline(RegisteredPipeline registeredPipeline) {
    String pipelineName = registeredPipeline.pipelineName();
    if (pipelineName == null || pipelineName.trim().isEmpty()) {
        throw new PipeliteException("Missing pipeline name");
    }
    if (registeredPipelineMap.containsKey(pipelineName)) {
        throw new PipeliteException("Non-unique pipeline name: " + pipelineName);
    }
    if (registeredPipeline instanceof Schedule) {
        Schedule schedule = (Schedule) registeredPipeline;
        String cron = schedule.configurePipeline().cron();
        if (cron == null) {
            throw new PipeliteException("Missing cron expression for pipeline schedule: " + pipelineName);
        }
        if (!CronUtils.validate(cron)) {
            throw new PipeliteException("Invalid cron expression '" + cron + "' for pipeline schedule: " + pipelineName);
        }
    } else if (registeredPipeline instanceof Pipeline) {
        Pipeline pipeline = (Pipeline) registeredPipeline;
        int pipelineParallelism = pipeline.configurePipeline().pipelineParallelism();
        if (pipelineParallelism < 1) {
            throw new PipeliteException("Invalid pipeline parallelism '" + pipelineParallelism + "' for pipeline: " + pipelineName);
        }
    }
    registeredPipelineMap.put(pipelineName, registeredPipeline);
}
Also used : Schedule(pipelite.Schedule) PipeliteException(pipelite.exception.PipeliteException) RegisteredPipeline(pipelite.RegisteredPipeline) Pipeline(pipelite.Pipeline)

Example 3 with Schedule

use of pipelite.Schedule in project pipelite by enasequence.

the class RegisteredScheduleService method saveSchedules.

@PostConstruct
public void saveSchedules() {
    registeredPipelineService.getRegisteredPipelines(Schedule.class).forEach(schedule -> {
        String pipelineName = schedule.pipelineName();
        Optional<ScheduleEntity> savedScheduleEntityOpt = scheduleService.getSavedSchedule(pipelineName);
        if (!savedScheduleEntityOpt.isPresent()) {
            createSchedule(schedule);
        } else {
            ScheduleEntity savedScheduleEntity = savedScheduleEntityOpt.get();
            String registeredCron = savedScheduleEntity.getCron();
            String registeredServiceName = savedScheduleEntity.getServiceName();
            String cron = schedule.configurePipeline().cron();
            boolean isCronChanged = !registeredCron.equals(cron);
            boolean isServiceNameChanged = !registeredServiceName.equals(serviceName);
            if (isCronChanged) {
                log.atInfo().log("Cron changed for pipeline schedule: " + schedule.pipelineName());
            }
            if (isServiceNameChanged) {
                log.atInfo().log("Service name changed for pipeline schedule: " + schedule.pipelineName());
            }
            if (isServiceNameChanged && !pipeliteConfiguration.service().isForce()) {
                throw new PipeliteException("Forceful startup not requested. Service name changed for pipeline schedule " + pipelineName + " from " + registeredServiceName + " to " + serviceName);
            }
            if (isServiceNameChanged) {
                log.atWarning().log("Forceful startup requested. Changing service name for pipeline schedule " + pipelineName + " from " + registeredServiceName + " to " + serviceName);
            }
            if (isCronChanged || isServiceNameChanged) {
                log.atInfo().log("Updating pipeline schedule: " + schedule.pipelineName());
                try {
                    savedScheduleEntity.setCron(cron);
                    savedScheduleEntity.setDescription(CronUtils.describe(cron));
                    savedScheduleEntity.setServiceName(serviceName);
                    if (!savedScheduleEntity.isActive()) {
                        savedScheduleEntity.setNextTime(CronUtils.launchTime(savedScheduleEntity.getCron(), savedScheduleEntity.getStartTime()));
                    }
                    scheduleService.saveSchedule(savedScheduleEntity);
                } catch (Exception ex) {
                    throw new PipeliteException("Failed to update pipeline schedule: " + schedule.pipelineName(), ex);
                }
            }
        }
    });
}
Also used : Schedule(pipelite.Schedule) PipeliteException(pipelite.exception.PipeliteException) ScheduleEntity(pipelite.entity.ScheduleEntity) PipeliteException(pipelite.exception.PipeliteException) PostConstruct(javax.annotation.PostConstruct)

Example 4 with Schedule

use of pipelite.Schedule in project pipelite by enasequence.

the class ScheduleCache method getSchedule.

public Schedule getSchedule(String pipelineName) {
    if (cache.containsKey(pipelineName)) {
        return cache.get(pipelineName);
    }
    Schedule schedule = service.getRegisteredPipeline(pipelineName, Schedule.class);
    if (schedule == null) {
        return null;
    }
    cache.putIfAbsent(pipelineName, schedule);
    return cache.get(pipelineName);
}
Also used : Schedule(pipelite.Schedule)

Example 5 with Schedule

use of pipelite.Schedule in project pipelite by enasequence.

the class ProcessRunnerPoolManager method _createScheduleRunner.

/**
 * Should not be called directly. Called by {@link #createPools()}.
 */
public void _createScheduleRunner() {
    if (state != State.STOPPED) {
        log.atWarning().log("Failed to create schedule runners manager state is not stopped");
        return;
    }
    if (pipeliteServices.registeredPipeline().isSchedules()) {
        ScheduleRunner scheduleRunner = createScheduler(pipeliteServices.registeredPipeline().getRegisteredPipelines(Schedule.class));
        log.atInfo().log("Creating schedule runner");
        pipeliteServices.runner().setScheduleRunner(scheduleRunner);
        pools.add(scheduleRunner);
        log.atInfo().log("Created schedule runner");
    }
}
Also used : ScheduleRunner(pipelite.runner.schedule.ScheduleRunner) Schedule(pipelite.Schedule)

Aggregations

Schedule (pipelite.Schedule)5 ScheduleEntity (pipelite.entity.ScheduleEntity)2 PipeliteException (pipelite.exception.PipeliteException)2 ZonedDateTime (java.time.ZonedDateTime)1 PostConstruct (javax.annotation.PostConstruct)1 Pipeline (pipelite.Pipeline)1 RegisteredPipeline (pipelite.RegisteredPipeline)1 Process (pipelite.process.Process)1 ScheduleRunner (pipelite.runner.schedule.ScheduleRunner)1