From 753f7b12b13375c4b91158c9688212bcbee2fdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 11 Feb 2025 16:32:53 +0100 Subject: [PATCH] fix(jdbc): delete the executor state at the correct stage Without this change, the executor state is deleted when the execution is terminated. Then the last execution message is emitted, which goes again into the queue wich recreates the executor state. --- .../java/io/kestra/jdbc/runner/JdbcExecutor.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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())) {