in src/main/java/com/uber/cadence/migration/MigrationInterceptor.java [154:203]
public void continueAsNew(
Optional<String> workflowType, Optional<ContinueAsNewOptions> options, Object[] args) {
// Versioning to ensure replay is deterministic
int version = getVersion(versionChangeID, Workflow.DEFAULT_VERSION, versionV1);
switch (version) {
case versionV1:
WorkflowInfo workflowInfo = Workflow.getWorkflowInfo();
WorkflowExecutionStartedEventAttributes startedEventAttributes =
workflowInfo.getWorkflowExecutionStartedEventAttributes();
if (isChildWorkflow(startedEventAttributes)) {
next.continueAsNew(workflowType, options, args);
}
MigrationDecision decision =
Workflow.sideEffect(MigrationDecision.class, () -> new MigrationDecision(true, ""));
if (decision.shouldMigrate) {
try {
MigrationActivities activities =
Workflow.newActivityStub(MigrationActivities.class, activityOptions);
activities.startWorkflowInNewDomain(
new StartWorkflowExecutionRequest()
.setDomain(domainNew)
.setWorkflowId(workflowInfo.getWorkflowId())
.setTaskList(new TaskList().setName(startedEventAttributes.taskList.getName()))
.setInput(workflowInfo.getDataConverter().toData(args))
.setWorkflowType(
new WorkflowType()
.setName(startedEventAttributes.getWorkflowType().getName()))
.setWorkflowIdReusePolicy(WorkflowIdReusePolicy.TerminateIfRunning)
.setRetryPolicy(startedEventAttributes.getRetryPolicy())
.setRequestId(UUID.randomUUID().toString())
.setIdentity(startedEventAttributes.getIdentity())
.setMemo(startedEventAttributes.getMemo())
.setCronSchedule(startedEventAttributes.getCronSchedule())
.setHeader(startedEventAttributes.getHeader())
.setSearchAttributes(startedEventAttributes.getSearchAttributes())
.setExecutionStartToCloseTimeoutSeconds(
startedEventAttributes.getExecutionStartToCloseTimeoutSeconds())
.setTaskStartToCloseTimeoutSeconds(
startedEventAttributes.getTaskStartToCloseTimeoutSeconds()));
cancelCurrentWorkflow();
} catch (ActivityException e) {
// fallback if start workflow in new domain failed
next.continueAsNew(workflowType, options, args);
}
}
default:
next.continueAsNew(workflowType, options, args);
}
}