use of com.uber.cadence.TaskList in project cadence-client by uber-java.
the class WorkflowDecisionContext method startChildWorkflow.
Consumer<Exception> startChildWorkflow(StartChildWorkflowExecutionParameters parameters, Consumer<WorkflowExecution> executionCallback, BiConsumer<byte[], Exception> callback) {
final StartChildWorkflowExecutionDecisionAttributes attributes = new StartChildWorkflowExecutionDecisionAttributes();
attributes.setWorkflowType(parameters.getWorkflowType());
String workflowId = parameters.getWorkflowId();
if (workflowId == null) {
workflowId = generateUniqueId();
}
attributes.setWorkflowId(workflowId);
if (parameters.getDomain() == null) {
// Could be removed as soon as server allows null for domain.
attributes.setDomain(workflowContext.getDomain());
} else {
attributes.setDomain(parameters.getDomain());
}
attributes.setInput(parameters.getInput());
if (parameters.getExecutionStartToCloseTimeoutSeconds() == 0) {
// TODO: Substract time passed since the parent start
attributes.setExecutionStartToCloseTimeoutSeconds(workflowContext.getExecutionStartToCloseTimeoutSeconds());
} else {
attributes.setExecutionStartToCloseTimeoutSeconds((int) parameters.getExecutionStartToCloseTimeoutSeconds());
}
if (parameters.getTaskStartToCloseTimeoutSeconds() == 0) {
attributes.setTaskStartToCloseTimeoutSeconds(workflowContext.getDecisionTaskTimeoutSeconds());
} else {
attributes.setTaskStartToCloseTimeoutSeconds((int) parameters.getTaskStartToCloseTimeoutSeconds());
}
if (parameters.getChildPolicy() == null) {
// TODO: Child policy from a parent as soon as it is available in the WorkflowExecutionStarted event
// Or when server accepts null
// attributes.setChildPolicy(workflowContext.getChildPolicy());
attributes.setChildPolicy(ChildPolicy.TERMINATE);
} else {
attributes.setChildPolicy(parameters.getChildPolicy());
}
String taskList = parameters.getTaskList();
TaskList tl = new TaskList();
if (taskList != null && !taskList.isEmpty()) {
tl.setName(taskList);
} else {
tl.setName(workflowContext.getTaskList());
}
attributes.setTaskList(tl);
attributes.setWorkflowIdReusePolicy(parameters.getWorkflowIdReusePolicy());
decisions.startChildWorkflowExecution(attributes);
final OpenChildWorkflowRequestInfo context = new OpenChildWorkflowRequestInfo(executionCallback);
context.setCompletionHandle(callback);
scheduledExternalWorkflows.put(attributes.getWorkflowId(), context);
return new ChildWorkflowCancellationHandler(attributes.getWorkflowId(), callback);
}
use of com.uber.cadence.TaskList in project cadence-client by uber-java.
the class DecisionsHelper method continueAsNewWorkflowExecution.
void continueAsNewWorkflowExecution(ContinueAsNewWorkflowExecutionParameters continueParameters) {
WorkflowExecutionStartedEventAttributes startedEvent = task.getHistory().getEvents().get(0).getWorkflowExecutionStartedEventAttributes();
ContinueAsNewWorkflowExecutionDecisionAttributes attributes = new ContinueAsNewWorkflowExecutionDecisionAttributes();
attributes.setWorkflowType(task.getWorkflowType());
attributes.setInput(continueParameters.getInput());
int executionStartToClose = continueParameters.getExecutionStartToCloseTimeoutSeconds();
if (executionStartToClose == 0) {
executionStartToClose = startedEvent.getExecutionStartToCloseTimeoutSeconds();
}
attributes.setExecutionStartToCloseTimeoutSeconds(executionStartToClose);
int taskStartToClose = continueParameters.getTaskStartToCloseTimeoutSeconds();
if (taskStartToClose == 0) {
taskStartToClose = startedEvent.getTaskStartToCloseTimeoutSeconds();
}
attributes.setTaskStartToCloseTimeoutSeconds(taskStartToClose);
String taskList = continueParameters.getTaskList();
if (taskList == null || taskList.isEmpty()) {
taskList = startedEvent.getTaskList().getName();
}
TaskList tl = new TaskList();
tl.setName(taskList);
attributes.setTaskList(tl);
Decision decision = new Decision();
decision.setDecisionType(DecisionType.ContinueAsNewWorkflowExecution);
decision.setContinueAsNewWorkflowExecutionDecisionAttributes(attributes);
DecisionId decisionId = new DecisionId(DecisionTarget.SELF, null);
addDecision(decisionId, new CompleteWorkflowStateMachine(decisionId, decision));
}
use of com.uber.cadence.TaskList in project cadence-client by uber-java.
the class GenericWorkflowClientExternalImpl method startWorkflow.
@Override
public WorkflowExecution startWorkflow(StartWorkflowExecutionParameters startParameters) throws WorkflowExecutionAlreadyStartedError {
StartWorkflowExecutionRequest request = new StartWorkflowExecutionRequest();
request.setDomain(domain);
request.setInput(startParameters.getInput());
request.setExecutionStartToCloseTimeoutSeconds((int) startParameters.getExecutionStartToCloseTimeoutSeconds());
request.setTaskStartToCloseTimeoutSeconds((int) startParameters.getTaskStartToCloseTimeoutSeconds());
request.setWorkflowIdReusePolicy(startParameters.getWorkflowIdReusePolicy());
String taskList = startParameters.getTaskList();
if (taskList != null && !taskList.isEmpty()) {
TaskList tl = new TaskList();
tl.setName(taskList);
request.setTaskList(tl);
}
String workflowId = startParameters.getWorkflowId();
if (workflowId == null) {
workflowId = UUID.randomUUID().toString();
}
request.setWorkflowId(workflowId);
request.setWorkflowType(startParameters.getWorkflowType());
// if(startParameters.getChildPolicy() != null) {
// request.setChildPolicy(startParameters.getChildPolicy());
// }
StartWorkflowExecutionResponse result;
try {
result = service.StartWorkflowExecution(request);
} catch (WorkflowExecutionAlreadyStartedError e) {
throw e;
} catch (TException e) {
throw CheckedExceptionWrapper.wrap(e);
}
WorkflowExecution execution = new WorkflowExecution();
execution.setRunId(result.getRunId());
execution.setWorkflowId(request.getWorkflowId());
return execution;
}
use of com.uber.cadence.TaskList 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);
}
Aggregations