Skip to content

Commit

Permalink
pass retry count to state save exception analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed Feb 5, 2021
1 parent 3bbf8a8 commit 55ad024
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DefaultStateSaveExceptionAnalyzer(Environment env) {
* {@inheritDoc}
*/
@Override
public StateSaveExceptionHandling analyze(Exception e) {
public StateSaveExceptionHandling analyze(Exception e, int saveRetryCount) {
return handling;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public interface StateSaveExceptionAnalyzer {
*
* @param e
* The exception to be analyzed.
* @param saveRetryCount
* How many times the saving has been attempted before this attempt.
* @return How the exception should be handled.
*/
StateSaveExceptionHandling analyze(Exception e);
StateSaveExceptionHandling analyze(Exception e, int saveRetryCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private WorkflowInstance saveWorkflowInstanceState(StateExecutionImpl execution,
.setStateText(getStateText(instance, execution)) //
.setState(execution.getNextState()) //
.setRetries(execution.isRetry() ? execution.getRetries() + 1 : 0);
int saveRetryCount = 0;
while (true) {
try {
return persistWorkflowInstanceState(execution, instance.stateVariables, actionBuilder, instanceBuilder);
Expand All @@ -302,7 +303,7 @@ private WorkflowInstance saveWorkflowInstanceState(StateExecutionImpl execution,
// return the original instance since persisting failed
return instance;
}
StateSaveExceptionHandling handling = stateSaveExceptionAnalyzer.analyze(ex);
StateSaveExceptionHandling handling = stateSaveExceptionAnalyzer.analyze(ex, saveRetryCount++);
if (handling.logStackTrace) {
nflowLogger.log(logger, handling.logLevel, "Failed to save workflow instance {} new state, retrying after {} seconds.",
new Object[] { instance.id, handling.retryDelay, ex });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DefaultStateSaveExceptionAnalyzerTest {

@Test
void analyzeReturnsConfiguredDelay() {
StateSaveExceptionHandling handling = analyzer.analyze(new Exception());
StateSaveExceptionHandling handling = analyzer.analyze(new Exception(), 0);

assertEquals(handling.logLevel, Level.ERROR);
assertTrue(handling.logStackTrace);
Expand Down

0 comments on commit 55ad024

Please sign in to comment.