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);
}
}
}
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;
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations