Search in sources :

Example 1 with WorkflowData

use of com.uber.cadence.internal.testservice.StateMachines.WorkflowData in project cadence-client by uber-java.

the class TestWorkflowMutableStateImpl method processFailWorkflowExecution.

private void processFailWorkflowExecution(RequestContext ctx, FailWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) throws InternalServiceError, BadRequestError {
    WorkflowData data = workflow.getData();
    if (data.retryState.isPresent()) {
        RetryState rs = data.retryState.get();
        int backoffIntervalSeconds = rs.getBackoffIntervalInSeconds(d.getReason(), store.currentTimeMillis());
        if (backoffIntervalSeconds > 0) {
            ContinueAsNewWorkflowExecutionDecisionAttributes continueAsNewAttr = new ContinueAsNewWorkflowExecutionDecisionAttributes().setInput(startRequest.getInput()).setWorkflowType(startRequest.getWorkflowType()).setExecutionStartToCloseTimeoutSeconds(startRequest.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(startRequest.getTaskStartToCloseTimeoutSeconds()).setTaskList(startRequest.getTaskList()).setBackoffStartIntervalInSeconds(backoffIntervalSeconds).setRetryPolicy(startRequest.getRetryPolicy());
            workflow.action(Action.CONTINUE_AS_NEW, ctx, continueAsNewAttr, decisionTaskCompletedId);
            HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1);
            WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewEventAttributes = event.getWorkflowExecutionContinuedAsNewEventAttributes();
            Optional<RetryState> continuedRetryState = Optional.of(rs.getNextAttempt());
            String runId = service.continueAsNew(startRequest, continuedAsNewEventAttributes, continuedRetryState, identity, getExecutionId(), parent, parentChildInitiatedEventId);
            continuedAsNewEventAttributes.setNewExecutionRunId(runId);
            return;
        }
    }
    if (!Strings.isNullOrEmpty(data.cronSchedule)) {
        startNewCronRun(ctx, decisionTaskCompletedId, identity, data, data.lastCompletionResult);
        return;
    }
    workflow.action(StateMachines.Action.FAIL, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionFailedEventAttributes a = new ChildWorkflowExecutionFailedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setDetails(d.getDetails()).setReason(d.getReason()).setWorkflowType(startRequest.getWorkflowType()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowFailed(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) HistoryEvent(com.uber.cadence.HistoryEvent) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowData(com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData) WorkflowData(com.uber.cadence.internal.testservice.StateMachines.WorkflowData) ContinueAsNewWorkflowExecutionDecisionAttributes(com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes) StartChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes) ChildWorkflowExecutionFailedEventAttributes(com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)

Example 2 with WorkflowData

use of com.uber.cadence.internal.testservice.StateMachines.WorkflowData in project cadence-client by uber-java.

the class TestWorkflowMutableStateImpl method processCompleteWorkflowExecution.

private void processCompleteWorkflowExecution(RequestContext ctx, CompleteWorkflowExecutionDecisionAttributes d, long decisionTaskCompletedId, String identity) throws InternalServiceError, BadRequestError {
    WorkflowData data = workflow.getData();
    if (!Strings.isNullOrEmpty(data.cronSchedule)) {
        startNewCronRun(ctx, decisionTaskCompletedId, identity, data, d.getResult());
        return;
    }
    workflow.action(StateMachines.Action.COMPLETE, ctx, d, decisionTaskCompletedId);
    if (parent.isPresent()) {
        // unlocked by the parent
        ctx.lockTimer();
        ChildWorkflowExecutionCompletedEventAttributes a = new ChildWorkflowExecutionCompletedEventAttributes().setInitiatedEventId(parentChildInitiatedEventId.getAsLong()).setResult(d.getResult()).setDomain(ctx.getDomain()).setWorkflowExecution(ctx.getExecution()).setWorkflowType(startRequest.getWorkflowType());
        ForkJoinPool.commonPool().execute(() -> {
            try {
                parent.get().childWorkflowCompleted(ctx.getExecutionId().getWorkflowId().getWorkflowId(), a);
            } catch (EntityNotExistsError | WorkflowExecutionAlreadyCompletedError e) {
            // Parent might already close
            } catch (BadRequestError | InternalServiceError e) {
                log.error("Failure reporting child completion", e);
            }
        });
    }
}
Also used : InternalServiceError(com.uber.cadence.InternalServiceError) ChildWorkflowExecutionCompletedEventAttributes(com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) WorkflowExecutionAlreadyCompletedError(com.uber.cadence.WorkflowExecutionAlreadyCompletedError) BadRequestError(com.uber.cadence.BadRequestError) ChildWorkflowData(com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData) WorkflowData(com.uber.cadence.internal.testservice.StateMachines.WorkflowData)

Aggregations

BadRequestError (com.uber.cadence.BadRequestError)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)2 InternalServiceError (com.uber.cadence.InternalServiceError)2 WorkflowExecutionAlreadyCompletedError (com.uber.cadence.WorkflowExecutionAlreadyCompletedError)2 ChildWorkflowData (com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData)2 WorkflowData (com.uber.cadence.internal.testservice.StateMachines.WorkflowData)2 ChildWorkflowExecutionCompletedEventAttributes (com.uber.cadence.ChildWorkflowExecutionCompletedEventAttributes)1 ChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes)1 ContinueAsNewWorkflowExecutionDecisionAttributes (com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes)1 HistoryEvent (com.uber.cadence.HistoryEvent)1 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)1 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)1