@@ -22,6 +22,7 @@ package internal
2222
2323import (
2424 "context"
25+ "fmt"
2526 "time"
2627
2728 "go.uber.org/cadence/encoded"
@@ -43,15 +44,42 @@ type (
4344 // StartWorkflow starts a workflow execution
4445 // The user can use this to start using a function or workflow type name.
4546 // Either by
46- // StartWorkflow(ctx, options, "workflowTypeName", input )
47+ // StartWorkflow(ctx, options, "workflowTypeName", arg1, arg2, arg3 )
4748 // or
4849 // StartWorkflow(ctx, options, workflowExecuteFn, arg1, arg2, arg3)
4950 // The errors it can return:
50- // - EntityNotExistsError
51+ // - EntityNotExistsError, if domain does not exists
5152 // - BadRequestError
5253 // - WorkflowExecutionAlreadyStartedError
54+ // - InternalServiceError
5355 StartWorkflow (ctx context.Context , options StartWorkflowOptions , workflow interface {}, args ... interface {}) (* WorkflowExecution , error )
5456
57+ // ExecuteWorkflow starts a workflow execution and return a WorkflowRun instance and error
58+ // The user can use this to start using a function or workflow type name.
59+ // Either by
60+ // ExecuteWorkflow(ctx, options, "workflowTypeName", arg1, arg2, arg3)
61+ // or
62+ // ExecuteWorkflow(ctx, options, workflowExecuteFn, arg1, arg2, arg3)
63+ // The errors it can return:
64+ // - EntityNotExistsError, if domain does not exists
65+ // - BadRequestError
66+ // - WorkflowExecutionAlreadyStartedError
67+ // - InternalServiceError
68+ //
69+ // WorkflowRun has 2 methods:
70+ // - GetRunID() string: which return the first started workflow run ID (please see below)
71+ // - Get(ctx context.Context, valuePtr interface{}) error: which will fill the workflow
72+ // execution result to valuePtr, if workflow execution is a success, or return corresponding
73+ // error. This is a blocking API.
74+ // NOTE: if the started workflow return ContinueAsNewError during the workflow execution, the
75+ // return result of GetRunID() will be the started workflow run ID, not the new run ID caused by ContinueAsNewError,
76+ // however, Get(ctx context.Context, valuePtr interface{}) will return result from the run which did not return ContinueAsNewError.
77+ // Say ExecuteWorkflow started a workflow, in its first run, has run ID "run ID 1", and returned ContinueAsNewError,
78+ // the second run has run ID "run ID 2" and return some result other than ContinueAsNewError:
79+ // GetRunID() will always return "run ID 1" and Get(ctx context.Context, valuePtr interface{}) will return the result of second run.
80+ // NOTE: DO NOT USE THIS API INSIDE A WORKFLOW, USE workflow.ExecuteChildWorkflow instead
81+ ExecuteWorkflow (ctx context.Context , options StartWorkflowOptions , workflow interface {}, args ... interface {}) (WorkflowRun , error )
82+
5583 // SignalWorkflow sends a signals to a workflow in execution
5684 // - workflow ID of the workflow.
5785 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
@@ -80,14 +108,25 @@ type (
80108 // - InternalServiceError
81109 TerminateWorkflow (ctx context.Context , workflowID string , runID string , reason string , details []byte ) error
82110
83- // GetWorkflowHistory gets history of a particular workflow.
111+ // GetWorkflowHistory gets history events of a particular workflow
84112 // - workflow ID of the workflow.
85- // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
86- // The errors it can return:
87- // - EntityNotExistsError
88- // - BadRequestError
89- // - InternalServiceError
90- GetWorkflowHistory (ctx context.Context , workflowID string , runID string ) (* s.History , error )
113+ // - runID can be default(empty string). if empty string then it will pick the last running execution of that workflow ID.
114+ // - whether use long poll for tracking new events: when the workflow is running, there can be new events generated during iteration
115+ // of HistoryEventIterator, if isLongPoll == true, then iterator will do long poll, tracking new history event, i.e. the iteration
116+ // will not be finished until workflow is finished; if isLongPoll == false, then iterator will only return current history events.
117+ // - whether return all history events or just the last event, which contains the workflow execution end result
118+ // Example:-
119+ // To iterate all events,
120+ // iter := GetWorkflowHistory(ctx, workflowID, runID, isLongPoll, filterType)
121+ // events := []*shared.HistoryEvent{}
122+ // for iter.HasNext() {
123+ // event, err := iter.Next()
124+ // if err != nil {
125+ // return err
126+ // }
127+ // events = append(events, event)
128+ // }
129+ GetWorkflowHistory (ctx context.Context , workflowID string , runID string , isLongPoll bool , filterType s.HistoryEventFilterType ) HistoryEventIterator
91130
92131 // CompleteActivity reports activity completed.
93132 // activity Execute method can return acitivity.activity.ErrResultPending to
@@ -147,7 +186,7 @@ type (
147186 // run. By default, cadence supports "__stack_trace" as a standard query type, which will return string value
148187 // representing the call stack of the target workflow. The target workflow could also setup different query handler
149188 // to handle custom query types.
150- // See comments at cadence .SetQueryHandler(ctx Context, queryType string, handler interface{}) for more details
189+ // See comments at workflow .SetQueryHandler(ctx Context, queryType string, handler interface{}) for more details
151190 // on how to setup query handler within the target workflow.
152191 // - workflowID is required.
153192 // - runID can be default(empty string). if empty string then it will pick the running execution of that workflow ID.
@@ -196,6 +235,10 @@ type (
196235 // The resolution is seconds.
197236 // Optional: defaulted to 20 secs.
198237 DecisionTaskStartToCloseTimeout time.Duration
238+
239+ // WorkflowIDReusePolicy - Whether server allow reuse of workflow ID, can be useful
240+ // for dedup logic if set to WorkflowIdReusePolicyRejectDuplicate
241+ WorkflowIDReusePolicy WorkflowIDReusePolicy
199242 }
200243
201244 // DomainClient is the client for managing operations on the domain.
@@ -226,6 +269,23 @@ type (
226269 // - InternalServiceError
227270 Update (ctx context.Context , name string , domainInfo * s.UpdateDomainInfo , domainConfig * s.DomainConfiguration ) error
228271 }
272+
273+ // WorkflowIDReusePolicy defines workflow ID reuse behavior.
274+ WorkflowIDReusePolicy int
275+ )
276+
277+ const (
278+ // WorkflowIDReusePolicyAllowDuplicateFailedOnly allow start a workflow execution
279+ // when workflow not running, and the last execution close state is in
280+ // [terminated, cancelled, timeouted, failed].
281+ WorkflowIDReusePolicyAllowDuplicateFailedOnly WorkflowIDReusePolicy = iota
282+
283+ // WorkflowIDReusePolicyAllowDuplicate allow start a workflow execution using
284+ // the same workflow ID,when workflow not running.
285+ WorkflowIDReusePolicyAllowDuplicate
286+
287+ // WorkflowIDReusePolicyRejectDuplicate do not allow start a workflow execution using the same workflow ID at all
288+ WorkflowIDReusePolicyRejectDuplicate
229289)
230290
231291// NewClient creates an instance of a workflow client
@@ -268,3 +328,18 @@ func NewDomainClient(service workflowserviceclient.Interface, options *ClientOpt
268328 identity : identity ,
269329 }
270330}
331+
332+ func (p WorkflowIDReusePolicy ) toThriftPtr () * s.WorkflowIdReusePolicy {
333+ var policy s.WorkflowIdReusePolicy
334+ switch p {
335+ case WorkflowIDReusePolicyAllowDuplicate :
336+ policy = s .WorkflowIdReusePolicyAllowDuplicate
337+ case WorkflowIDReusePolicyAllowDuplicateFailedOnly :
338+ policy = s .WorkflowIdReusePolicyAllowDuplicateFailedOnly
339+ case WorkflowIDReusePolicyRejectDuplicate :
340+ policy = s .WorkflowIdReusePolicyRejectDuplicate
341+ default :
342+ panic (fmt .Sprintf ("unknown workflow reuse policy %v" , p ))
343+ }
344+ return & policy
345+ }
0 commit comments