Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): don't retry a task if the execution is killed #2057

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions core/src/main/java/io/kestra/core/runners/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ private WorkerTaskResult run(WorkerTask workerTask, Boolean cleanUp) throws Queu
WorkerTask finalWorkerTask = Failsafe
.with(AbstractRetry.<WorkerTask>retryPolicy(workerTask.getTask().getRetry())
.handleResultIf(result -> result.getTaskRun().lastAttempt() != null &&
Objects.requireNonNull(result.getTaskRun().lastAttempt()).getState().getCurrent() == State.Type.FAILED
result.getTaskRun().lastAttempt().getState().getCurrent() == State.Type.FAILED &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It lacks a test to cover it I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to make one but as it's by nature racy the test might be flaky.

!killedExecution.contains(result.getTaskRun().getExecutionId())
)
.onRetry(e -> {
WorkerTask lastResult = e.getLastResult();
Expand Down Expand Up @@ -438,7 +439,7 @@ private WorkerTask runAttempt(WorkerTask workerTask) {

Logger logger = runContext.logger();

if (!(workerTask.getTask() instanceof RunnableTask)) {
if (!(workerTask.getTask() instanceof RunnableTask<?> task)) {
// This should never happen but better to deal with it than crashing the Worker
TaskRunAttempt attempt = TaskRunAttempt.builder().state(new State().withState(State.Type.FAILED)).build();
List<TaskRunAttempt> attempts = this.addAttempt(workerTask, attempt);
Expand All @@ -448,8 +449,6 @@ private WorkerTask runAttempt(WorkerTask workerTask) {
return workerTask.withTaskRun(taskRun);
}

RunnableTask<?> task = (RunnableTask<?>) workerTask.getTask();

TaskRunAttempt.TaskRunAttemptBuilder builder = TaskRunAttempt.builder()
.state(new State().withState(State.Type.RUNNING));

Expand Down Expand Up @@ -497,7 +496,7 @@ private WorkerTask runAttempt(WorkerTask workerTask) {
log.debug("Outputs\n{}", JacksonMapper.log(workerThread.getTaskOutput()));
}

if (runContext.metrics().size() > 0 && log.isTraceEnabled()) {
if (!runContext.metrics().isEmpty() && log.isTraceEnabled()) {
log.trace("Metrics\n{}", JacksonMapper.log(runContext.metrics()));
}

Expand Down