use of io.kestra.core.models.triggers.Trigger in project kestra by kestra-io.
the class SchedulerTriggerStateInterfaceTest method all.
@Test
void all() {
Trigger.TriggerBuilder<?, ?> builder = trigger();
Optional<Trigger> find = triggerState.findLast(builder.build());
assertThat(find.isPresent(), is(false));
Trigger save = triggerState.save(builder.build());
find = triggerState.findLast(save);
assertThat(find.isPresent(), is(true));
assertThat(find.get().getExecutionId(), is(save.getExecutionId()));
save = triggerState.save(builder.executionId(IdUtils.create()).build());
find = triggerState.findLast(save);
assertThat(find.isPresent(), is(true));
assertThat(find.get().getExecutionId(), is(save.getExecutionId()));
}
use of io.kestra.core.models.triggers.Trigger in project kestra by kestra-io.
the class ExecutorTriggerCleaner method topology.
public StreamsBuilder topology() {
StreamsBuilder builder = new KafkaStreamsBuilder();
KStream<String, Executor> executorKStream = kafkaStreamSourceService.executorKStream(builder);
KStream<String, Executor> executionWithFlowKStream = kafkaStreamSourceService.executorWithFlow(executorKStream, false);
GlobalKTable<String, Trigger> triggerGlobalKTable = kafkaStreamSourceService.triggerGlobalKTable(builder);
executionWithFlowKStream.filter((key, value) -> value.getExecution().getTrigger() != null, Named.as("cleanTrigger-hasTrigger-filter")).filter((key, value) -> conditionService.isTerminatedWithListeners(value.getFlow(), value.getExecution()), Named.as("cleanTrigger-terminated-filter")).join(triggerGlobalKTable, (key, executionWithFlow) -> Trigger.uid(executionWithFlow.getExecution()), (execution, trigger) -> trigger.resetExecution(), Named.as("cleanTrigger-join")).selectKey((key, value) -> queueService.key(value)).to(kafkaAdminService.getTopicName(Trigger.class), Produced.with(Serdes.String(), JsonSerde.of(Trigger.class)));
return builder;
}
use of io.kestra.core.models.triggers.Trigger in project kestra by kestra-io.
the class AbstractScheduler method getLastTrigger.
private Trigger getLastTrigger(FlowWithPollingTrigger f, ZonedDateTime now) {
return triggerState.findLast(f.getTriggerContext()).orElseGet(() -> {
ZonedDateTime nextDate = f.getPollingTrigger().nextEvaluationDate(f.getConditionContext(), Optional.empty());
Trigger build = Trigger.builder().date(nextDate.compareTo(now) < 0 ? nextDate : now).flowId(f.getFlow().getId()).flowRevision(f.getFlow().getRevision()).namespace(f.getFlow().getNamespace()).triggerId(f.getTriggerContext().getTriggerId()).updatedDate(Instant.now()).build();
// but since we could have some changed on the flow in meantime, we wait 1 min before saving them.
if (triggerStateSaved.containsKey(build.uid())) {
Trigger cachedTrigger = triggerStateSaved.get(build.uid());
if (cachedTrigger.getUpdatedDate() != null && Instant.now().isAfter(cachedTrigger.getUpdatedDate().plusSeconds(60))) {
triggerState.save(build);
triggerStateSaved.remove(build.uid());
}
return cachedTrigger;
} else {
triggerStateSaved.put(build.uid(), build);
}
return build;
});
}
use of io.kestra.core.models.triggers.Trigger in project kestra by kestra-io.
the class AbstractScheduler method saveLastTriggerAndEmitExecution.
protected synchronized void saveLastTriggerAndEmitExecution(SchedulerExecutionWithTrigger executionWithTrigger) {
Trigger trigger = Trigger.of(executionWithTrigger.getTriggerContext(), executionWithTrigger.getExecution());
this.triggerState.save(trigger);
this.executionQueue.emit(executionWithTrigger.getExecution());
}
use of io.kestra.core.models.triggers.Trigger in project kestra by kestra-io.
the class RestoreQueueService method triggers.
public int triggers(boolean noRecreate) {
TriggerRepositoryInterface triggerRepository = applicationContext.getBean(TriggerRepositoryInterface.class);
List<Trigger> triggers = new ArrayList<>(triggerRepository.findAll());
return this.send(triggers, QueueFactoryInterface.TRIGGER_NAMED, Trigger.class, noRecreate);
}
Aggregations