use of io.kestra.core.models.executions.Execution 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();
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class RunContextTest method variables.
@Test
void variables() throws TimeoutException {
Execution execution = runnerUtils.runOne("io.kestra.tests", "return");
assertThat(execution.getTaskRunList(), hasSize(3));
assertThat(ZonedDateTime.from(ZonedDateTime.parse((String) execution.getTaskRunList().get(0).getOutputs().get("value"))), ZonedDateTimeMatchers.within(10, ChronoUnit.SECONDS, ZonedDateTime.now()));
assertThat(execution.getTaskRunList().get(1).getOutputs().get("value"), is("task-id"));
assertThat(execution.getTaskRunList().get(2).getOutputs().get("value"), is("return"));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class RunContextTest method logs.
@Test
void logs() throws TimeoutException {
List<LogEntry> logs = new ArrayList<>();
List<LogEntry> filters;
workerTaskLogQueue.receive(logs::add);
Execution execution = runnerUtils.runOne("io.kestra.tests", "logs");
assertThat(execution.getTaskRunList(), hasSize(3));
filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(0));
assertThat(filters, hasSize(1));
assertThat(filters.get(0).getLevel(), is(Level.TRACE));
assertThat(filters.get(0).getMessage(), is("first t1"));
filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(1));
assertThat(filters, hasSize(1));
assertThat(filters.get(0).getLevel(), is(Level.WARN));
assertThat(filters.get(0).getMessage(), is("second io.kestra.core.tasks.debugs.Echo"));
filters = TestsUtils.filterLogs(logs, execution.getTaskRunList().get(2));
assertThat(filters, hasSize(1));
assertThat(filters.get(0).getLevel(), is(Level.ERROR));
assertThat(filters.get(0).getMessage(), is("third logs"));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class TaskDefaultsCaseTest method invalidTaskDefaults.
public void invalidTaskDefaults() throws TimeoutException {
List<LogEntry> logs = new ArrayList<>();
logQueue.receive(logs::add);
Execution execution = runnerUtils.runOne("io.kestra.tests", "invalid-task-defaults", Duration.ofSeconds(60));
assertThat(execution.getTaskRunList(), hasSize(1));
assertThat(logs.stream().filter(logEntry -> logEntry.getMessage().contains("Unrecognized field \"invalid\"")).count(), greaterThan(0L));
}
use of io.kestra.core.models.executions.Execution in project kestra by kestra-io.
the class WorkerTest method workerTask.
private WorkerTask workerTask(String sleep) {
Bash bash = Bash.builder().type(Bash.class.getName()).id("unit-test").commands(new String[] { "for i in $(seq 1 " + sleep + "); do echo $i; sleep 1; done" }).build();
Flow flow = Flow.builder().id(IdUtils.create()).namespace("io.kestra.unit-test").tasks(Collections.singletonList(bash)).build();
Execution execution = TestsUtils.mockExecution(flow, ImmutableMap.of());
ResolvedTask resolvedTask = ResolvedTask.of(bash);
return WorkerTask.builder().runContext(runContextFactory.of(ImmutableMap.of("key", "value"))).task(bash).taskRun(TaskRun.of(execution, resolvedTask)).build();
}
Aggregations