Skip to content

Commit

Permalink
fix(core): don't crash the worker if it receive a flowable task
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed May 25, 2023
1 parent f917c69 commit 1b9d2ee
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/src/main/java/io/kestra/core/runners/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,24 @@ private void logTerminated(WorkerTask workerTask) {
}

private WorkerTask runAttempt(WorkerTask workerTask) {
RunnableTask<?> task = (RunnableTask<?>) workerTask.getTask();

RunContext runContext = workerTask
.getRunContext()
.forWorker(this.applicationContext, workerTask);

Logger logger = runContext.logger();

if(!(workerTask.getTask() instanceof RunnableTask)) {
// 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);
TaskRun taskRun = workerTask.getTaskRun().withAttempts(attempts);
logger.error("Unable to execute the task '" + workerTask.getTask().getId() +
"': only runnable tasks can be executed by the worker but the task is of type " + workerTask.getTask().getClass());
return workerTask.withTaskRun(taskRun);
}

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

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

Expand Down

0 comments on commit 1b9d2ee

Please sign in to comment.