Skip to content

Commit d9a961d

Browse files
authored
runID being optional is moved from empty string to not specified. (#169)
1 parent ba6a088 commit d9a961d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type (
4646

4747
// SignalWorkflow sends a signals to a workflow in execution
4848
// - workflow ID of the workflow.
49-
// - runID can be optional if not specified it will pick the latest execution of that workflow ID.
49+
// - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
5050
// - signalName name to identify the signal.
5151
// The errors it can return:
5252
// - EntityNotExistsError
@@ -55,7 +55,7 @@ type (
5555

5656
// CancelWorkflow cancels a workflow in execution
5757
// - workflow ID of the workflow.
58-
// - runID can be optional if not specified it will pick the latest execution of that workflow ID.
58+
// - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
5959
// The errors it can return:
6060
// - EntityNotExistsError
6161
// - BadRequestError
@@ -64,14 +64,17 @@ type (
6464

6565
// TerminateWorkflow terminates a workflow execution.
6666
// workflowID is required, other parameters are optional.
67-
// If runID is omit, it will terminate currently running workflow (if there is one) based on the workflowID.
67+
// - workflow ID of the workflow.
68+
// - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
6869
// The errors it can return:
6970
// - EntityNotExistsError
7071
// - BadRequestError
7172
// - InternalServiceError
7273
TerminateWorkflow(workflowID string, runID string, reason string, details []byte) error
7374

7475
// GetWorkflowHistory gets history of a particular workflow.
76+
// - workflow ID of the workflow.
77+
// - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
7578
// The errors it can return:
7679
// - EntityNotExistsError
7780
// - BadRequestError

internal_workflow_client.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,19 @@ func (wc *workflowClient) StartWorkflow(
137137

138138
// SignalWorkflow signals a workflow in execution.
139139
func (wc *workflowClient) SignalWorkflow(workflowID string, runID string, signalName string, arg interface{}) error {
140-
input, err := getHostEnvironment().encodeArg(arg)
141-
if err != nil {
142-
return err
140+
var input []byte
141+
if arg != nil {
142+
var err error
143+
if input, err = getHostEnvironment().encodeArg(arg); err != nil {
144+
return err
145+
}
143146
}
147+
144148
request := &s.SignalWorkflowExecutionRequest{
145149
Domain: common.StringPtr(wc.domain),
146150
WorkflowExecution: &s.WorkflowExecution{
147151
WorkflowId: common.StringPtr(workflowID),
148-
RunId: common.StringPtr(runID),
152+
RunId: getRunID(runID),
149153
},
150154
SignalName: common.StringPtr(signalName),
151155
Input: input,
@@ -166,7 +170,7 @@ func (wc *workflowClient) CancelWorkflow(workflowID string, runID string) error
166170
Domain: common.StringPtr(wc.domain),
167171
WorkflowExecution: &s.WorkflowExecution{
168172
WorkflowId: common.StringPtr(workflowID),
169-
RunId: common.StringPtr(runID),
173+
RunId: getRunID(runID),
170174
},
171175
Identity: common.StringPtr(wc.identity),
172176
}
@@ -187,7 +191,7 @@ func (wc *workflowClient) TerminateWorkflow(workflowID string, runID string, rea
187191
Domain: common.StringPtr(wc.domain),
188192
WorkflowExecution: &s.WorkflowExecution{
189193
WorkflowId: common.StringPtr(workflowID),
190-
RunId: common.StringPtr(runID),
194+
RunId: getRunID(runID),
191195
},
192196
Reason: common.StringPtr(reason),
193197
Identity: common.StringPtr(wc.identity),
@@ -215,7 +219,7 @@ GetHistoryLoop:
215219
Domain: common.StringPtr(wc.domain),
216220
Execution: &s.WorkflowExecution{
217221
WorkflowId: common.StringPtr(workflowID),
218-
RunId: common.StringPtr(runID),
222+
RunId: getRunID(runID),
219223
},
220224
NextPageToken: nextPageToken,
221225
}
@@ -383,3 +387,11 @@ func (dc *domainClient) Update(name string, domainInfo *s.UpdateDomainInfo, doma
383387
return err
384388
}, serviceOperationRetryPolicy, isServiceTransientError)
385389
}
390+
391+
func getRunID(runID string) *string {
392+
if runID == "" {
393+
// Cadence Server will pick current runID if provided empty.
394+
return nil
395+
}
396+
return common.StringPtr(runID)
397+
}

0 commit comments

Comments
 (0)