You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hop.apache.org by "beatum (via GitHub)" <gi...@apache.org> on 2026/09/23 03:50:50 UTC

[PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

beatum opened a new pull request, #8544:
URL: https://github.com/apache/hop/pull/8544

   ## Summary
   
   During pipeline execution, a REST API request may occasionally fail. For example, a pipeline may use an access token or API key to retrieve data from a third-party service. Although credentials are typically cached or stored securely, access tokens can expire. When an expired token is used, the API request may fail with an authentication or authorization error.
   
   In some pipelines, the token can be refreshed automatically before the next execution attempt. To support this scenario, this PR allows the Pipeline Executor to retry a failed pipeline a configurable number of times, with an optional delay between attempts.
   
   ## Implementation
   
   ### 1. Added configurable retry settings
   
   Added the following fields to `PipelineExecutorMeta`:
   
   - `retry_attempts`: The number of additional retry attempts after the initial execution fails.
   - `retry_delay`: The delay between retry attempts.
   
   Serialization and default-value handling are also included.
   
   ### 2. Added retry settings to the dialog
   
   Added configuration fields for retry attempts and retry delay to `PipelineExecutorDialog`.
   
   Corresponding labels and tooltips were added to:
   
   ```text
   messages_en_US.properties
   ```
   
   ### 3. Updated the runtime execution flow
   
   Updated `PipelineExecutor` to retry an execution when either of the following conditions is met:
   
   ```java
   !result.isResult()
   ```
   
   or:
   
   ```java
   nrErrors > 0
   ```
   
   If a retry delay is configured, the executor waits before starting the next attempt.
   
   The existing final-result handling remains unchanged after all execution attempts have completed.
   
   ### 4. Added and updated tests
   
   Updated the following test files and fixtures:
   
   - `PipelineExecutorMetaTest`
   - `PipelineExecutorTest`
   - `pipeline-executor-transform.xml`
   
   The tests cover:
   
   - Retry-setting serialization
   - Default retry values
   - Successful execution without retry
   - Failed execution followed by retry
   - Retry-attempt limits
   - Final-result handling after retries are exhausted
   
   ## Example Use Case
   
   1. A pipeline calls a third-party REST API using a cached access token.
   2. The token has expired, causing the API request to fail.
   3. The pipeline's error-handling logic refreshes the token.
   4. The Pipeline Executor waits for the configured delay.
   5. The Pipeline Executor retries the pipeline using the refreshed token.
   
   ## Backward Compatibility
   
   Retry behavior is disabled by default. Existing Pipeline Executor configurations continue to run once unless retry attempts are explicitly configured.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "beatum (via GitHub)" <gi...@apache.org>.
beatum commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-5805483704

   I understand and agree with the concern about adding retry behavior at a low level. It can become difficult to define where retries should stop or which failures should be considered retry-able.
   
   In this implementation, the behavior is intentionally limited:
   
   - Retries are disabled by default.
   - The user must explicitly configure the number of additional attempts.
   - Execution stops after the configured limit is reached.
   - An optional delay can be configured between attempts.
   - Existing pipeline behavior remains unchanged.
   
   I considered using the Repeat transform, but that would make this use case significantly more complex. I also tried creating a loop with Simple Evaluation, but Hop prevents this kind of pipeline loop, similar to the behavior in Pentaho Kettle.
   <img width="1062" height="693" alt="image" src="https://github.com/user-attachments/assets/2e43ad98-4d62-4b61-8350-a0338d585c47" />
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on code in PR #8544:
URL: https://github.com/apache/hop/pull/8544#discussion_r4229684898


##########
plugins/transforms/pipelineexecutor/src/main/resources/org/apache/hop/pipeline/transforms/pipelineexecutor/messages/messages_en_US.properties:
##########
@@ -70,10 +70,16 @@ PipelineExecutorDialog.ResultRows.Title=Result rows
 PipelineExecutorDialog.ResultRows.Tooltip=You can specify the target and specification of the result rows that need to be passed from the pipeline.
 PipelineExecutorDialog.RowGroup.Title=Row grouping
 PipelineExecutorDialog.RowGroup.Tooltip=Determine how many rows of data are passed to the pipeline before execution
+PipelineExecutorDialog.Retry.Title=Retry
+PipelineExecutorDialog.Retry.Tooltip=Configure retries for failed child pipeline executions.
 PipelineExecutorDialog.RunConfiguration.Label=Run configuration
 PipelineExecutorDialog.RunConfiguration.Tooltip=The pipeline run configuration used to execute the specified pipeline. Use the buttons to create, edit or open the selected configuration.
 PipelineExecutorDialog.WaitTimeout.Label=Stop after (milliseconds)
 PipelineExecutorDialog.WaitTimeout.Tooltip=Maximum time to wait for the pipeline to complete, in milliseconds. Empty or 0 means wait indefinitely. When the time is reached the pipeline is stopped and the execution result is reported as failed. You can use a variable such as '${MAX_WAIT_MS}'.
+PipelineExecutorDialog.RetryAttempts.Label=Retry attempts on failure

Review Comment:
   **[suggestion]** The new options are not documented on the Pipeline Executor page (`docs/hop-user-manual/modules/ROOT/pages/pipeline/transforms/pipeline-executor.adoc`). That page has an options table and today describes stop-after only.
   
   **Suggestion:** Document retry attempts and retry delay there, including the default of no retries, and state whether stop-after applies to each attempt or is a shared budget across attempts and the delay.



##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -283,12 +294,55 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
       result.setResult(false);
       result.setNrErrors(1);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toInt(resolve(meta.getRetryAttempts()), 0));
