Skip to content

Commit

Permalink
Move commonly used get & update function to api package (#3311)
Browse files Browse the repository at this point in the history
* Move commonly used get & update function to api package
  * Update history engine & workflow task handler accordingly
  • Loading branch information
wxing1292 authored Sep 7, 2022
1 parent c0577e0 commit 44ee560
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 143 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ update-mockgen:

update-proto-plugins:
@printf $(COLOR) "Install/update proto plugins..."
@go install github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick@latest
@go install github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick@master
# This to download sources of gogo-protobuf which are required to build proto files.
@GO111MODULE=off go get github.com/temporalio/gogo-protobuf/protoc-gen-gogoslick
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Expand Down
26 changes: 26 additions & 0 deletions service/history/api/update_workflow_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,36 @@ package api
import (
"context"

clockspb "go.temporal.io/server/api/clock/v1"
"go.temporal.io/server/common/definition"
"go.temporal.io/server/service/history/shard"
"go.temporal.io/server/service/history/workflow"
)

func GetAndUpdateWorkflowWithNew(
ctx context.Context,
reqClock *clockspb.VectorClock,
consistencyCheckFn MutableStateConsistencyPredicate,
workflowKey definition.WorkflowKey,
action UpdateWorkflowActionFunc,
newWorkflowFn func() (workflow.Context, workflow.MutableState, error),
shard shard.Context,
workflowConsistencyChecker WorkflowConsistencyChecker,
) (retError error) {
workflowContext, err := workflowConsistencyChecker.GetWorkflowContext(
ctx,
reqClock,
consistencyCheckFn,
workflowKey,
)
if err != nil {
return err
}
defer func() { workflowContext.GetReleaseFn()(retError) }()

return UpdateWorkflowWithNew(shard, ctx, workflowContext, action, newWorkflowFn)
}

func UpdateWorkflowWithNew(
shard shard.Context,
ctx context.Context,
Expand Down
Loading

0 comments on commit 44ee560

Please sign in to comment.