Search in sources :

Example 1 with ActivityType

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

the class ActivityDecisionContext method handleActivityTaskTimedOut.

void handleActivityTaskTimedOut(HistoryEvent event) {
    ActivityTaskTimedOutEventAttributes attributes = event.getActivityTaskTimedOutEventAttributes();
    String activityId = decisions.getActivityId(attributes);
    if (decisions.handleActivityTaskClosed(activityId)) {
        OpenRequestInfo<byte[], ActivityType> scheduled = scheduledActivities.remove(activityId);
        if (scheduled != null) {
            TimeoutType timeoutType = attributes.getTimeoutType();
            byte[] details = attributes.getDetails();
            ActivityTaskTimeoutException failure = new ActivityTaskTimeoutException(event.getEventId(), scheduled.getUserContext(), activityId, timeoutType, details);
            BiConsumer<byte[], Exception> completionHandle = scheduled.getCompletionCallback();
            completionHandle.accept(null, failure);
        }
    }
}
Also used : ActivityTaskTimedOutEventAttributes(com.uber.cadence.ActivityTaskTimedOutEventAttributes) TimeoutType(com.uber.cadence.TimeoutType) ActivityType(com.uber.cadence.ActivityType) CancellationException(java.util.concurrent.CancellationException)

Example 2 with ActivityType

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

the class SyncDecisionContext method executeActivityOnce.

private Promise<byte[]> executeActivityOnce(String name, ActivityOptions options, byte[] input) {
    CompletablePromise<byte[]> result = Workflow.newPromise();
    ExecuteActivityParameters parameters = new ExecuteActivityParameters();
    // TODO: Real task list
    String taskList = options.getTaskList();
    if (taskList == null) {
        taskList = context.getTaskList();
    }
    parameters.withActivityType(new ActivityType().setName(name)).withInput(input).withTaskList(taskList).withScheduleToStartTimeoutSeconds(options.getScheduleToStartTimeout().getSeconds()).withStartToCloseTimeoutSeconds(options.getStartToCloseTimeout().getSeconds()).withScheduleToCloseTimeoutSeconds(options.getScheduleToCloseTimeout().getSeconds()).setHeartbeatTimeoutSeconds(options.getHeartbeatTimeout().getSeconds());
    Consumer<Exception> cancellationCallback = context.scheduleActivityTask(parameters, (output, failure) -> {
        if (failure != null) {
            runner.executeInWorkflowThread("activity failure callback", () -> result.completeExceptionally(mapActivityException(failure)));
        } else {
            runner.executeInWorkflowThread("activity completion callback", () -> result.complete(output));
        }
    });
    CancellationScope.current().getCancellationRequest().thenApply((reason) -> {
        cancellationCallback.accept(new CancellationException(reason));
        return null;
    });
    return result;
}
Also used : ExecuteActivityParameters(com.uber.cadence.internal.replay.ExecuteActivityParameters) CancellationException(java.util.concurrent.CancellationException) ActivityType(com.uber.cadence.ActivityType) ActivityTimeoutException(com.uber.cadence.workflow.ActivityTimeoutException) ChildWorkflowTaskFailedException(com.uber.cadence.internal.replay.ChildWorkflowTaskFailedException) ActivityTaskTimeoutException(com.uber.cadence.internal.replay.ActivityTaskTimeoutException) ActivityTaskFailedException(com.uber.cadence.internal.replay.ActivityTaskFailedException) ChildWorkflowFailureException(com.uber.cadence.workflow.ChildWorkflowFailureException) CancellationException(java.util.concurrent.CancellationException) ChildWorkflowException(com.uber.cadence.workflow.ChildWorkflowException) ActivityFailureException(com.uber.cadence.workflow.ActivityFailureException) SignalExternalWorkflowException(com.uber.cadence.workflow.SignalExternalWorkflowException) ActivityException(com.uber.cadence.workflow.ActivityException)

Example 3 with ActivityType

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

the class ActivityDecisionContext method scheduleActivityTask.

