@SuppressWarnings("null") public void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action, List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction) { Assert.isTrue(action != null, "action can not be null"); Assert.isTrue(childWorkflows != null, "childWorkflows can not be null"); Assert.isTrue(workflows != null, "workflows can not be null"); Map<String, String> changedStateVariables = instance.getChangedStateVariables(); if (!createAction && (!childWorkflows.isEmpty() || !workflows.isEmpty() || !changedStateVariables.isEmpty())) { logger.info("Forcing action creation because new workflow instances are created or state variables are changed."); createAction = true; } if (createAction) { if (sqlVariants.hasUpdateableCTE() && childWorkflows.isEmpty() && workflows.isEmpty()) { updateWorkflowInstanceWithCTE(instance, action, changedStateVariables); } else { updateWorkflowInstanceWithTransaction(instance, action, childWorkflows, workflows, changedStateVariables); } } else { updateWorkflowInstance(instance); } }
private void rescheduleUnknownWorkflowState(WorkflowInstance instance) { logger.warn("Workflow state {} not configured to workflow type {} - rescheduling workflow instance", instance.state, instance.type); instance = new WorkflowInstance.Builder(instance).setNextActivation(now().plusMinutes(unknownWorkflowStateRetryDelay)) .setStatus(inProgress).setStateText("Unsupported workflow state").build(); workflowInstanceDao.updateWorkflowInstance(instance); logger.debug("Finished."); }
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); } WorkflowInstance.Builder builder = new WorkflowInstance.Builder(instance) // .setNextActivation(execution.getNextActivation()) // .setStatus(getStatus(execution, definition.getState(execution.getNextState()))) // .setStateText(getStateText(instance, execution)) // .setState(execution.getNextState()) // .setRetries(execution.isRetry() ? execution.getRetries() + 1 : 0); if (execution.isStateProcessInvoked()) { actionBuilder.setExecutionEnd(now()).setType(getActionType(execution)).setStateText(execution.getNextStateReason()); if (execution.isFailed()) { workflowInstanceDao.updateWorkflowInstanceAfterExecution(builder.build(), actionBuilder.build(), Collections.<WorkflowInstance> emptyList(), Collections.<WorkflowInstance> emptyList(), true); } else { workflowInstanceDao.updateWorkflowInstanceAfterExecution(builder.build(), actionBuilder.build(), execution.getNewChildWorkflows(), execution.getNewWorkflows(), execution.createAction()); processSuccess(execution, instance); } } else { workflowInstanceDao.updateWorkflowInstance(builder.build()); } return builder.setOriginalStateVariables(instance.stateVariables).build(); }
private void rescheduleUnknownWorkflowType(WorkflowInstance instance) { logger.warn("Workflow type {} not configured to this nFlow instance - rescheduling workflow instance", instance.type); instance = new WorkflowInstance.Builder(instance).setNextActivation(now().plusMinutes(unknownWorkflowTypeRetryDelay)) .setStatus(inProgress).setStateText("Unsupported workflow type").build(); workflowInstanceDao.updateWorkflowInstance(instance); logger.debug("Finished."); }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { updateWorkflowInstance(instance); int parentActionId = insertWorkflowInstanceAction(action); insertVariables(action.workflowInstanceId, parentActionId, changedStateVariables); for (WorkflowInstance childTemplate : childWorkflows) { Integer rootWorkflowId = instance.rootWorkflowId == null ? instance.id : instance.rootWorkflowId; WorkflowInstance childWorkflow = new WorkflowInstance.Builder(childTemplate).setRootWorkflowId(rootWorkflowId) .setParentWorkflowId(instance.id).setParentActionId(parentActionId).build(); insertWorkflowInstance(childWorkflow); } for (WorkflowInstance workflow : workflows) { insertWorkflowInstance(workflow); } } });