Skip to content

Commit e527afb

Browse files
authored
fixed bug: Added alreadyStarted workflow case (#853)
If we get WorkflowExecutionAlreadyStartedError while starting workflow in new domain, then we don't require startWorkflowInNew domain again as well as not throw error. Hence, we will inform by giving status as "Workflow already started".
1 parent 8f153cf commit e527afb

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

src/main/java/com/uber/cadence/migration/MigrationActivities.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@
1919

2020
import com.uber.cadence.RequestCancelWorkflowExecutionRequest;
2121
import com.uber.cadence.StartWorkflowExecutionRequest;
22-
import com.uber.cadence.StartWorkflowExecutionResponse;
2322
import com.uber.cadence.activity.ActivityMethod;
2423

2524
public interface MigrationActivities {
25+
/**
26+
* Starts a new workflow execution in a new domain.
27+
*
28+
* @param request The request to start the workflow in new domain.
29+
* @return A response indicating the status of the operation.
30+
*/
2631
@ActivityMethod
27-
StartWorkflowExecutionResponse startWorkflowInNewDomain(StartWorkflowExecutionRequest request);
32+
StartWorkflowInNewResponse startWorkflowInNewDomain(StartWorkflowExecutionRequest request);
2833

34+
/**
35+
* Cancels a workflow execution in the current domain.
36+
*
37+
* @param request The request to cancel the workflow.
38+
*/
2939
@ActivityMethod
3040
void cancelWorkflowInCurrentDomain(RequestCancelWorkflowExecutionRequest request);
3141
}

src/main/java/com/uber/cadence/migration/MigrationActivitiesImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import com.uber.cadence.RequestCancelWorkflowExecutionRequest;
2121
import com.uber.cadence.StartWorkflowExecutionRequest;
22-
import com.uber.cadence.StartWorkflowExecutionResponse;
22+
import com.uber.cadence.WorkflowExecutionAlreadyStartedError;
2323
import com.uber.cadence.client.WorkflowClient;
2424
import com.uber.cadence.workflow.Workflow;
2525

@@ -33,10 +33,14 @@ public MigrationActivitiesImpl(
3333
}
3434

3535
@Override
36-
public StartWorkflowExecutionResponse startWorkflowInNewDomain(
36+
public StartWorkflowInNewResponse startWorkflowInNewDomain(
3737
StartWorkflowExecutionRequest request) {
3838
try {
39-
return clientInNewDomain.getService().StartWorkflowExecution(request);
39+
return new StartWorkflowInNewResponse(
40+
clientInNewDomain.getService().StartWorkflowExecution(request),
41+
"New workflow starting successful");
42+
} catch (WorkflowExecutionAlreadyStartedError e) {
43+
return new StartWorkflowInNewResponse(null, "Workflow already started");
4044
} catch (Exception e) {
4145
throw Workflow.wrap(e);
4246
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
package com.uber.cadence.migration;
19+
20+
import com.uber.cadence.StartWorkflowExecutionResponse;
21+
22+
public class StartWorkflowInNewResponse {
23+
StartWorkflowExecutionResponse startWorkflowExecutionResponse;
24+
String status;
25+
26+
StartWorkflowInNewResponse(StartWorkflowExecutionResponse startWorkflowResponse, String msg) {
27+
startWorkflowExecutionResponse = startWorkflowResponse;
28+
status = msg;
29+
}
30+
}

0 commit comments

Comments
 (0)