Consumer<Exception> scheduleActivityTask(ExecuteActivityParameters parameters, BiConsumer<byte[], Exception> callback) {
    final OpenRequestInfo<byte[], ActivityType> context = new OpenRequestInfo<>(parameters.getActivityType());
    final ScheduleActivityTaskDecisionAttributes attributes = new ScheduleActivityTaskDecisionAttributes();
    attributes.setActivityType(parameters.getActivityType());
    attributes.setInput(parameters.getInput());
    if (parameters.getHeartbeatTimeoutSeconds() > 0) {
        attributes.setHeartbeatTimeoutSeconds((int) parameters.getHeartbeatTimeoutSeconds());
    }
    attributes.setScheduleToCloseTimeoutSeconds((int) parameters.getScheduleToCloseTimeoutSeconds());
    attributes.setScheduleToStartTimeoutSeconds((int) parameters.getScheduleToStartTimeoutSeconds());
    attributes.setStartToCloseTimeoutSeconds((int) parameters.getStartToCloseTimeoutSeconds());
    // attributes.setTaskPriority(InternalUtils.taskPriorityToString(parameters.getTaskPriority()));
    String activityId = parameters.getActivityId();
    if (activityId == null) {
        activityId = String.valueOf(decisions.getNextId());
    }
    attributes.setActivityId(activityId);
    String taskList = parameters.getTaskList();
    if (taskList != null && !taskList.isEmpty()) {
        TaskList tl = new TaskList();
        tl.setName(taskList);
        attributes.setTaskList(tl);
    }
    decisions.scheduleActivityTask(attributes);
    context.setCompletionHandle(callback);
    scheduledActivities.put(attributes.getActivityId(), context);
    return new ActivityDecisionContext.ActivityCancellationHandler(attributes.getActivityId(), callback);
}
Also used : TaskList(com.uber.cadence.TaskList) ActivityType(com.uber.cadence.ActivityType) ScheduleActivityTaskDecisionAttributes(com.uber.cadence.ScheduleActivityTaskDecisionAttributes)

Example 4 with ActivityType

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

the class ActivityDecisionContext method handleActivityTaskFailed.

void handleActivityTaskFailed(HistoryEvent event) {
    ActivityTaskFailedEventAttributes attributes = event.getActivityTaskFailedEventAttributes();
    String activityId = decisions.getActivityId(attributes);
    if (decisions.handleActivityTaskClosed(activityId)) {
        OpenRequestInfo<byte[], ActivityType> scheduled = scheduledActivities.remove(activityId);
        if (scheduled != null) {
            String reason = attributes.getReason();
            byte[] details = attributes.getDetails();
            ActivityTaskFailedException failure = new ActivityTaskFailedException(event.getEventId(), scheduled.getUserContext(), activityId, reason, details);
            BiConsumer<byte[], Exception> completionHandle = scheduled.getCompletionCallback();
            completionHandle.accept(null, failure);
        }
    }
}
Also used : ActivityTaskFailedEventAttributes(com.uber.cadence.ActivityTaskFailedEventAttributes) ActivityType(com.uber.cadence.ActivityType) CancellationException(java.util.concurrent.CancellationException)

Example 5 with ActivityType

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

the class ActivityDecisionContext method handleActivityTaskCompleted.

void handleActivityTaskCompleted(HistoryEvent event) {
    ActivityTaskCompletedEventAttributes attributes = event.getActivityTaskCompletedEventAttributes();
    String activityId = decisions.getActivityId(attributes);
    if (decisions.handleActivityTaskClosed(activityId)) {
        OpenRequestInfo<byte[], ActivityType> scheduled = scheduledActivities.remove(activityId);
        if (scheduled != null) {
            byte[] result = attributes.getResult();
            BiConsumer<byte[], Exception> completionHandle = scheduled.getCompletionCallback();
            completionHandle.accept(result, null);
        }
    }
}
Also used : ActivityTaskCompletedEventAttributes(com.uber.cadence.ActivityTaskCompletedEventAttributes) ActivityType(com.uber.cadence.ActivityType) CancellationException(java.util.concurrent.CancellationException)

Aggregations

ActivityType (com.uber.cadence.ActivityType)6 CancellationException (java.util.concurrent.CancellationException)5 ActivityTaskCanceledEventAttributes (com.uber.cadence.ActivityTaskCanceledEventAttributes)1 ActivityTaskCompletedEventAttributes (com.uber.cadence.ActivityTaskCompletedEventAttributes)1 ActivityTaskFailedEventAttributes (com.uber.cadence.ActivityTaskFailedEventAttributes)1 ActivityTaskTimedOutEventAttributes (com.uber.cadence.ActivityTaskTimedOutEventAttributes)1 ScheduleActivityTaskDecisionAttributes (com.uber.cadence.ScheduleActivityTaskDecisionAttributes)1 TaskList (com.uber.cadence.TaskList)1 TimeoutType (com.uber.cadence.TimeoutType)1 ActivityTaskFailedException (com.uber.cadence.internal.replay.ActivityTaskFailedException)1 ActivityTaskTimeoutException (com.uber.cadence.internal.replay.ActivityTaskTimeoutException)1 ChildWorkflowTaskFailedException (com.uber.cadence.internal.replay.ChildWorkflowTaskFailedException)1 ExecuteActivityParameters (com.uber.cadence.internal.replay.ExecuteActivityParameters)1 ActivityException (com.uber.cadence.workflow.ActivityException)1 ActivityFailureException (com.uber.cadence.workflow.ActivityFailureException)1 ActivityTimeoutException (com.uber.cadence.workflow.ActivityTimeoutException)1 ChildWorkflowException (com.uber.cadence.workflow.ChildWorkflowException)1 ChildWorkflowFailureException (com.uber.cadence.workflow.ChildWorkflowFailureException)1 SignalExternalWorkflowException (com.uber.cadence.workflow.SignalExternalWorkflowException)1