Skip to content

Commit

Permalink
fix(core): fix processing of execution killed with tenant (#4173)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Jul 5, 2024
1 parent a152354 commit 5d4c4dc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
import lombok.ToString;
import lombok.experimental.SuperBuilder;

/**
* The Kestra event for killing an execution. A {@link ExecutionKilled} can be in two states:
* <p>
* <pre>
* - {@link State#REQUESTED}: The event was requested either by an Executor or by an external request.
* - {@link State#EXECUTED}: The event was consumed and processed by the Executor.
* </pre>
*
* A {@link ExecutionKilled} will always transit from {@link State#REQUESTED} to {@link State#EXECUTED}
* regardless of whether the associated execution exist or not to ensure that Workers will be notified for the tasks
* to be killed no matter what the circumstances.
* <p>
* IMPORTANT: A {@link ExecutionKilled} is considered to be a fire-and-forget event. As a result, we do not manage a
* COMPLETED state, i.e., the Executor will never wait for Workers to process an executed {@link ExecutionKilled}
* before considering an execution to be KILLED.
*/
@Getter
@SuperBuilder
@EqualsAndHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
* The Kestra event for killing an execution. A {@link ExecutionKilledExecution} can be in two states:
* <p>
* <pre>
* - {@link State#REQUESTED}: The event was requested either by an Executor or by an external request.
* - {@link State#EXECUTED}: The event was consumed and processed by the Executor.
* </pre>
*
* A {@link ExecutionKilledExecution} will always transit from {@link State#REQUESTED} to {@link State#EXECUTED}
* regardless of whether the associated execution exist or not to ensure that Workers will be notified for the tasks
* to be killed no matter what the circumstances.
* <p>
* IMPORTANT: A {@link ExecutionKilledExecution} is considered to be a fire-and-forget event. As a result, we do not manage a
* COMPLETED state, i.e., the Executor will never wait for Workers to process an executed {@link ExecutionKilledExecution}
* before considering an execution to be KILLED.
*/
@Getter
@SuperBuilder
@EqualsAndHashCode
Expand All @@ -47,8 +31,9 @@ public class ExecutionKilledExecution extends ExecutionKilled implements TenantI
Boolean isOnKillCascade;

public boolean isEqual(WorkerTask workerTask) {
return (workerTask.getTaskRun().getTenantId() == null || (workerTask.getTaskRun().getTenantId() != null && workerTask.getTaskRun().getTenantId().equals(this.tenantId))) &&
workerTask.getTaskRun().getExecutionId().equals(this.executionId);
String taskTenantId = workerTask.getTaskRun().getTenantId();
String taskExecutionId = workerTask.getTaskRun().getExecutionId();
return (taskTenantId == null || taskTenantId.equals(this.tenantId)) && taskExecutionId.equals(this.executionId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public Flux<ExecutionKilledExecution> killSubflowExecutions(final String tenantI
.executionId(childExecution.getId())
.isOnKillCascade(true)
.state(ExecutionKilled.State.REQUESTED) // Event will be reentrant in the Executor.
.tenantId(tenantId)
.build()
);
}
Expand Down
1 change: 1 addition & 0 deletions jdbc/src/main/java/io/kestra/jdbc/runner/JdbcExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ private void killQueue(Either<ExecutionKilled, DeserializationException> either)
.executionId(killedExecution.getExecutionId())
.isOnKillCascade(false)
.state(ExecutionKilled.State.EXECUTED)
.tenantId(killedExecution.getTenantId())
.build()
);

Expand Down

0 comments on commit 5d4c4dc

Please sign in to comment.