Skip to content

Commit

Permalink
ctx added
Browse files Browse the repository at this point in the history
  • Loading branch information
yedf2 committed Feb 12, 2023
1 parent f4cd29a commit e809fb5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ req := busi.BusiReq{Amount: 30, TransInResult: ""}
data, err := proto.Marshal(&req)

// Execute workflow
err = workflow.Execute(wfName, shortuuid.New(), data)
_, err = workflow.ExecuteCtx(wfName, shortuuid.New(), data)
logger.Infof("result of workflow.Execute is: %v", err)

```
Expand Down
31 changes: 12 additions & 19 deletions client/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,32 @@ func Register2(name string, handler WfFunc2, custom ...func(wf *Workflow)) error
return defaultFac.register(name, handler, custom...)
}

// Execute is the same as ExecuteCtx, but with context.Background
func Execute(name string, gid string, data []byte) error {
return ExecuteCtx(context.Background(), name, gid, data)
}

// ExecuteCtx will execute a workflow with the gid and specified params
// if the workflow with the gid does not exist, then create a new workflow and execute it
// if the workflow with the gid exists, resume to execute it
func ExecuteCtx(ctx context.Context, name string, gid string, data []byte) error {
_, err := defaultFac.execute(ctx, name, gid, data)
func ExecuteCtx(ctx context.Context, name string, gid string, data []byte) ([]byte, error) {
return defaultFac.execute(ctx, name, gid, data)
}

// Execute is the same as ExecuteCtx, but with context.Background
// Deprecated: use ExecuteCtx instaead
func Execute(name string, gid string, data []byte) error {
_, err := ExecuteCtx(context.Background(), name, gid, data)
return err
}

// Execute2 is the same as Execute, but workflow func can return result
// Deprecated: use ExecuteCtx instaead
func Execute2(name string, gid string, data []byte) ([]byte, error) {
return Execute2Ctx(context.Background(), name, gid, data)
}

// Execute2Ctx is the same as Execute2, but with context.Background
func Execute2Ctx(ctx context.Context, name string, gid string, data []byte) ([]byte, error) {
return defaultFac.execute(ctx, name, gid, data)
return ExecuteCtx(context.Background(), name, gid, data)
}

// ExecuteByQS is like Execute, but name and gid will be obtained from qs
// Deprecated: use ExecuteCtx instaead
func ExecuteByQS(qs url.Values, body []byte) error {
return ExecuteByQSCtx(context.Background(), qs, body)
}

// ExecuteByQSCtx is the same as ExecuteByQS, but with context.Background
func ExecuteByQSCtx(ctx context.Context, qs url.Values, body []byte) error {
name := qs.Get("op")
gid := qs.Get("gid")
_, err := defaultFac.execute(ctx, name, gid, body)
_, err := ExecuteCtx(context.Background(), name, gid, body)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion helper/README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ req := busi.BusiReq{Amount: 30, TransInResult: ""}
data, err := proto.Marshal(&req)

// Execute workflow
err = workflow.Execute(wfName, shortuuid.New(), data)
_, err = workflow.ExecuteCtx(wfName, shortuuid.New(), data)
logger.Infof("result of workflow.Execute is: %v", err)

```
Expand Down

0 comments on commit e809fb5

Please sign in to comment.