Search in sources :

Example 1 with Decision

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

the class ActivityDecisionStateMachine method createRequestCancelActivityTaskDecision.

private Decision createRequestCancelActivityTaskDecision() {
    RequestCancelActivityTaskDecisionAttributes tryCancel = new RequestCancelActivityTaskDecisionAttributes();
    tryCancel.setActivityId(scheduleAttributes.getActivityId());
    Decision decision = new Decision();
    decision.setRequestCancelActivityTaskDecisionAttributes(tryCancel);
    decision.setDecisionType(DecisionType.RequestCancelActivityTask);
    return decision;
}
Also used : RequestCancelActivityTaskDecisionAttributes(com.uber.cadence.RequestCancelActivityTaskDecisionAttributes) Decision(com.uber.cadence.Decision)

Example 2 with Decision

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

the class ActivityDecisionStateMachine method createScheduleActivityTaskDecision.

private Decision createScheduleActivityTaskDecision() {
    Decision decision = new Decision();
    decision.setScheduleActivityTaskDecisionAttributes(scheduleAttributes);
    decision.setDecisionType(DecisionType.ScheduleActivityTask);
    return decision;
}
Also used : Decision(com.uber.cadence.Decision)

Example 3 with Decision

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

the class ReplayDecisionTaskHandler method handleDecisionTaskImpl.

private Result handleDecisionTaskImpl(DecisionTaskWithHistoryIterator decisionTaskIterator) throws Throwable {
    HistoryHelper historyHelper = new HistoryHelper(decisionTaskIterator);
    ReplayDecider decider = createDecider(historyHelper);
    PollForDecisionTaskResponse decisionTask = historyHelper.getDecisionTask();
    if (decisionTask.isSetQuery()) {
        RespondQueryTaskCompletedRequest queryCompletedRequest = new RespondQueryTaskCompletedRequest();
        queryCompletedRequest.setTaskToken(decisionTask.getTaskToken());
        try {
            byte[] queryResult = decider.query(decisionTask.getQuery());
            queryCompletedRequest.setQueryResult(queryResult);
            queryCompletedRequest.setCompletedType(QueryTaskCompletedType.COMPLETED);
        } catch (Throwable e) {
            // TODO: Appropriate exception serialization.
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            queryCompletedRequest.setErrorMessage(sw.toString());
            queryCompletedRequest.setCompletedType(QueryTaskCompletedType.FAILED);
        }
        return new DecisionTaskHandler.Result(null, null, queryCompletedRequest, null);
    } else {
        decider.decide();
        DecisionsHelper decisionsHelper = decider.getDecisionsHelper();
        List<Decision> decisions = decisionsHelper.getDecisions();
        byte[] context = decisionsHelper.getWorkflowContextDataToReturn();
        if (log.isTraceEnabled()) {
            WorkflowExecution execution = decisionTask.getWorkflowExecution();
            log.trace("WorkflowTask startedEventId=" + decisionTask.getStartedEventId() + ", WorkflowID=" + execution.getWorkflowId() + ", RunID=" + execution.getRunId() + " completed with " + WorkflowExecutionUtils.prettyPrintDecisions(decisions));
        } else if (log.isDebugEnabled()) {
            WorkflowExecution execution = decisionTask.getWorkflowExecution();
            log.debug("WorkflowTask startedEventId=" + decisionTask.getStartedEventId() + ", WorkflowID=" + execution.getWorkflowId() + ", RunID=" + execution.getRunId() + " completed with " + decisions.size() + " new decisions");
        }
        RespondDecisionTaskCompletedRequest completedRequest = new RespondDecisionTaskCompletedRequest();
        completedRequest.setTaskToken(decisionTask.getTaskToken());
        completedRequest.setDecisions(decisions);
        completedRequest.setExecutionContext(context);
        return new DecisionTaskHandler.Result(completedRequest, null, null, null);
    }
}
Also used : PollForDecisionTaskResponse(com.uber.cadence.PollForDecisionTaskResponse) Decision(com.uber.cadence.Decision) StringWriter(java.io.StringWriter) RespondQueryTaskCompletedRequest(com.uber.cadence.RespondQueryTaskCompletedRequest) WorkflowExecution(com.uber.cadence.WorkflowExecution) RespondDecisionTaskCompletedRequest(com.uber.cadence.RespondDecisionTaskCompletedRequest) PrintWriter(java.io.PrintWriter)

Example 4 with Decision

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

the class TimerDecisionStateMachine method createCancelTimerDecision.

private Decision createCancelTimerDecision() {
    CancelTimerDecisionAttributes tryCancel = new CancelTimerDecisionAttributes();
    tryCancel.setTimerId(attributes.getTimerId());
    Decision decision = new Decision();
    decision.setCancelTimerDecisionAttributes(tryCancel);
    decision.setDecisionType(DecisionType.CancelTimer);
    return decision;
}
Also used : CancelTimerDecisionAttributes(com.uber.cadence.CancelTimerDecisionAttributes) Decision(com.uber.cadence.Decision)

Example 5 with Decision

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

the class ChildWorkflowDecisionStateMachine method createStartChildWorkflowExecutionDecision.

private Decision createStartChildWorkflowExecutionDecision() {
    Decision decision = new Decision();
    decision.setStartChildWorkflowExecutionDecisionAttributes(startAttributes);
    decision.setDecisionType(DecisionType.StartChildWorkflowExecution);
    return decision;
}
Also used : Decision(com.uber.cadence.Decision)

Aggregations

Decision (com.uber.cadence.Decision)15 BadRequestError (com.uber.cadence.BadRequestError)1 CancelTimerDecisionAttributes (com.uber.cadence.CancelTimerDecisionAttributes)1 CancelWorkflowExecutionDecisionAttributes (com.uber.cadence.CancelWorkflowExecutionDecisionAttributes)1 ChildWorkflowExecutionStartedEventAttributes (com.uber.cadence.ChildWorkflowExecutionStartedEventAttributes)1 CompleteWorkflowExecutionDecisionAttributes (com.uber.cadence.CompleteWorkflowExecutionDecisionAttributes)1 ContinueAsNewWorkflowExecutionDecisionAttributes (com.uber.cadence.ContinueAsNewWorkflowExecutionDecisionAttributes)1 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 FailWorkflowExecutionDecisionAttributes (com.uber.cadence.FailWorkflowExecutionDecisionAttributes)1 InternalServiceError (com.uber.cadence.InternalServiceError)1 PollForDecisionTaskResponse (com.uber.cadence.PollForDecisionTaskResponse)1 RequestCancelActivityTaskDecisionAttributes (com.uber.cadence.RequestCancelActivityTaskDecisionAttributes)1 RequestCancelExternalWorkflowExecutionDecisionAttributes (com.uber.cadence.RequestCancelExternalWorkflowExecutionDecisionAttributes)1 RespondDecisionTaskCompletedRequest (com.uber.cadence.RespondDecisionTaskCompletedRequest)1 RespondDecisionTaskFailedRequest (com.uber.cadence.RespondDecisionTaskFailedRequest)1 RespondQueryTaskCompletedRequest (com.uber.cadence.RespondQueryTaskCompletedRequest)1 StartTimerDecisionAttributes (com.uber.cadence.StartTimerDecisionAttributes)1 TaskList (com.uber.cadence.TaskList)1 WorkflowExecution (com.uber.cadence.WorkflowExecution)1 WorkflowExecutionStartedEventAttributes (com.uber.cadence.WorkflowExecutionStartedEventAttributes)1