+    long retryDelayMs = Math.max(0L, Const.toLong(resolve(meta.getRetryDelay()), 0L));
+    long configuredTimeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
+    long retryStartTime = System.currentTimeMillis();
+
+    Result result = null;
+    for (int attempt = 0; attempt <= retryAttempts; attempt++) {
+      long timeoutForAttemptMs = configuredTimeoutMs;
+      if (configuredTimeoutMs > 0) {

Review Comment:
   **[bug]** Stop-after is folded into one shared budget for every attempt, but the retry delay does not honor that budget. `Thread.sleep(retryDelayMs)` always sleeps the full delay, so a stop-after of 1000 ms and a retry delay of 30000 ms blocks the transform for about 30 s after a fast failure and only then sees `remainingMs <= 0` and skips the retry. The same budget means a child that was stopped for hitting the timeout has no time left for another attempt, and a later attempt can be started with only a few milliseconds and killed immediately. The dialog tooltip and `pipeline-executor.adoc` still describe stop-after as the maximum wait for that child pipeline, which is what a single execution did before this change.
   
   **Suggestion:** Pass the original `parseTimeoutMs` value into every attempt so stop-after keeps its per-execution meaning. If a total deadline is intentional, cap the sleep with the remaining time, do not start an attempt when the remainder is too small to be useful, and update the tooltip and manual to say the limit covers every attempt and the delay.



##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -283,12 +294,55 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
       result.setResult(false);
       result.setNrErrors(1);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toInt(resolve(meta.getRetryAttempts()), 0));
+    long retryDelayMs = Math.max(0L, Const.toLong(resolve(meta.getRetryDelay()), 0L));
+    long configuredTimeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
+    long retryStartTime = System.currentTimeMillis();
+
+    Result result = null;
+    for (int attempt = 0; attempt <= retryAttempts; attempt++) {
+      long timeoutForAttemptMs = configuredTimeoutMs;
+      if (configuredTimeoutMs > 0) {
+        long elapsedMs = System.currentTimeMillis() - retryStartTime;
+        long remainingMs = configuredTimeoutMs - elapsedMs;
+        if (remainingMs <= 0) {
+          if (result == null) {
+            result = new Result();
+            result.setResult(false);
+            result.setNrErrors(1);
+          }
+          break;
+        }
+        timeoutForAttemptMs = remainingMs;
+      }
+
+      result = executePipelineAttempt(parameterValues, timeoutForAttemptMs);
+      if (!isFailedResult(result) || attempt == retryAttempts) {
+        break;
+      }
+      if (retryDelayMs > 0) {
+        try {
+          Thread.sleep(retryDelayMs);
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+          logError("Interrupted while waiting before retrying failed child pipeline execution", e);

Review Comment:
   **[nit]** This message is hard-coded English. The other user-visible strings in this transform go through `BaseMessages` and `messages_en_US.properties`.
   
   **Suggestion:** Add a `PipelineExecutor.Log.RetryInterrupted` key and log that.



##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -283,12 +294,55 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
       result.setResult(false);
       result.setNrErrors(1);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toInt(resolve(meta.getRetryAttempts()), 0));
+    long retryDelayMs = Math.max(0L, Const.toLong(resolve(meta.getRetryDelay()), 0L));
+    long configuredTimeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
+    long retryStartTime = System.currentTimeMillis();
+
+    Result result = null;
+    for (int attempt = 0; attempt <= retryAttempts; attempt++) {
+      long timeoutForAttemptMs = configuredTimeoutMs;
+      if (configuredTimeoutMs > 0) {
+        long elapsedMs = System.currentTimeMillis() - retryStartTime;
+        long remainingMs = configuredTimeoutMs - elapsedMs;
+        if (remainingMs <= 0) {
+          if (result == null) {
+            result = new Result();
+            result.setResult(false);
+            result.setNrErrors(1);
+          }
+          break;
+        }
+        timeoutForAttemptMs = remainingMs;
+      }
+
+      result = executePipelineAttempt(parameterValues, timeoutForAttemptMs);

Review Comment:
   **[bug]** A parent stop is ignored for the rest of the retry loop. `Pipeline.stopTransform` sets `stopped` and calls `stopRunning()`, which only stops `getData().getExecutorPipeline()`. After a failed attempt that engine has already finished, so the stop does not interrupt `Thread.sleep(retryDelayMs)` (the transform thread is not interrupted). This call then runs again with no `isStopped()` check, including when the delay is 0.
   
   **Suggestion:** Return before each attempt when `isStopped()` is true. Wait for the delay in short slices that also return once the transform is stopped, and do not launch another child after that.



##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -232,49 +232,60 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
     }
     pipelineExecutorData.groupTimeStart = System.currentTimeMillis();
 
+    List<String> parameterValues = incomingFieldValues;
+    if (parameterValues == null) {
+      List<String> lastIncomingFieldValues = getLastIncomingFieldValues();
+      parameterValues = !Utils.isEmpty(lastIncomingFieldValues) ? lastIncomingFieldValues : null;
+    }
+
+    // Execute the pipeline with retries if necessary
+    Result result = executeWithRetries(parameterValues);
+
+    collectPipelineResults(result);
+    collectExecutionResults(result);
+    collectExecutionResultFiles(result);
+
+    pipelineExecutorData.groupBuffer.clear();
+  }
+
+  @VisibleForTesting
+  Result executePipelineAttempt(List<String> parameterValues, long timeoutMs) throws HopException {
+    PipelineExecutorData pipelineExecutorData = getData();
+
     if (first) {

Review Comment:
   **[suggestion]** Each attempt creates a new engine and registers it as the active sub-pipeline, but the previous attempt is not stopped or removed from the logging registry. `discardLogLines` still runs only when `first` is true, and `processRow` sets `first` to false before `executePipeline`, so this block does not run between attempts. If `startThreads()` throws, the catch marks the result failed and the next attempt replaces `executorPipeline` without stopping the engine that already started. Log buffers from the failed attempts stay allocated, and the execution-log field only shows the last channel.
   
   **Suggestion:** Before another attempt, stop the previous engine if it is still running and discard its log channel. Do that from the `HopException` catch in `executePipelineAttempt` as well, instead of only when `first` is true.



##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -283,12 +294,55 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
       result.setResult(false);
       result.setNrErrors(1);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toInt(resolve(meta.getRetryAttempts()), 0));

Review Comment:
   **[bug]** Both dialog fields call `TextVar.enableExpandedInteger()`. That widget's contract, and the `#` tooltip, is that values such as `1,000`, `100k`, `1.5m`, and `1e3` are accepted and that variables are resolved before parsing (`Const.toIntExpanded` / `Const.toLongExpanded`). These lines use `Const.toInt` and `Const.toLong`, so those forms fail and become the default 0. Retries or the delay are then silently disabled. Group size in this class already parses with `Const.toIntExpanded`.
   
   **Suggestion:** Use `Const.toIntExpanded(resolve(meta.getRetryAttempts()), 0)` and `Const.toLongExpanded(resolve(meta.getRetryDelay()), 0L)`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "beatum (via GitHub)" <gi...@apache.org>.
beatum commented on code in PR #8544:
URL: https://github.com/apache/hop/pull/8544#discussion_r4237460800


##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -232,63 +232,130 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
     }
     pipelineExecutorData.groupTimeStart = System.currentTimeMillis();
 
-    if (first) {
-      discardLogLines(pipelineExecutorData);
+    List<String> parameterValues = incomingFieldValues;
+    if (parameterValues == null) {
+      List<String> lastIncomingFieldValues = getLastIncomingFieldValues();
+      parameterValues = !Utils.isEmpty(lastIncomingFieldValues) ? lastIncomingFieldValues : null;
     }
 
+    // Execute the pipeline with retries if necessary
+    Result result = executeWithRetries(parameterValues);
+
+    collectPipelineResults(result);
+    collectExecutionResults(result);
+    collectExecutionResultFiles(result);
+
+    pipelineExecutorData.groupBuffer.clear();
+  }
+
+  @VisibleForTesting
+  Result executePipelineAttempt(List<String> parameterValues, long timeoutMs) throws HopException {
+    PipelineExecutorData pipelineExecutorData = getData();
+    cleanupPreviousAttemptPipeline(pipelineExecutorData);
+
     IPipelineEngine<PipelineMeta> executorPipeline = createInternalPipeline();
     pipelineExecutorData.setExecutorPipeline(executorPipeline);
-    if (incomingFieldValues != null) {
-      // Pass parameter values
-      passParametersToPipeline(incomingFieldValues);
-    } else {
-      List<String> lastIncomingFieldValues = getLastIncomingFieldValues();
-      // incomingFieldValues == null-  There are no more rows - Last Case - pass previous values if
-      // exists
-      // If not still pass the null parameter values
-      passParametersToPipeline(
-          !Utils.isEmpty(lastIncomingFieldValues) ? lastIncomingFieldValues : incomingFieldValues);
-    }
+
+    passParametersToPipeline(parameterValues);
 
     // keep track for drill down in HopGui...
     getPipeline().addActiveSubPipeline(getTransformName(), executorPipeline);
 
-    Result result = new Result();
-    result.setRows(pipelineExecutorData.groupBuffer);
-    executorPipeline.setPreviousResult(result);
+    Result previousResult = new Result();
+    previousResult.setRows(pipelineExecutorData.groupBuffer);
+    executorPipeline.setPreviousResult(previousResult);
 
+    Result result = new Result();
     try {
       executorPipeline.prepareExecution();
 
       // run pipeline
       executorPipeline.startThreads();
 
       // Wait a while until we're done with the pipeline
-      long timeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
       boolean finishedInTime = ExecutionWait.waitForPipeline(executorPipeline, timeoutMs);
 
       result = executorPipeline.getResult();
+      if (result == null) {
+        result = new Result();
+      }
       if (!finishedInTime) {
         logError(
             BaseMessages.getString(
                 PKG, "PipelineExecutor.Log.WaitTimeoutReached", Long.toString(timeoutMs)));
-        if (result == null) {
-          result = new Result();
-        }
         result.setResult(false);
         result.setNrErrors(Math.max(1, result.getNrErrors()));
       }
     } catch (HopException e) {
       logError("An error occurred executing the pipeline: ", e);
       result.setResult(false);
       result.setNrErrors(1);
+      cleanupPreviousAttemptPipeline(pipelineExecutorData);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toIntExpanded(resolve(meta.getRetryAttempts()), 0));
+    long retryDelayMs = Math.max(0L, Const.toLongExpanded(resolve(meta.getRetryDelay()), 0L));
+    long configuredTimeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
+
+    Result result = null;
+    for (int attempt = 0; attempt <= retryAttempts; attempt++) {
+      if (isStopped()) {
+        if (result == null) {
+          result = new Result();
+          result.setResult(false);
+          result.setNrErrors(1);
+        }
+        break;
+      }
+
+      result = executePipelineAttempt(parameterValues, configuredTimeoutMs);
+      if (!isFailedResult(result) || attempt == retryAttempts) {
+        break;
+      }
+      if (!waitRetryDelay(retryDelayMs)) {
+        break;
+      }
+    }
+    return result;
+  }
+
+  private boolean waitRetryDelay(long retryDelayMs) {
+    long remainingDelayMs = retryDelayMs;
+    while (remainingDelayMs > 0) {
+      if (isStopped()) {
+        return false;
+      }
+      long sleepMs = Math.min(remainingDelayMs, 100L);
+      try {
+        Thread.sleep(sleepMs);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        logError(BaseMessages.getString(PKG, "PipelineExecutor.Log.RetryInterrupted"), e);
+        return false;
+      }
+      remainingDelayMs -= sleepMs;
+    }
+    return !isStopped();
+  }
+
+  @VisibleForTesting
+  void cleanupPreviousAttemptPipeline(PipelineExecutorData pipelineExecutorData) {
+    IPipelineEngine<PipelineMeta> executorPipeline = pipelineExecutorData.getExecutorPipeline();
+    if (executorPipeline != null && executorPipeline.isRunning()) {
+      executorPipeline.stopAll();
+    }
+    discardLogLines(pipelineExecutorData);

Review Comment:
   thanks for your time and have a good day!  
   here is my latest updates:
   
   Changed :
   - `executePipelineAttempt()` no longer cleans up at attempt start.
   - On `HopException`, it only stops a still-running child (`stopPreviousAttemptPipeline`) and does not discard logs.
   - `executeWithRetries()` now calls `cleanupPreviousAttemptPipeline()` after a failed attempt, after delay wait succeeds, and only when another retry will follow.
   
   Tests:
   - Added coverage that cleanup runs only when retrying and not when no retry will run.
   - Updated the startThreads-throws test to assert `discardLogLines()` is not called in that path.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-5809999679

   The first feature request that needs to get added is to stop retrying after a certain period of time. (where do you stop?)
   
   In my experience we'll keep seeing more feature requests for this "Retry" option ... which we'll then need to copy over to the workflow executor transform but I admit that wouldn't be the end of the world. 
   
   That being said, I would put these retry widgets onto their own "Retry" tab to clarify that it's an exceptional thing to do and to get it out of the way of regular use cases.  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-5794645796

   I hate retry on a low level with a passion. Where do you stop? Is there really no alternative?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-6097062378

   Thanks @beatum !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters merged PR #8544:
URL: https://github.com/apache/hop/pull/8544


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "beatum (via GitHub)" <gi...@apache.org>.
beatum commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-6073058951

   @mattcasters  so what any else should i keep to improve ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "beatum (via GitHub)" <gi...@apache.org>.
beatum commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-6093032549

   Thanks again for your time and for the detailed review. I really appreciate the thoughtful suggestions.here’s a summary of the latest updates:
   
   ## Retry-loop fixes
   
   Both retry-loop issues have been fixed in `PipelineExecutor`.
   
   - `executeWithRetries()` now uses the parsed `waitTimeout` **for each individual attempt**, rather than sharing one total timeout budget across all retries. This restores the intended behavior where **Stop after** applies separately to each execution attempt.
   - Added stop-aware retry handling. The executor now checks `isStopped()` before starting each attempt and waits for the retry delay through `waitRetryDelay(...)` in short 100 ms intervals. This allows it to exit promptly when the transform is stopped, instead of sleeping through the full delay or starting another child execution.
   
   Updated `PipelineExecutorTest` with the following tests:
   
   - `executeWithRetriesUsesConfiguredStopAfterForEachAttempt`
   - `executeWithRetriesDoesNotStartAnotherAttemptAfterTransformStop`
   
   ## Expanded-number support
   
   `PipelineExecutor` now parses both retry-related fields with expanded-number support, matching the dialog contract:
   
   ```java
   retryAttempts = Const.toIntExpanded(resolve(meta.getRetryAttempts()), 0);
   retryDelay = Const.toLongExpanded(resolve(meta.getRetryDelay()), 0L);
   ```
   
   That the values such like `1e0`, `100k`, and resolved variables are now handled correctly instead of silently falling back to `0`.
   
   Also added the following unit test:
   
   - `executeWithRetriesParsesExpandedRetryAttempts`
   
   ## Additional review suggestions
   
   All three additional suggestions have also been addressed:
   
   - Before starting a new attempt, `PipelineExecutor` now stops any still-running child pipeline from the previous attempt and removes that attempt’s log channel.
   - The same cleanup is also performed in the `HopException` path within `executePipelineAttempt()`.
   - Replaced the hard-coded interruption message with the i18n key `PipelineExecutor.Log.RetryInterrupted` and added the corresponding entry to `messages_en_US.properties`.
   - Updated `pipeline-executor.adoc` to document:
     - **Retry attempts on failure**
     - **Retry delay (milliseconds)**, including the default no-retry behavior
     - **Stop after (milliseconds)** applies independently to each execution attempt
     - That the retry delay occurs between attempts and is outside the per-attempt timeout


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "mattcasters (via GitHub)" <gi...@apache.org>.
mattcasters commented on code in PR #8544:
URL: https://github.com/apache/hop/pull/8544#discussion_r4236909163


##########
plugins/transforms/pipelineexecutor/src/main/java/org/apache/hop/pipeline/transforms/pipelineexecutor/PipelineExecutor.java:
##########
@@ -232,63 +232,130 @@ private void executePipeline(List<String> incomingFieldValues) throws HopExcepti
     }
     pipelineExecutorData.groupTimeStart = System.currentTimeMillis();
 
-    if (first) {
-      discardLogLines(pipelineExecutorData);
+    List<String> parameterValues = incomingFieldValues;
+    if (parameterValues == null) {
+      List<String> lastIncomingFieldValues = getLastIncomingFieldValues();
+      parameterValues = !Utils.isEmpty(lastIncomingFieldValues) ? lastIncomingFieldValues : null;
     }
 
+    // Execute the pipeline with retries if necessary
+    Result result = executeWithRetries(parameterValues);
+
+    collectPipelineResults(result);
+    collectExecutionResults(result);
+    collectExecutionResultFiles(result);
+
+    pipelineExecutorData.groupBuffer.clear();
+  }
+
+  @VisibleForTesting
+  Result executePipelineAttempt(List<String> parameterValues, long timeoutMs) throws HopException {
+    PipelineExecutorData pipelineExecutorData = getData();
+    cleanupPreviousAttemptPipeline(pipelineExecutorData);
+
     IPipelineEngine<PipelineMeta> executorPipeline = createInternalPipeline();
     pipelineExecutorData.setExecutorPipeline(executorPipeline);
-    if (incomingFieldValues != null) {
-      // Pass parameter values
-      passParametersToPipeline(incomingFieldValues);
-    } else {
-      List<String> lastIncomingFieldValues = getLastIncomingFieldValues();
-      // incomingFieldValues == null-  There are no more rows - Last Case - pass previous values if
-      // exists
-      // If not still pass the null parameter values
-      passParametersToPipeline(
-          !Utils.isEmpty(lastIncomingFieldValues) ? lastIncomingFieldValues : incomingFieldValues);
-    }
+
+    passParametersToPipeline(parameterValues);
 
     // keep track for drill down in HopGui...
     getPipeline().addActiveSubPipeline(getTransformName(), executorPipeline);
 
-    Result result = new Result();
-    result.setRows(pipelineExecutorData.groupBuffer);
-    executorPipeline.setPreviousResult(result);
+    Result previousResult = new Result();
+    previousResult.setRows(pipelineExecutorData.groupBuffer);
+    executorPipeline.setPreviousResult(previousResult);
 
+    Result result = new Result();
     try {
       executorPipeline.prepareExecution();
 
       // run pipeline
       executorPipeline.startThreads();
 
       // Wait a while until we're done with the pipeline
-      long timeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
       boolean finishedInTime = ExecutionWait.waitForPipeline(executorPipeline, timeoutMs);
 
       result = executorPipeline.getResult();
+      if (result == null) {
+        result = new Result();
+      }
       if (!finishedInTime) {
         logError(
             BaseMessages.getString(
                 PKG, "PipelineExecutor.Log.WaitTimeoutReached", Long.toString(timeoutMs)));
-        if (result == null) {
-          result = new Result();
-        }
         result.setResult(false);
         result.setNrErrors(Math.max(1, result.getNrErrors()));
       }
     } catch (HopException e) {
       logError("An error occurred executing the pipeline: ", e);
       result.setResult(false);
       result.setNrErrors(1);
+      cleanupPreviousAttemptPipeline(pipelineExecutorData);
     }
+    return result;
+  }
 
-    collectPipelineResults(result);
-    collectExecutionResults(result);
-    collectExecutionResultFiles(result);
+  private boolean isFailedResult(Result result) {
+    if (result == null) {
+      return true;
+    }
+    return !result.isResult() || result.getNrErrors() > 0;
+  }
 
-    pipelineExecutorData.groupBuffer.clear();
+  @VisibleForTesting
+  Result executeWithRetries(List<String> parameterValues) throws HopException {
+    int retryAttempts = Math.max(0, Const.toIntExpanded(resolve(meta.getRetryAttempts()), 0));
+    long retryDelayMs = Math.max(0L, Const.toLongExpanded(resolve(meta.getRetryDelay()), 0L));
+    long configuredTimeoutMs = ExecutionWait.parseTimeoutMs(this, meta.getWaitTimeout());
+
+    Result result = null;
+    for (int attempt = 0; attempt <= retryAttempts; attempt++) {
+      if (isStopped()) {
+        if (result == null) {
+          result = new Result();
+          result.setResult(false);
+          result.setNrErrors(1);
+        }
+        break;
+      }
+
+      result = executePipelineAttempt(parameterValues, configuredTimeoutMs);
+      if (!isFailedResult(result) || attempt == retryAttempts) {
+        break;
+      }
+      if (!waitRetryDelay(retryDelayMs)) {
+        break;
+      }
+    }
+    return result;
+  }
+
+  private boolean waitRetryDelay(long retryDelayMs) {
+    long remainingDelayMs = retryDelayMs;
+    while (remainingDelayMs > 0) {
+      if (isStopped()) {
+        return false;
+      }
+      long sleepMs = Math.min(remainingDelayMs, 100L);
+      try {
+        Thread.sleep(sleepMs);
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        logError(BaseMessages.getString(PKG, "PipelineExecutor.Log.RetryInterrupted"), e);
+        return false;
+      }
+      remainingDelayMs -= sleepMs;
+    }
+    return !isStopped();
+  }
+
+  @VisibleForTesting
+  void cleanupPreviousAttemptPipeline(PipelineExecutorData pipelineExecutorData) {
+    IPipelineEngine<PipelineMeta> executorPipeline = pipelineExecutorData.getExecutorPipeline();
+    if (executorPipeline != null && executorPipeline.isRunning()) {
+      executorPipeline.stopAll();
+    }
+    discardLogLines(pipelineExecutorData);

Review Comment:
   **[bug]** `discardLogLines` runs for every caller of `cleanupPreviousAttemptPipeline`, and both callers drop a log channel the execution-results row still needs.
   
   `executePipelineAttempt` calls this at the start of every attempt. Group size still defaults to 1 and retries default to 0, so the second input row deletes the previous child's channel. `collectExecutionResults` has already copied `ExecutionLogText` onto the output row, and the `ExecutionLogChannelId` on that row then points at a channel `HopLogStore.discardLines` has removed. Previously this discard ran only when `first` was still true, and `processRow` clears `first` before `executePipeline`, so those channels stayed available across groups.
   
   The `HopException` catch calls this again, before `executePipeline` reaches `collectExecutionResults`. When `prepareExecution` or `startThreads` throws on the last attempt, the execution-log field is read from a buffer this method just cleared. That catch used to leave the child log in place. `executePipelineAttemptStopsCurrentChildWhenStartThreadsThrows` only verifies `stopAll()`, so it still passes if the log is kept.
   
   **Suggestion:** In the catch, stop the engine when it is still running and leave its log channel alone. Call `discardLogLines` only when a later retry is about to start, so the last attempt's log is still there for `collectExecutionResults`. Leave the previous group's channel in place when the next input group starts its first attempt.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add Retry Mechanism for Failed Pipeline Executor Executions (hop)

Posted by "beatum (via GitHub)" <gi...@apache.org>.
beatum commented on PR #8544:
URL: https://github.com/apache/hop/pull/8544#issuecomment-5830653503

   Thank you for the insightful feedback! I realized I was focusing too narrowly on my immediate use case rather than the broader design. I really appreciate the guidance.
   
   Here are the latest updates in this commit:
   
   - **UI Organization:** Moved all Retry-related options into a dedicated **Retry** tab to keep the main configuration tab clean.
   - **Timeout / Stop Logic:**
     - The retry loop records the initial start timestamp.
     - Before each retry attempt, it calculates the remaining time budget based on the "Stop after" limit.
     - If the remaining time is less and equal to 0, retrying stops immediately.
     - Each individual attempt uses only the remaining timeout budget.
     - **"Where do you stop?"**: Right before starting the next attempt once the time budget is exhausted.
   - **Testing:** Added integration test cases (and unit tests) covering the new retry timeout behaviors and settings.
   
   <img width="772" height="710" alt="image" src="https://github.com/user-attachments/assets/fb9400b0-392b-4574-8071-91cc16bcf39e" />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org