use of io.kestra.core.repositories.ExecutionRepositoryInterface in project kestra by kestra-io.
the class Counts method run.
@Override
public Output run(RunContext runContext) throws Exception {
Logger logger = runContext.logger();
ExecutionRepositoryInterface executionRepository = runContext.getApplicationContext().getBean(ExecutionRepositoryInterface.class);
String query = null;
if (this.states != null) {
query = "state.current:(" + this.states.stream().map(Enum::name).collect(Collectors.joining(" OR ")) + ")";
}
List<ExecutionCount> executionCounts = executionRepository.executionCounts(flows, query, startDate != null ? ZonedDateTime.parse(runContext.render(startDate)) : null, endDate != null ? ZonedDateTime.parse(runContext.render(endDate)) : null);
logger.trace("{} flows matching filters", executionCounts.size());
List<Result> count = executionCounts.stream().filter(throwPredicate(item -> runContext.render(this.expression, ImmutableMap.of("count", item.getCount().intValue())).equals("true"))).map(item -> Result.builder().namespace(item.getNamespace()).flowId(item.getFlowId()).count(item.getCount()).build()).collect(Collectors.toList());
logger.debug("{} flows matching the expression", count.size());
return Output.builder().results(count).build();
}
use of io.kestra.core.repositories.ExecutionRepositoryInterface in project kestra by kestra-io.
the class ListenersTestTask method run.
@SuppressWarnings("unchecked")
@Override
public ListenersTestTask.Output run(RunContext runContext) throws Exception {
ExecutionRepositoryInterface executionRepository = runContext.getApplicationContext().getBean(ExecutionRepositoryInterface.class);
RetryUtils.Instance<Execution, NoSuchElementException> retryInstance = runContext.getApplicationContext().getBean(RetryUtils.class).of(Exponential.builder().delayFactor(2.0).interval(Duration.ofSeconds(1)).maxInterval(Duration.ofSeconds(15)).maxAttempt(-1).maxDuration(Duration.ofMinutes(10)).build(), runContext.logger());
String executionRendererId = runContext.render(runContext.render("{{ execution.id }}"));
Execution execution = retryInstance.run(NoSuchElementException.class, () -> executionRepository.findById(executionRendererId).filter(e -> e.getState().getCurrent().isTerninated()).orElseThrow(() -> new NoSuchElementException("Unable to find execution '" + executionRendererId + "'")));
return Output.builder().value(execution.toString()).build();
}
Aggregations