@Override
public Promise<String> scheduleActivityTask(final ExecuteActivityParameters parameters) {
final OpenRequestInfo<String, ActivityType> context = new OpenRequestInfo<String, ActivityType>(
parameters.getActivityType());
final ScheduleActivityTaskDecisionAttributes attributes = new ScheduleActivityTaskDecisionAttributes();
attributes.setActivityType(parameters.getActivityType());
attributes.setInput(parameters.getInput());
attributes.setHeartbeatTimeout(FlowHelpers.secondsToDuration(parameters.getHeartbeatTimeoutSeconds()));
attributes.setScheduleToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getScheduleToCloseTimeoutSeconds()));
attributes.setScheduleToStartTimeout(FlowHelpers.secondsToDuration(parameters.getScheduleToStartTimeoutSeconds()));
attributes.setStartToCloseTimeout(FlowHelpers.secondsToDuration(parameters.getStartToCloseTimeoutSeconds()));
String activityId = parameters.getActivityId();
if (activityId == null) {
activityId = String.valueOf(decisions.getNextId());
}
attributes.setActivityId(activityId);
String taskList = parameters.getTaskList();
if (taskList != null && !taskList.isEmpty()) {
attributes.setTaskList(new TaskList().withName(taskList));
}
String taskName = "activityId=" + activityId + ", activityType=" + attributes.getActivityType();
new ExternalTask() {
@Override
protected ExternalTaskCancellationHandler doExecute(final ExternalTaskCompletionHandle handle) throws Throwable {
decisions.scheduleActivityTask(attributes);
context.setCompletionHandle(handle);
scheduledActivities.put(attributes.getActivityId(), context);
return new ActivityCancellationHandler(attributes.getActivityId(), handle);
}
}.setName(taskName);
context.setResultDescription("scheduleActivityTask " + taskName);
return context.getResult();
}