use of io.kestra.core.models.triggers.PollingTriggerInterface in project kestra by kestra-io.
the class AbstractScheduler method handle.
private void handle() {
if (!this.isReady) {
log.warn("Scheduler is not ready, waiting");
}
metricRegistry.counter(MetricRegistry.SCHEDULER_LOOP_COUNT).increment();
ZonedDateTime now = now();
synchronized (this) {
if (log.isDebugEnabled()) {
log.debug("Scheduler next iteration for {} with {} schedulables of {} flows", now, schedulable.size(), this.flowListeners.flows().size());
}
// get all that is ready from evaluation
List<FlowWithPollingTriggerNextDate> readyForEvaluate = schedulable.stream().filter(f -> conditionService.isValid(f.getFlow(), f.getTrigger(), f.getConditionContext())).map(flowWithTrigger -> FlowWithPollingTrigger.builder().flow(flowWithTrigger.getFlow()).trigger(flowWithTrigger.getTrigger()).pollingTrigger((PollingTriggerInterface) flowWithTrigger.getTrigger()).conditionContext(flowWithTrigger.getConditionContext()).triggerContext(TriggerContext.builder().namespace(flowWithTrigger.getFlow().getNamespace()).flowId(flowWithTrigger.getFlow().getId()).flowRevision(flowWithTrigger.getFlow().getRevision()).triggerId(flowWithTrigger.getTrigger().getId()).date(now()).build()).build()).filter(f -> this.isEvaluationInterval(f, now)).filter(f -> this.isExecutionNotRunning(f, now)).map(f -> {
synchronized (this) {
Trigger lastTrigger = this.getLastTrigger(f, now);
return FlowWithPollingTriggerNextDate.of(f, f.getPollingTrigger().nextEvaluationDate(f.getConditionContext(), Optional.of(lastTrigger)));
}
}).filter(Objects::nonNull).collect(Collectors.toList());
if (log.isDebugEnabled()) {
log.debug("Scheduler will evaluate for {} with {} readyForEvaluate of {} schedulables", now, readyForEvaluate.size(), schedulable.size());
}
metricRegistry.counter(MetricRegistry.SCHEDULER_EVALUATE_COUNT).increment(readyForEvaluate.size());
// submit ready one to cached thread pool
readyForEvaluate.forEach(f -> {
schedulableNextDate.put(f.getTriggerContext().uid(), f);
if (f.getPollingTrigger().getInterval() == null) {
try {
this.handleEvaluatePollingTriggerResult(this.evaluatePollingTrigger(f));
} catch (Exception e) {
AbstractScheduler.logError(f, e);
}
} else {
this.addToRunning(f.getTriggerContext(), now);
ListenableFuture<SchedulerExecutionWithTrigger> result = cachedExecutor.submit(() -> this.evaluatePollingTrigger(f));
Futures.addCallback(result, new EvaluateFuture(this, f), cachedExecutor);
}
});
}
}
use of io.kestra.core.models.triggers.PollingTriggerInterface in project kestra by kestra-io.
the class AbstractScheduler method computeSchedulable.
private void computeSchedulable(List<Flow> flows) {
schedulableNextDate = new HashMap<>();
this.schedulable = flows.stream().filter(flow -> flow.getTriggers() != null && flow.getTriggers().size() > 0).flatMap(flow -> flow.getTriggers().stream().map(trigger -> {
RunContext runContext = runContextFactory.of(flow, trigger);
return new FlowWithTrigger(flow, trigger, runContext, conditionService.conditionContext(runContext, flow, null));
})).filter(flowWithTrigger -> flowWithTrigger.getTrigger() instanceof PollingTriggerInterface).collect(Collectors.toList());
}
Aggregations