Source:
<code>private WorkflowInstance saveWorkflowInstanceState(StateExecutionImpl execution, WorkflowInstance instance, AbstractWorkflowDefinition<?> definition, WorkflowInstanceAction.Builder actionBuilder) { if (definition.getMethod(execution.getNextState()) == null && execution.getNextActivation() != null) { logger.debug("No handler method defined for {}, clearing next activation", execution.getNextState()); execution.setNextActivation(null); } WorkflowState nextState = definition.getState(execution.getNextState()); if (instance.parentWorkflowId != null && nextState.getType() == WorkflowStateType.end) { try { String parentType = workflowInstanceDao.getWorkflowInstanceType(instance.parentWorkflowId); AbstractWorkflowDefinition<? extends WorkflowState> parentDefinition = workflowDefinitions .getWorkflowDefinition(parentType); String[] waitStates = parentDefinition.getStates().stream() .filter(state -> state.getType() == WorkflowStateType.wait) .map(WorkflowState::name) .toArray(String[]::new); if (waitStates.length > 0) { execution.wakeUpParentWorkflow(waitStates); } } catch (@SuppressWarnings("unused") EmptyResultDataAccessException e) { } } WorkflowInstance.Builder instanceBuilder = new WorkflowInstance.Builder(instance) .setNextActivation(execution.getNextActivation()) .setStatus(getStatus(execution, nextState)) .setStateText(getStateText(instance, execution)) .setState(execution.getNextState()) .setRetries(execution.isRetry() ? execution.getRetries() + 1 : 0); do { try { return persistWorkflowInstanceState(execution, instance.stateVariables, actionBuilder, instanceBuilder); } catch (Exception ex) { logger.error("Failed to save workflow instance new state, retrying after seconds", instance.id, stateSaveRetryDelay, ex); sleepIgnoreInterrupted(stateSaveRetryDelay); } <START> } while (!shutdownRequested.get()); <END> throw new IllegalStateException(format("Failed to save workflow instance %s new state and shutdown requested", instance.id)); }</code><technical_language>Check shutdown in catch block above. If shutting down, log error (failed, shutting down) return instance. If not, log error (failed, retrying) sleep. check for shutdown in run method catch block also. If shutting down, log error (failed, shutting down) stateProcessingFinished = true, else log error (failed, retrying) sleep</technical_language>

Target:
private WorkflowInstance saveWorkflowInstanceState(StateExecutionImpl execution, WorkflowInstance instance, AbstractWorkflowDefinition<?> definition, WorkflowInstanceAction.Builder actionBuilder) { if (definition.getMethod(execution.getNextState()) == null && execution.getNextActivation() != null) { logger.debug("No handler method defined for {}, clearing next activation", execution.getNextState()); execution.setNextActivation(null); } WorkflowState nextState = definition.getState(execution.getNextState()); if (instance.parentWorkflowId != null && nextState.getType() == WorkflowStateType.end) { try { String parentType = workflowInstanceDao.getWorkflowInstanceType(instance.parentWorkflowId); AbstractWorkflowDefinition<? extends WorkflowState> parentDefinition = workflowDefinitions .getWorkflowDefinition(parentType); String[] waitStates = parentDefinition.getStates().stream() .filter(state -> state.getType() == WorkflowStateType.wait) .map(WorkflowState::name) .toArray(String[]::new); if (waitStates.length > 0) { execution.wakeUpParentWorkflow(waitStates); } } catch (@SuppressWarnings("unused") EmptyResultDataAccessException e) { } } WorkflowInstance.Builder instanceBuilder = new WorkflowInstance.Builder(instance) .setNextActivation(execution.getNextActivation()) .setStatus(getStatus(execution, nextState)) .setStateText(getStateText(instance, execution)) .setState(execution.getNextState()) .setRetries(execution.isRetry() ? execution.getRetries() + 1 : 0); while (true) { try { return persistWorkflowInstanceState(execution, instance.stateVariables, actionBuilder, instanceBuilder); } catch (Exception ex) { if (shutdownRequested.get()) { logger.error("Failed to save workflow instance new state, not retrying due to shutdown request. The state will be rerun on recovery.", instance.id, ex); return instance; } logger.error("Failed to save workflow instance new state, retrying after seconds", instance.id, stateSaveRetryDelay, ex); sleepIgnoreInterrupted(stateSaveRetryDelay); } } }