use of com.uber.cadence.WorkflowType in project cadence-client by uber-java.
the class ReplayDecisionTaskHandler method createDecider.
private ReplayDecider createDecider(HistoryHelper historyHelper) throws Exception {
PollForDecisionTaskResponse decisionTask = historyHelper.getDecisionTask();
WorkflowType workflowType = decisionTask.getWorkflowType();
DecisionsHelper decisionsHelper = new DecisionsHelper(decisionTask);
ReplayWorkflow workflow = workflowFactory.getWorkflow(workflowType);
return new ReplayDecider(domain, workflow, historyHelper, decisionsHelper);
}
use of com.uber.cadence.WorkflowType in project cadence-client by uber-java.
the class SyncWorkflow method start.
@Override
public void start(HistoryEvent event, DecisionContext context) {
WorkflowType workflowType = event.getWorkflowExecutionStartedEventAttributes().getWorkflowType();
if (workflow == null) {
throw new IllegalArgumentException("Unknown workflow type: " + workflowType);
}
SyncDecisionContext syncContext = new SyncDecisionContext(context, dataConverter);
if (event.getEventType() != EventType.WorkflowExecutionStarted) {
throw new IllegalArgumentException("first event is not WorkflowExecutionStarted, but " + event.getEventType());
}
workflowProc = new WorkflowRunnable(syncContext, workflow, event.getWorkflowExecutionStartedEventAttributes());
runner = DeterministicRunner.newRunner(threadPool, syncContext, context::currentTimeMillis, workflowProc);
syncContext.setRunner(runner);
}
use of com.uber.cadence.WorkflowType in project cadence-client by uber-java.
the class SyncDecisionContext method executeChildWorkflowOnce.
/**
* @param executionResult promise that is set bu this method when child workflow is started.
*/
private Promise<byte[]> executeChildWorkflowOnce(String name, ChildWorkflowOptions options, byte[] input, CompletablePromise<WorkflowExecution> executionResult) {
StartChildWorkflowExecutionParameters parameters = new StartChildWorkflowExecutionParameters.Builder().setWorkflowType(new WorkflowType().setName(name)).setWorkflowId(options.getWorkflowId()).setInput(input).setChildPolicy(options.getChildPolicy()).setExecutionStartToCloseTimeoutSeconds(options.getExecutionStartToCloseTimeout().getSeconds()).setDomain(options.getDomain()).setTaskList(options.getTaskList()).setTaskStartToCloseTimeoutSeconds(options.getTaskStartToCloseTimeout().getSeconds()).setWorkflowIdReusePolicy(options.getWorkflowIdReusePolicy()).build();
CompletablePromise<byte[]> result = Workflow.newPromise();
Consumer<Exception> cancellationCallback = context.startChildWorkflow(parameters, executionResult::complete, (output, failure) -> {
if (failure != null) {
runner.executeInWorkflowThread("child workflow failure callback", () -> result.completeExceptionally(mapChildWorkflowException(failure)));
} else {
runner.executeInWorkflowThread("child workflow completion callback", () -> result.complete(output));
}
});
CancellationScope.current().getCancellationRequest().thenApply((reason) -> {
cancellationCallback.accept(new CancellationException(reason));
return null;
});
return result;
}
use of com.uber.cadence.WorkflowType in project cadence-client by uber-java.
the class WorkflowDecisionContext method handleStartChildWorkflowExecutionFailed.
void handleStartChildWorkflowExecutionFailed(HistoryEvent event) {
StartChildWorkflowExecutionFailedEventAttributes attributes = event.getStartChildWorkflowExecutionFailedEventAttributes();
String workflowId = attributes.getWorkflowId();
if (decisions.handleStartChildWorkflowExecutionFailed(event)) {
OpenChildWorkflowRequestInfo scheduled = scheduledExternalWorkflows.remove(workflowId);
if (scheduled != null) {
WorkflowExecution workflowExecution = new WorkflowExecution();
workflowExecution.setWorkflowId(workflowId);
WorkflowType workflowType = attributes.getWorkflowType();
ChildWorkflowExecutionFailedCause cause = attributes.getCause();
RuntimeException failure = new StartChildWorkflowFailedException(event.getEventId(), workflowExecution, workflowType, cause);
BiConsumer<byte[], Exception> completionCallback = scheduled.getCompletionCallback();
completionCallback.accept(null, failure);
}
}
}
use of com.uber.cadence.WorkflowType in project cadence-client by uber-java.
the class WorkflowStubImpl method startWithOptions.
private WorkflowExecution startWithOptions(WorkflowOptions o, Object... args) {
if (execution.get() != null) {
throw new DuplicateWorkflowException(execution.get(), workflowType.get(), "Cannot reuse a stub instance to start more than one workflow execution. The stub " + "points to already started execution.");
}
StartWorkflowExecutionParameters p = new StartWorkflowExecutionParameters();
p.setTaskStartToCloseTimeoutSeconds(o.getTaskStartToCloseTimeout().getSeconds());
if (o.getWorkflowId() == null) {
p.setWorkflowId(UUID.randomUUID().toString());
} else {
p.setWorkflowId(o.getWorkflowId());
}
p.setExecutionStartToCloseTimeoutSeconds(o.getExecutionStartToCloseTimeout().getSeconds());
p.setInput(dataConverter.toData(args));
p.setWorkflowType(new WorkflowType().setName(workflowType.get()));
p.setTaskList(o.getTaskList());
p.setChildPolicy(o.getChildPolicy());
try {
execution.set(genericClient.startWorkflow(p));
} catch (WorkflowExecutionAlreadyStartedError e) {
execution.set(new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId()));
WorkflowExecution execution = new WorkflowExecution().setWorkflowId(p.getWorkflowId()).setRunId(e.getRunId());
throw new DuplicateWorkflowException(execution, workflowType.get(), e.getMessage());
} catch (Exception e) {
throw new WorkflowServiceException(execution.get(), workflowType, e);
}
return execution.get();
}
Aggregations