diff --git a/jdbc/src/main/java/io/kestra/jdbc/runner/JdbcExecutor.java b/jdbc/src/main/java/io/kestra/jdbc/runner/JdbcExecutor.java index e9f03d8dee1..20934df53ad 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/runner/JdbcExecutor.java +++ b/jdbc/src/main/java/io/kestra/jdbc/runner/JdbcExecutor.java @@ -933,6 +933,13 @@ private void toExecution(Executor executor, boolean ignoreFailure) { } if (!shouldSend) { + // delete the execution from the state storage if ended + // IMPORTANT: it must be done here as it's when the execution arrives 'again' with a terminated state, + // so we are sure at this point that no new executions will be created otherwise the tate storage would be re-created by the execution queue. + if (executorService.canBePurged(executor)) { + executorStateStorage.delete(executor.getExecution()); + } + return; } @@ -957,11 +964,6 @@ private void toExecution(Executor executor, boolean ignoreFailure) { ((JdbcQueue) this.executionQueue).emitOnly(null, executor.getExecution()); } - // delete the execution from the state storage if ended - if (executorService.canBePurged(executor)) { - executorStateStorage.delete(executor.getExecution()); - } - Execution execution = executor.getExecution(); // handle flow triggers on state change if (!execution.getState().getCurrent().equals(executor.getOriginalState())) {