From e809fb56ed432057d4524502d50c6cc30b843b99 Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Sun, 12 Feb 2023 11:33:31 +0800 Subject: [PATCH] ctx added --- README.md | 2 +- client/workflow/workflow.go | 31 ++++++++++++------------------- helper/README-en.md | 2 +- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 2fc52d3e6..42c817122 100644 --- a/README.md +++ b/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) ``` diff --git a/client/workflow/workflow.go b/client/workflow/workflow.go index 02b38a29b..3abed6a10 100644 --- a/client/workflow/workflow.go +++ b/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 } diff --git a/helper/README-en.md b/helper/README-en.md index 2fc52d3e6..42c817122 100644 --- a/helper/README-en.md +++ b/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) ```