Search in sources :

Example 1 with ExecutionRepositoryInterface

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();
}
Also used : Schema(io.swagger.v3.oas.annotations.media.Schema) Rethrow.throwPredicate(io.kestra.core.utils.Rethrow.throwPredicate) ExecutionRepositoryInterface(io.kestra.core.repositories.ExecutionRepositoryInterface) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Plugin(io.kestra.core.models.annotations.Plugin) Flow(io.kestra.core.models.executions.statistics.Flow) ZonedDateTime(java.time.ZonedDateTime) SuperBuilder(lombok.experimental.SuperBuilder) NotNull(javax.validation.constraints.NotNull) ExecutionCount(io.kestra.core.models.executions.statistics.ExecutionCount) Collectors(java.util.stream.Collectors) lombok(lombok) PluginProperty(io.kestra.core.models.annotations.PluginProperty) State(io.kestra.core.models.flows.State) NotEmpty(javax.validation.constraints.NotEmpty) Task(io.kestra.core.models.tasks.Task) List(java.util.List) RunContext(io.kestra.core.runners.RunContext) Example(io.kestra.core.models.annotations.Example) RunnableTask(io.kestra.core.models.tasks.RunnableTask) ExecutionCount(io.kestra.core.models.executions.statistics.ExecutionCount) ExecutionRepositoryInterface(io.kestra.core.repositories.ExecutionRepositoryInterface) Logger(org.slf4j.Logger)

Example 2 with ExecutionRepositoryInterface

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();
}
Also used : Execution(io.kestra.core.models.executions.Execution) ExecutionRepositoryInterface(io.kestra.core.repositories.ExecutionRepositoryInterface) RetryUtils(io.kestra.core.utils.RetryUtils) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

ExecutionRepositoryInterface (io.kestra.core.repositories.ExecutionRepositoryInterface)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Example (io.kestra.core.models.annotations.Example)1 Plugin (io.kestra.core.models.annotations.Plugin)1 PluginProperty (io.kestra.core.models.annotations.PluginProperty)1 Execution (io.kestra.core.models.executions.Execution)1 ExecutionCount (io.kestra.core.models.executions.statistics.ExecutionCount)1 Flow (io.kestra.core.models.executions.statistics.Flow)1 State (io.kestra.core.models.flows.State)1 RunnableTask (io.kestra.core.models.tasks.RunnableTask)1 Task (io.kestra.core.models.tasks.Task)1 RunContext (io.kestra.core.runners.RunContext)1 Rethrow.throwPredicate (io.kestra.core.utils.Rethrow.throwPredicate)1 RetryUtils (io.kestra.core.utils.RetryUtils)1 Schema (io.swagger.v3.oas.annotations.media.Schema)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Collectors (java.util.stream.Collectors)1 NotEmpty (javax.validation.constraints.NotEmpty)1