Skip to content

Commit

Permalink
fix: fixes child workflow options
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Ludden committed Jul 29, 2023
1 parent 5039511 commit ca8d05d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 94 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ Optional **CLI** with:
## Getting Started
1. Install [buf](https://docs.buf.build/installation)

1. Install this plugin by downloading the latest [release](https://github.com/cludden/protoc-gen-go-temporal/releases)
2. Install this plugin

2. Install Go protoc plugin
2a. Grab a binary for your OS from [the releases page](https://github.com/cludden/protoc-gen-go-temporal/releases) and place in your $PATH

2b. `go install github.com/cludden/protoc-gen-go-temporal/cmd/protoc-gen-go_temporal@<version>`

3. Install Go protoc plugin
```shell
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
```

3. Install this plugin

3a. Grab a binary for your OS from [the releases page](https://github.com/cludden/protoc-gen-go-temporal/releases) and place in your $PATH

3b. `go install github.com/cludden/protoc-gen-go-temporal/cmd/protoc-gen-go_temporal@<version>`

4. Initialize buf repository
```shell
mkdir proto && cd proto && buf init
Expand All @@ -74,7 +72,7 @@ mkdir proto && cd proto && buf init
```yaml
version: v1
deps:
- buf.build/cludden/protoc-gen-go-temporal@<version>
- buf.build/cludden/protoc-gen-go-temporal:<version>
```
6. Add plugin to `buf.gen.yaml` and exclude it from managed mode go prefix
Expand Down
10 changes: 5 additions & 5 deletions gen/example/v1/example_temporal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions gen/simple/simple_temporal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gen/temporal/v1/temporal.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 1 addition & 64 deletions internal/plugin/testclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (svc *Service) genTestClientImplQueryMethod(f *g.File, query string) {
hasInput := !isEmpty(handler.Input)
hasOutput := !isEmpty(handler.Output)

f.Commentf("%s executes a %s query", query, query)
f.Commentf("%s executes a %s query", query, svc.fqnForQuery(query))
f.Func().
Params(g.Id("c").Op("*").Id(toCamel("Test%sClient", svc.Service.GoName))).
Id(query).
Expand Down Expand Up @@ -108,69 +108,6 @@ func (svc *Service) genTestClientImplQueryMethod(f *g.File, query string) {
})
}

// genTestClientImplQueryDelayedMethod genereates a TestClient <Query>Delayed method
func (svc *Service) genTestClientImplQueryDelayedMethod(f *g.File, query string) {
handler := svc.methods[query]
hasInput := !isEmpty(handler.Input)
hasOutput := !isEmpty(handler.Output)
methodName := toCamel("%sDelayed", query)

f.Commentf("%s executes a %s query", methodName, svc.fqnForQuery(query))
f.Func().
Params(g.Id("c").Op("*").Id(toCamel("Test%sClient", svc.Service.GoName))).
Id(methodName).
ParamsFunc(func(args *g.Group) {
args.Id("ctx").Qual("context", "Context")
args.Id("workflowID").String()
args.Id("runID").String()
if hasInput {
args.Id("req").Op("*").Id(handler.Input.GoIdent.GoName)
}
}).
ParamsFunc(func(returnVals *g.Group) {
if hasOutput {
returnVals.Op("*").Id(handler.Output.GoIdent.GoName)
}
returnVals.Error()
}).
BlockFunc(func(fn *g.Group) {
fn.List(g.Id("val"), g.Err()).Op(":=").Id("c").Dot("env").Dot("QueryWorkflow").CallFunc(func(args *g.Group) {
args.Id(fmt.Sprintf("%sQueryName", query))
if hasInput {
args.Id("req")
}
})
fn.If(g.Err().Op("!=").Nil()).Block(
g.ReturnFunc(func(returnVals *g.Group) {
if hasOutput {
returnVals.Nil()
}
returnVals.Err()
}),
).Else().If(g.Op("!").Id("val").Dot("HasValue").Call()).Block(
g.ReturnFunc(func(returnVals *g.Group) {
if hasOutput {
returnVals.Nil()
}
returnVals.Nil()
}),
).Else().BlockFunc(func(bl *g.Group) {
if !hasOutput {
bl.Return(g.Nil())
} else {
bl.Var().Id("result").Id(handler.Output.GoIdent.GoName)
bl.If(g.Err().Op(":=").Id("val").Dot("Get").Call(g.Op("&").Id("result")), g.Err().Op("!=").Nil()).Block(
g.Return(
g.Nil(),
g.Err(),
),
)
bl.Return(g.Op("&").Id("result"), g.Nil())
}
})
})
}

// genTestClientImplSignalMethod genereates a TestClient <Signal> method
func (svc *Service) genTestClientImplSignalMethod(f *g.File, signal string) {
handler := svc.methods[signal]
Expand Down
4 changes: 2 additions & 2 deletions internal/plugin/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,10 @@ func (svc *Service) genWorkerWorkflowChildOptions(f *g.File, workflow string) {
g.Return(g.Op("&").Id(typeName).Values()),
)

f.Comment("WithStartWorkflowOptions sets the initial client.StartWorkflowOptions")
f.Comment("WithChildWorkflowOptions sets the initial client.StartWorkflowOptions")
f.Func().
Params(g.Id("opts").Op("*").Id(typeName)).
Id("WithStartWorkflowOptions").
Id("WithChildWorkflowOptions").
Params(g.Id("options").Qual(workflowPkg, "ChildWorkflowOptions")).
Op("*").Id(typeName).
Block(
Expand Down

0 comments on commit ca8d05d

Please sign in to comment.