-
Notifications
You must be signed in to change notification settings - Fork 1.2k
batch: add activity reset and update-options #8061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
f2eca79
6386a98
2ab3fc2
5dffea2
3be16ed
67b5561
cf21122
4839bf9
6a231dd
81feb90
4bb1270
92762f4
d15af61
0db12cf
43a6ace
0a0fcfd
f77a9c3
215876c
a6cae5d
9cf8d90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,6 +339,7 @@ func startTaskProcessor( | |
| WorkflowId: workflowID, | ||
| RunId: runID, | ||
| }, | ||
| // QUESTION: do we want to plumb through the identity from cli/ui/sdk ? @yuri/@chetan | ||
|
||
| Identity: "batch unpause", | ||
| Activity: &workflowservice.UnpauseActivityRequest_Type{Type: batchParams.UnpauseActivitiesParams.ActivityType}, | ||
| ResetAttempts: !batchParams.UnpauseActivitiesParams.ResetAttempts, | ||
|
|
@@ -370,6 +371,59 @@ func startTaskProcessor( | |
| }) | ||
| return err | ||
| }) | ||
|
|
||
| case BatchTypeResetActivities: | ||
| err = processTask(ctx, limiter, task, | ||
| func(workflowID, runID string) error { | ||
| resetRequest := &workflowservice.ResetActivityRequest{ | ||
| Namespace: batchParams.Namespace, | ||
| Execution: &commonpb.WorkflowExecution{ | ||
| WorkflowId: workflowID, | ||
| RunId: runID, | ||
| }, | ||
| Identity: "batch reset", | ||
| Activity: &workflowservice.ResetActivityRequest_Type{Type: batchParams.ResetActivitiesParams.ActivityType}, | ||
| ResetHeartbeat: batchParams.ResetActivitiesParams.ResetHeartbeat, | ||
| Jitter: durationpb.New(batchParams.ResetActivitiesParams.Jitter), | ||
| KeepPaused: batchParams.ResetActivitiesParams.KeepPaused, | ||
| RestoreOriginalOptions: batchParams.ResetActivitiesParams.RestoreOriginalOptions, | ||
| } | ||
|
|
||
| if batchParams.ResetActivitiesParams.MatchAll { | ||
| resetRequest.Activity = &workflowservice.ResetActivityRequest_ResetAll{ResetAll: true} | ||
| } else { | ||
| resetRequest.Activity = &workflowservice.ResetActivityRequest_Type{Type: batchParams.ResetActivitiesParams.ActivityType} | ||
| } | ||
|
|
||
| _, err = frontendClient.ResetActivity(ctx, resetRequest) | ||
| return err | ||
| }) | ||
| case BatchTypeUpdateOptionsActivities: | ||
| err = processTask(ctx, limiter, task, | ||
| func(workflowID, runID string) error { | ||
| updateRequest := &workflowservice.UpdateActivityOptionsRequest{ | ||
| Namespace: batchParams.Namespace, | ||
| Execution: &commonpb.WorkflowExecution{ | ||
| WorkflowId: workflowID, | ||
| RunId: runID, | ||
| }, | ||
| Activity: &workflowservice.UpdateActivityOptionsRequest_Type{Type: batchParams.UpdateOptionsActivitiesParams.ActivityType}, | ||
| UpdateMask: batchParams.UpdateOptionsActivitiesParams.UpdateMask, | ||
| RestoreOriginal: batchParams.UpdateOptionsActivitiesParams.RestoreOriginal, | ||
| Identity: batchParams.UpdateOptionsActivitiesParams.Identity, | ||
| ActivityOptions: batchParams.UpdateOptionsActivitiesParams.ActivityOptions, | ||
| } | ||
|
|
||
| if batchParams.UpdateOptionsActivitiesParams.MatchAll { | ||
| updateRequest.Activity = &workflowservice.UpdateActivityOptionsRequest_UpdateAll{UpdateAll: true} | ||
| } else { | ||
| updateRequest.Activity = &workflowservice.UpdateActivityOptionsRequest_Type{Type: batchParams.UpdateOptionsActivitiesParams.ActivityType} | ||
| } | ||
|
|
||
| _, err = frontendClient.UpdateActivityOptions(ctx, updateRequest) | ||
| return err | ||
| }) | ||
| // QUESTION: why do we not have a default case and return an error? @yuri/@chetan | ||
| } | ||
| if err != nil { | ||
| metrics.BatcherProcessorFailures.With(metricsHandler).Record(1) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package batcher | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| activitypb "go.temporal.io/api/activity/v1" | ||
| commonpb "go.temporal.io/api/common/v1" | ||
| enumspb "go.temporal.io/api/enums/v1" | ||
| workflowpb "go.temporal.io/api/workflow/v1" | ||
|
|
@@ -42,6 +44,10 @@ const ( | |
| BatchTypeUpdateOptions = "update_options" | ||
| // BatchTypePauseActivities is batch type for unpausing activities | ||
| BatchTypeUnpauseActivities = "unpause_activities" | ||
| // BatchTypeUpdateOptionsActivities is batch type for updating the options of activities | ||
| BatchTypeUpdateOptionsActivities = "update_options_activities" | ||
spkane31 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // BatchTypeResetActivities is batch type for resetting activities | ||
| BatchTypeResetActivities = "reset_activities" | ||
| ) | ||
|
|
||
| var ( | ||
|
|
@@ -103,6 +109,26 @@ type ( | |
| Jitter time.Duration | ||
| } | ||
|
|
||
| UpdateOptionsActivitiesParams struct { | ||
| Identity string | ||
| ActivityType string | ||
| MatchAll bool | ||
| ActivityOptions *activitypb.ActivityOptions | ||
| UpdateMask *fieldmaskpb.FieldMask | ||
|
||
| RestoreOriginal bool | ||
| } | ||
|
|
||
| ResetActivitiesParams struct { | ||
| Identity string | ||
| ActivityType string | ||
| MatchAll bool | ||
| ResetAttempts bool | ||
| ResetHeartbeat bool | ||
| KeepPaused bool | ||
| Jitter time.Duration | ||
| RestoreOriginalOptions bool | ||
| } | ||
|
|
||
| // BatchParams is the parameters for batch operation workflow | ||
| BatchParams struct { | ||
| // Target namespace to execute batch operation | ||
|
|
@@ -131,6 +157,10 @@ type ( | |
| UpdateOptionsParams UpdateOptionsParams | ||
| // UnpauseActivitiesParams is params only for BatchTypeUnpauseActivities | ||
| UnpauseActivitiesParams UnpauseActivitiesParams | ||
| // UpdateOptionsActivitiesParams is params only for BatchTypeUpdateOptionsActivities | ||
| UpdateOptionsActivitiesParams UpdateOptionsActivitiesParams | ||
spkane31 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // ResetActivitiesParams is params only for BatchTypeResetActivities | ||
| ResetActivitiesParams ResetActivitiesParams | ||
|
|
||
| // RPS sets the requests-per-second limit for the batch. | ||
| // The default (and max) is defined by `worker.BatcherRPS` in the dynamic config. | ||
|
|
@@ -257,6 +287,16 @@ func validateParams(params BatchParams) error { | |
| return fmt.Errorf("must provide ActivityType or MatchAll") | ||
| } | ||
| return nil | ||
| case BatchTypeResetActivities: | ||
| if params.ResetActivitiesParams.ActivityType == "" && !params.ResetActivitiesParams.MatchAll { | ||
| return errors.New("must provide ActivityType or MatchAll") | ||
| } | ||
| return nil | ||
| case BatchTypeUpdateOptionsActivities: | ||
| if params.UpdateOptionsActivitiesParams.ActivityType == "" && !params.UpdateOptionsActivitiesParams.MatchAll { | ||
| return errors.New("must provide ActivityType or MatchAll") | ||
| } | ||
| return nil | ||
| default: | ||
| return fmt.Errorf("not supported batch type: %v", params.BatchType) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please merge the API change before the server PR.