Skip to content

Commit 0256258

Browse files
Add Reset API with new option of skip signal reapply and fix all lint errors (#1032)
1 parent 3b485bd commit 0256258

16 files changed

+587
-44
lines changed

.gen/go/shared/idl.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/go/shared/types.go

Lines changed: 481 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

activity/activity.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ type (
4646
// that could report the activity completed event to cadence server via Client.CompleteActivity() API.
4747
var ErrResultPending = internal.ErrActivityResultPending
4848

49+
// Register - calls RegisterWithOptions with default registration options.
4950
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
5051
// This method is kept to maintain backward compatibility and should not be used.
51-
// Register - calls RegisterWithOptions with default registration options.
5252
func Register(activityFunc interface{}) {
5353
internal.RegisterActivity(activityFunc)
5454
}
5555

56-
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
57-
// This method is kept to maintain backward compatibility and should not be used.
5856
// RegisterWithOptions registers the activity function with options
5957
// The user can use options to provide an external name for the activity or leave it empty if no
6058
// external name is required. This can be used as
@@ -72,6 +70,8 @@ func Register(activityFunc interface{}) {
7270
// If function implementation returns activity.ErrResultPending then activity is not completed from the
7371
// calling workflow point of view. See documentation of activity.ErrResultPending for more info.
7472
// This method calls panic if activityFunc doesn't comply with the expected format.
73+
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
74+
// This method is kept to maintain backward compatibility and should not be used.
7575
func RegisterWithOptions(activityFunc interface{}, opts RegisterOptions) {
7676
internal.RegisterActivityWithOptions(activityFunc, opts)
7777
}

client/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ type (
326326
// - QueryFailError
327327
QueryWorkflowWithOptions(ctx context.Context, request *QueryWorkflowWithOptionsRequest) (*QueryWorkflowWithOptionsResponse, error)
328328

329+
// ResetWorkflow reset a given workflow execution and returns a new execution
330+
// See ResetWorkflowRequest and ResetWorkflowResponse for more information.
331+
// The errors it can return:
332+
// - BadRequestError
333+
// - InternalServiceError
334+
// - EntityNotExistError
335+
ResetWorkflow(ctx context.Context, request *s.ResetWorkflowExecutionRequest) (*s.ResetWorkflowExecutionResponse, error)
336+
329337
// DescribeWorkflowExecution returns information about the specified workflow execution.
330338
// - runID can be default(empty string). if empty string then it will pick the last running execution of that workflow ID.
331339
//

idls

Submodule idls updated from 54a04b8 to 5216c3d

internal/activity.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ type (
127127
}
128128
)
129129

130-
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
131-
// This method is kept to maintain backward compatibility and should not be used.
132130
// RegisterActivity - register an activity function or a pointer to a structure with the framework.
133131
// The public form is: activity.Register(...)
134132
// An activity function takes a context and input and returns a (result, error) or just error.
@@ -158,12 +156,12 @@ type (
158156
//
159157
// Serialization of all primitive types, structures is supported ... except channels, functions, variadic, unsafe pointer.
160158
// This method calls panic if activityFunc doesn't comply with the expected format.
159+
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
160+
// This method is kept to maintain backward compatibility and should not be used.
161161
func RegisterActivity(activityFunc interface{}) {
162162
RegisterActivityWithOptions(activityFunc, RegisterActivityOptions{})
163163
}
164164

165-
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
166-
// This method is kept to maintain backward compatibility and should not be used.
167165
// RegisterActivityWithOptions registers the activity function or struct pointer with options.
168166
// The public form is: activity.RegisterWithOptions(...)
169167
// The user can use options to provide an external name for the activity or leave it empty if no
@@ -181,6 +179,8 @@ func RegisterActivity(activityFunc interface{}) {
181179
// The other use of options is to disable duplicated activity registration check
182180
// which might be useful for integration tests.
183181
// activity.RegisterWithOptions(barActivity, RegisterActivityOptions{DisableAlreadyRegisteredCheck: true})
182+
// Deprecated: Global activity registration methods are replaced by equivalent Worker instance methods.
183+
// This method is kept to maintain backward compatibility and should not be used.
184184
func RegisterActivityWithOptions(activityFunc interface{}, opts RegisterActivityOptions) {
185185
registry := getGlobalRegistry()
186186
registry.RegisterActivityWithOptions(activityFunc, opts)

internal/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ type (
301301
// - QueryFailError
302302
QueryWorkflowWithOptions(ctx context.Context, request *QueryWorkflowWithOptionsRequest) (*QueryWorkflowWithOptionsResponse, error)
303303

304+
// ResetWorkflow reset a given workflow execution and returns a new execution
305+
// See QueryWorkflowWithOptionsRequest and QueryWorkflowWithOptionsResponse for more information.
306+
// The errors it can return:
307+
// - BadRequestError
308+
// - InternalServiceError
309+
// - EntityNotExistError
310+
ResetWorkflow(ctx context.Context, request *s.ResetWorkflowExecutionRequest) (*s.ResetWorkflowExecutionResponse, error)
311+
304312
// DescribeWorkflowExecution returns information about the specified workflow execution.
305313
// The errors it can return:
306314
// - BadRequestError

internal/internal_workflow_client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,26 @@ func (wc *workflowClient) CountWorkflow(ctx context.Context, request *s.CountWor
773773
return response, nil
774774
}
775775

776+
// ResetWorkflow implementation
777+
func (wc *workflowClient) ResetWorkflow(ctx context.Context, request *s.ResetWorkflowExecutionRequest) (*s.ResetWorkflowExecutionResponse, error) {
778+
if len(request.GetDomain()) == 0 {
779+
request.Domain = common.StringPtr(wc.domain)
780+
}
781+
var response *s.ResetWorkflowExecutionResponse
782+
err := backoff.Retry(ctx,
783+
func() error {
784+
var err1 error
785+
tchCtx, cancel, opt := newChannelContext(ctx)
786+
defer cancel()
787+
response, err1 = wc.workflowService.ResetWorkflowExecution(tchCtx, request, opt...)
788+
return err1
789+
}, createDynamicServiceRetryPolicy(ctx), isServiceTransientError)
790+
if err != nil {
791+
return nil, err
792+
}
793+
return response, nil
794+
}
795+
776796
// GetSearchAttributes implementation
777797
func (wc *workflowClient) GetSearchAttributes(ctx context.Context) (*s.GetSearchAttributesResponse, error) {
778798
var response *s.GetSearchAttributesResponse

internal/internal_workflow_testsuite.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type (
154154
onTimerFiredListener func(timerID string)
155155
onTimerCancelledListener func(timerID string)
156156

157-
cronMaxIterations int
157+
cronMaxIterations int
158158
}
159159

160160
// testWorkflowEnvironmentImpl is the environment that runs the workflow/activity unit tests.
@@ -186,10 +186,9 @@ type (
186186
workerStopChannel chan struct{}
187187
sessionEnvironment *testSessionEnvironmentImpl
188188

189-
cronSchedule string
190-
cronIterations int
191-
workflowInput []byte
192-
189+
cronSchedule string
190+
cronIterations int
191+
workflowInput []byte
193192
}
194193

195194
testSessionEnvironmentImpl struct {
@@ -831,7 +830,7 @@ func (env *testWorkflowEnvironmentImpl) Complete(result []byte, err error) {
831830
// 1. Child-Workflows
832831
// 2. non-cron Workflows
833832
if env.isChildWorkflow() && !env.IsCron() {
834-
close(env.doneChannel)
833+
close(env.doneChannel)
835834
}
836835

837836
if env.isChildWorkflow() {
@@ -919,7 +918,7 @@ func (h *testWorkflowHandle) rerun(asChild bool) bool {
919918
workflowNow := env.Now().In(time.UTC)
920919
backoff := schedule.Next(workflowNow).Sub(workflowNow)
921920
if backoff > 0 {
922-
env.cronIterations += 1
921+
env.cronIterations++
923922
delete(env.runningWorkflows, env.workflowInfo.WorkflowExecution.ID)
924923
params.attempt = 0
925924
params.scheduledTime = env.Now()
@@ -943,7 +942,7 @@ func (h *testWorkflowHandle) rerun(asChild bool) bool {
943942
workflowNow := env.Now().In(time.UTC)
944943
backoff := schedule.Next(workflowNow).Sub(workflowNow)
945944
if backoff > 0 {
946-
env.cronIterations += 1
945+
env.cronIterations++
947946
// Prepare the env for the next iteration
948947
env.runningCount--
949948
env.setLastCompletionResult(result)
@@ -955,7 +954,7 @@ func (h *testWorkflowHandle) rerun(asChild bool) bool {
955954
// Use the existing headers and input
956955
env.workflowDef.Execute(env, env.header, env.workflowInput)
957956
env.startDecisionTask()
958-
}, backoff - backoff)
957+
}, backoff-backoff)
959958
return true
960959
}
961960
}

internal/internal_workflow_testsuite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_CronChildWorkflow() {
28042804
if HasLastCompletionResult(ctx) {
28052805
GetLastCompletionResult(ctx, &result)
28062806
}
2807-
Sleep(ctx, time.Second * 3)
2807+
Sleep(ctx, time.Second*3)
28082808
if info.Attempt == 0 {
28092809
failedCount++
28102810
return 0, errors.New("please-retry")
@@ -2831,7 +2831,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_CronChildWorkflow() {
28312831

28322832
cronFuture := ExecuteChildWorkflow(ctx1, cronWorkflow) // cron never stop so this future won't return
28332833

2834-
timeoutTimer := NewTimer(ctx, time.Hour * 3)
2834+
timeoutTimer := NewTimer(ctx, time.Hour*3)
28352835
selector := NewSelector(ctx)
28362836
var err error
28372837
selector.AddFuture(cronFuture, func(f Future) {
@@ -2867,7 +2867,7 @@ func (s *WorkflowTestSuiteUnitTest) Test_CronWorkflow() {
28672867
if HasLastCompletionResult(ctx) {
28682868
GetLastCompletionResult(ctx, &result)
28692869
}
2870-
Sleep(ctx, time.Second * 3)
2870+
Sleep(ctx, time.Second*3)
28712871
result++
28722872
return result, nil
28732873
}

0 commit comments

Comments
 (0)