in flux/src/main/java/software/amazon/aws/clients/swf/flux/FluxCapacitorImpl.java [172:222]
public WorkflowStatusChecker executeWorkflow(Class<? extends Workflow> workflowType, String workflowId,
Map<String, Object> workflowInput) {
if (workflowsByName.isEmpty()) {
throw new WorkflowExecutionException("Flux has not yet been initialized, please call the initialize method first.");
}
String workflowName = TaskNaming.workflowName(workflowType);
if (!workflowsByName.containsKey(workflowName)) {
throw new WorkflowExecutionException("Cannot execute a workflow that was not provided to Flux at initialization: "
+ workflowName);
}
Workflow workflow = workflowsByName.get(workflowName);
// nextInt generates a number between 0 (inclusive) and bucketCount (exclusive).
// We want a number between 1 (inclusive) and bucketCount (inclusive), so we can just add one to the result.
int bucket = 1 + RANDOM.nextInt(config.getTaskListConfig(workflow.taskList()).getBucketCount());
String taskList = synthesizeBucketedTaskListName(workflow.taskList(), bucket);
StartWorkflowExecutionRequest request = buildStartWorkflowRequest(workflowDomain, workflowName, workflowId,
taskList, workflow.maxStartToCloseDuration(),
workflowInput);
log.debug("Requesting new workflow execution for workflow {} with id {}", workflowName, workflowId);
try {
StartWorkflowExecutionResponse response = swf.startWorkflowExecution(request);
log.debug("Started workflow {} with id {}: received execution id {}.", workflowName, workflowId, response.runId());
return new WorkflowStatusCheckerImpl(swf, workflowDomain, workflowId, response.runId());
} catch (WorkflowExecutionAlreadyStartedException e) {
log.debug("Attempted to start workflow {} with id {} but it was already started.", workflowName, workflowId, e);
// swallow, we're ok with this happening
// TODO -- figure out how to find the run id so we can return a useful WorkflowStatusChecker
return new WorkflowStatusChecker() {
@Override
public WorkflowStatus checkStatus() {
return WorkflowStatus.UNKNOWN;
}
public SwfClient getSwfClient() {
return swf;
}
};
} catch (Exception e) {
String message = String.format("Got exception attempting to start workflow %s with id %s",
workflowName, workflowId);
log.debug(message, e);
throw new WorkflowExecutionException(message, e);
}
}