Browse Source

ctx added

alpha v1.17.0
yedf2 4 years ago
parent
commit
e809fb56ed
  1. 2
      README.md
  2. 31
      client/workflow/workflow.go
  3. 2
      helper/README-en.md

2
README.md

@ -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)
```

31
client/workflow/workflow.go

@ -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
}

2
helper/README-en.md

@ -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)
```

Loading…
Cancel
Save