Skip to content

Commit 76f53fe

Browse files
authored
Expose WithCancelReason and related types publicly, as originally intended (#1214)
Missed this during review of #1213, sorry! I'm not entirely sure how to catch things like this in tests, without a separate module...
1 parent a3fe700 commit 76f53fe

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

client/client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ type (
7373
// ParentClosePolicy defines the behavior performed on a child workflow when its parent is closed
7474
ParentClosePolicy = internal.ParentClosePolicy
7575

76+
// CancelOption values are functional options for the CancelWorkflow method.
77+
// Supported values can be created with:
78+
// - WithCancelReason(...)
79+
CancelOption = internal.Option
80+
7681
// Client is the client for starting and getting information about a workflow executions as well as
7782
// completing activities asynchronously.
7883
Client interface {
@@ -162,7 +167,7 @@ type (
162167
// - BadRequestError
163168
// - InternalServiceError
164169
// - WorkflowExecutionAlreadyCompletedError
165-
CancelWorkflow(ctx context.Context, workflowID string, runID string, opts ...internal.Option) error
170+
CancelWorkflow(ctx context.Context, workflowID string, runID string, opts ...CancelOption) error
166171

167172
// TerminateWorkflow terminates a workflow execution.
168173
// workflowID is required, other parameters are optional.
@@ -516,3 +521,10 @@ func IsWorkflowError(err error) bool {
516521
}
517522
return false
518523
}
524+
525+
// WithCancelReason can be passed to Client.CancelWorkflow to provide an explicit cancellation reason,
526+
// which will be recorded in the cancellation event in the workflow's history, similar to termination reasons.
527+
// This is purely informational, and does not influence Cadence behavior at all.
528+
func WithCancelReason(reason string) CancelOption {
529+
return internal.WithCancelReason(reason)
530+
}

internal/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ const (
4747

4848
type Option interface{ private() }
4949

50-
type cancelReason string
50+
type CancelReason string
5151

52-
func (cancelReason) private() {}
52+
func (CancelReason) private() {}
5353

54+
// WithCancelReason can be passed to Client.CancelWorkflow to provide an explicit cancellation reason,
55+
// which will be recorded in the cancellation event in the workflow's history, similar to termination reasons.
56+
// This is purely informational, and does not influence Cadence behavior at all.
5457
func WithCancelReason(reason string) Option {
55-
return cancelReason(reason)
58+
return CancelReason(reason)
5659
}
5760

5861
type (

internal/internal_workflow_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ func (wc *workflowClient) CancelWorkflow(ctx context.Context, workflowID string,
470470

471471
for _, opt := range opts {
472472
switch o := opt.(type) {
473-
case cancelReason:
473+
case CancelReason:
474474
cause := string(o)
475475
request.Cause = &cause
476476
}

0 commit comments

Comments
 (0)