Search in sources :

Example 1 with ActivityTaskData

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

the class TestWorkflowMutableStateImpl method startActivityTask.

@Override
public void startActivityTask(PollForActivityTaskResponse task, PollForActivityTaskRequest pollRequest) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    update(ctx -> {
        String activityId = task.getActivityId();
        StateMachine<ActivityTaskData> activity = getActivity(activityId);
        activity.action(StateMachines.Action.START, ctx, pollRequest, 0);
        ActivityTaskData data = activity.getData();
        int startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeoutSeconds();
        int heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeoutSeconds();
        if (startToCloseTimeout > 0) {
            ctx.addTimer(startToCloseTimeout, () -> timeoutActivity(activityId, TimeoutType.START_TO_CLOSE));
        }
        updateHeartbeatTimer(ctx, activityId, activity, startToCloseTimeout, heartbeatTimeout);
    });
}
Also used : ActivityTaskData(com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData)

Example 2 with ActivityTaskData

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

the class TestWorkflowMutableStateImpl method heartbeatActivityTask.

@Override
public RecordActivityTaskHeartbeatResponse heartbeatActivityTask(String activityId, RecordActivityTaskHeartbeatRequest request) throws InternalServiceError, EntityNotExistsError, BadRequestError {
    RecordActivityTaskHeartbeatResponse result = new RecordActivityTaskHeartbeatResponse();
    try {
        update(ctx -> {
            StateMachine<ActivityTaskData> activity = getActivity(activityId);
            activity.action(StateMachines.Action.UPDATE, ctx, request, 0);
            if (activity.getState() == StateMachines.State.CANCELLATION_REQUESTED) {
                result.setCancelRequested(true);
            }
            ActivityTaskData data = activity.getData();
            data.lastHeartbeatTime = clock.getAsLong();
            int startToCloseTimeout = data.scheduledEvent.getStartToCloseTimeoutSeconds();
            int heartbeatTimeout = data.scheduledEvent.getHeartbeatTimeoutSeconds();
            updateHeartbeatTimer(ctx, activityId, activity, startToCloseTimeout, heartbeatTimeout);
        });
    } catch (InternalServiceError | EntityNotExistsError e) {
        throw e;
    } catch (Exception e) {
        throw new InternalServiceError(Throwables.getStackTraceAsString(e));
    }
    return result;
}
Also used : RecordActivityTaskHeartbeatResponse(com.uber.cadence.RecordActivityTaskHeartbeatResponse) InternalServiceError(com.uber.cadence.InternalServiceError) EntityNotExistsError(com.uber.cadence.EntityNotExistsError) ActivityTaskData(com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ActivityTaskData (com.uber.cadence.internal.testservice.StateMachines.ActivityTaskData)2 EntityNotExistsError (com.uber.cadence.EntityNotExistsError)1 InternalServiceError (com.uber.cadence.InternalServiceError)1 RecordActivityTaskHeartbeatResponse (com.uber.cadence.RecordActivityTaskHeartbeatResponse)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TException (org.apache.thrift.TException)1