Search in sources :

Example 1 with ContinueAsNewWorkflowExecutionDecisionAttributes

use of com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes 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 ContinueAsNewWorkflowExecutionDecisionAttributes

use of com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes in project cadence-client by uber-java.

the class TestWorkflowMutableStateImpl method startNewCronRun.

private void startNewCronRun(RequestContext ctx, long decisionTaskCompletedId, String identity, WorkflowData data, byte[] lastCompletionResult) throws InternalServiceError, BadRequestError {
    CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    CronParser parser = new CronParser(cronDefinition);
    Cron cron = parser.parse(data.cronSchedule);
    Instant i = Instant.ofEpochMilli(store.currentTimeMillis());
    ZonedDateTime now = ZonedDateTime.ofInstant(i, ZoneOffset.UTC);
    ExecutionTime executionTime = ExecutionTime.forCron(cron);
    Optional<Duration> backoff = executionTime.timeToNextExecution(now);
    int backoffIntervalSeconds = (int) backoff.get().getSeconds();
    if (backoffIntervalSeconds == 0) {
        backoff = executionTime.timeToNextExecution(now.plusSeconds(1));
        backoffIntervalSeconds = (int) backoff.get().getSeconds() + 1;
    }
    ContinueAsNewWorkflowExecutionDecisionAttributes continueAsNewAttr = new ContinueAsNewWorkflowExecutionDecisionAttributes().setInput(startRequest.getInput()).setWorkflowType(startRequest.getWorkflowType()).setExecutionStartToCloseTimeoutSeconds(startRequest.getExecutionStartToCloseTimeoutSeconds()).setTaskStartToCloseTimeoutSeconds(startRequest.getTaskStartToCloseTimeoutSeconds()).setTaskList(startRequest.getTaskList()).setBackoffStartIntervalInSeconds(backoffIntervalSeconds).setRetryPolicy(startRequest.getRetryPolicy()).setLastCompletionResult(lastCompletionResult);
    workflow.action(Action.CONTINUE_AS_NEW, ctx, continueAsNewAttr, decisionTaskCompletedId);
    HistoryEvent event = ctx.getEvents().get(ctx.getEvents().size() - 1);
    WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewEventAttributes = event.getWorkflowExecutionContinuedAsNewEventAttributes();
    String runId = service.continueAsNew(startRequest, continuedAsNewEventAttributes, Optional.empty(), identity, getExecutionId(), parent, parentChildInitiatedEventId);
    continuedAsNewEventAttributes.setNewExecutionRunId(runId);
}
Also used : Instant(java.time.Instant) CronDefinition(com.cronutils.model.definition.CronDefinition) Duration(java.time.Duration) HistoryEvent(com.uber.cadence.HistoryEvent) Cron(com.cronutils.model.Cron) ExecutionTime(com.cronutils.model.time.ExecutionTime) ContinueAsNewWorkflowExecutionDecisionAttributes(com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes) ZonedDateTime(java.time.ZonedDateTime) WorkflowExecutionContinuedAsNewEventAttributes(com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes) CronParser(com.cronutils.parser.CronParser)

Example 3 with ContinueAsNewWorkflowExecutionDecisionAttributes

use of com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes in project cadence-client by uber-java.

the class DecisionsHelper method continueAsNewWorkflowExecution.

void continueAsNewWorkflowExecution(ContinueAsNewWorkflowExecutionParameters continueParameters) {
    addAllMissingVersionMarker(false, Optional.empty());
    WorkflowExecutionStartedEventAttributes startedEvent = task.getHistory().getEvents().get(0).getWorkflowExecutionStartedEventAttributes();
    ContinueAsNewWorkflowExecutionDecisionAttributes attributes = new ContinueAsNewWorkflowExecutionDecisionAttributes();
    attributes.setInput(continueParameters.getInput());
    String workflowType = continueParameters.getWorkflowType();
    if (workflowType != null && !workflowType.isEmpty()) {
        attributes.setWorkflowType(new WorkflowType().setName(workflowType));
    } else {
        attributes.setWorkflowType(task.getWorkflowType());
    }
    int executionStartToClose = continueParameters.getExecutionStartToCloseTimeoutSeconds();
    if (executionStartToClose == 0) {
        executionStartToClose = startedEvent.getExecutionStartToCloseTimeoutSeconds();
    }
    attributes.setExecutionStartToCloseTimeoutSeconds(executionStartToClose);
    int taskStartToClose = continueParameters.getTaskStartToCloseTimeoutSeconds();
    if (taskStartToClose == 0) {
        taskStartToClose = startedEvent.getTaskStartToCloseTimeoutSeconds();
    }
    attributes.setTaskStartToCloseTimeoutSeconds(taskStartToClose);
    String taskList = continueParameters.getTaskList();
    if (taskList == null || taskList.isEmpty()) {
        taskList = startedEvent.getTaskList().getName();
    }
    TaskList tl = new TaskList();
    tl.setName(taskList);
    attributes.setTaskList(tl);
    attributes.setHeader(startedEvent.getHeader());
    Decision decision = new Decision();
    decision.setDecisionType(DecisionType.ContinueAsNewWorkflowExecution);
    decision.setContinueAsNewWorkflowExecutionDecisionAttributes(attributes);
    DecisionId decisionId = new DecisionId(DecisionTarget.SELF, 0);
    addDecision(decisionId, new CompleteWorkflowStateMachine(decisionId, decision));
}
Also used : ContinueAsNewWorkflowExecutionDecisionAttributes(com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes) WorkflowType(com.uber.cadence.WorkflowType) TaskList(com.uber.cadence.TaskList) ChildWorkflowExecutionStartedEventAttributes(com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes) WorkflowExecutionStartedEventAttributes(com.uber.cadence.WorkflowExecutionStartedEventAttributes) Decision(com.uber.cadence.Decision)

Aggregations

ContinueAsNewWorkflowExecutionDecisionAttributes (com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes)3 HistoryEvent (com.uber.cadence.HistoryEvent)2 WorkflowExecutionContinuedAsNewEventAttributes (com.uber.cadence.WorkflowExecutionContinuedAsNewEventAttributes)2 Cron (com.cronutils.model.Cron)1 CronDefinition (com.cronutils.model.definition.CronDefinition)1 ExecutionTime (com.cronutils.model.time.ExecutionTime)1 CronParser (com.cronutils.parser.CronParser)1 BadRequestError (com.uber.cadence.BadRequestError)1 ChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.ChildWorkflowExecutionFailedEventAttributes)1 ChildWorkflowExecutionStartedEventAttributes (com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes)1 Decision (com.uber.cadence.Decision)1 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 InternalServiceError (com.uber.cadence.InternalServiceError)1 StartChildWorkflowExecutionFailedEventAttributes (com.uber.cadence.StartChildWorkflowExecutionFailedEventAttributes)1 TaskList (com.uber.cadence.TaskList)1 WorkflowExecutionAlreadyCompletedError (com.uber.cadence.WorkflowExecutionAlreadyCompletedError)1 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)1 WorkflowType (com.uber.cadence.WorkflowType)1 ChildWorkflowData (com.uber.cadence.internal.testservice.StateMachines.ChildWorkflowData)1 WorkflowData (com.uber.cadence.internal.testservice.StateMachines.WorkflowData)1