Skip to content

Commit 36f14a7

Browse files
author
Christopher Ludden
committed
fixup! feat: unnests default_options, makes opts optional
1 parent 8a05299 commit 36f14a7

File tree

3 files changed

+337
-39
lines changed

3 files changed

+337
-39
lines changed

README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
# protoc-gen-go-temporal
22

3-
a protoc plugin for generating temporal clients and workers in Go from protobuf schemas
3+
a protoc plugin for generating typed temporal clients and workers in Go from protobuf schemas
44

55
inspired by [github.com/cretz/temporal-sdk-go-advanced](https://github.com/cretz/temporal-sdk-go-advanced)
66

77
**Features:**
8-
- define default `client.StartWorkflowOptions`, `workflow.ActivityOptions`, `workflow.ChildWorkflowOptions` including:
9-
- default workflow ids that can leverage inputs via [Bloblang ID expressions](#id-expressions)
10-
- default timeouts, retry policies, id reuse policies
11-
- generates typed client and workflow helpers
12-
- generates client with methods for executing workflows, queries, signals
13-
- generates methods for calling activities and local activities from workflows
14-
- generates methods for executing child workflows and signalling external workflows
8+
- typed client with:
9+
- methods for executing workflows, queries, signals, and updates
10+
- methods for cancelling or terminating workflows
11+
- default `client.StartWorkflowOptions` and `client.UpdateWorkflowWithOptionsRequest`
12+
- dynamic workflow and update ids via [Bloblang expressions](#id-expressions)
13+
- default timeouts, id reuse policies, wait policies
14+
- typed worker helpers with:
15+
- functions for calling activities and local activities from workflows
16+
- functions for executing child workflows and signalling external workflows
17+
- default `workflow.ActivityOptions`, `workflow.ChildWorkflowOptions`
18+
- default timeouts, parent cose policies, retry policies
1519

1620
## Getting Started
1721
1. Install [buf](https://docs.buf.build/installation)
22+
23+
1. Install this plugin by downloading the latest [release](https://github.com/cludden/protoc-gen-go-temporal/releases)
1824

19-
2. Install protoc plugins
25+
1. Install go protoc plugins if necessary
2026
```shell
2127
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
2228
go install github.com/cludden/protoc-gen-go-temporal/cmd/protoc-gen-go_temporal@latest
2329
```
2430

25-
3. Initialize buf repository
31+
1. Initialize buf repository
2632
```shell
2733
mkdir proto && cd proto && buf init
2834
```
2935

30-
4. Add dependency to `buf.yaml`
36+
1. Add dependency to `buf.yaml`
3137
```yaml
3238
version: v1
3339
deps:
34-
- buf.build/cludden/protoc-gen-go-temporal
40+
- buf.build/cludden/protoc-gen-go-temporal:<release>
3541
```
3642
37-
5. Add plugin to `buf.gen.yaml` and exclude it from managed mode go prefix
43+
1. Add plugin to `buf.gen.yaml` and exclude it from managed mode go prefix
3844
```yaml
3945
version: v1
4046
managed:
@@ -53,8 +59,8 @@ plugins:
5359
strategy: all
5460
```
5561

56-
6. Define your service
57-
<small><b><i>note:</i></b> see [advanced](#advanced), [example](./example/), and [test](./test/) for more details on generated code and usage</small>
62+
1. Define your service
63+
<small><b><i>note:</i></b> see [advanced](#advanced), [example](./example/), and [test](./test) for more details on generated code and usage</small>
5864

5965
```protobuf
6066
syntax="proto3";
@@ -73,10 +79,8 @@ service Example {
7379
// HelloWorld defines a workflow with a single activity of the same name
7480
rpc HelloWorld(HelloWorldRequest) returns (HelloWorldResponse) {
7581
option (temporal.v1.workflow) = {
76-
default_options {
77-
id: 'hello-world/${! uuid_v4() }'
78-
execution_timeout: { seconds: 30 }
79-
}
82+
id: 'hello-world/${! uuid_v4() }'
83+
execution_timeout: { seconds: 30 }
8084
};
8185
option (temporal.v1.activity) = {};
8286
}
@@ -95,12 +99,12 @@ message HelloWorldResponse {
9599
}
96100
```
97101

98-
7. Generate temporal worker and client types, methods, interfaces, and functions
102+
1. Generate temporal worker and client types, methods, interfaces, and functions
99103
```shell
100104
buf generate
101105
```
102106

103-
8. Implement your activities, workflows
107+
1. Implement your activities, workflows
104108

105109
```go
106110
package main
@@ -169,14 +173,12 @@ func main() {
169173
170174
// initialize generated client and execute workflow
171175
example := examplev1.NewClient(c)
172-
resp, err := example.HelloWorld(context.Background(), nil, &examplev1.HelloWorldRequest{})
176+
resp, err := example.HelloWorld(context.Background(), &examplev1.HelloWorldRequest{})
173177
if err != nil {
174178
log.Fatalf("error executing %s workflow: %v", examplev1.HelloWorldWorkflowName, err)
175179
}
176180
log.Printf("hello world successful: %sv", resp)
177181
}
178-
179-
180182
```
181183

182184
### Advanced
@@ -207,11 +209,9 @@ service Mutex {
207209
// Mutex provides a mutex over a shared resource
208210
rpc Mutex(MutexRequest) returns (google.protobuf.Empty) {
209211
option (temporal.v1.workflow) = {
210-
default_options {
211-
id: 'mutex/${!resource}'
212-
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
213-
execution_timeout: { seconds: 3600 }
214-
}
212+
id: 'mutex/${!resource}'
213+
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
214+
execution_timeout: { seconds: 3600 }
215215
signal: { ref: 'AcquireLease', start: true }
216216
signal: { ref: 'RenewLease' }
217217
signal: { ref: 'RevokeLease' }
@@ -223,11 +223,9 @@ service Mutex {
223223
// a Mutex workflow to prevent concurrent access to a shared resource
224224
rpc SampleWorkflowWithMutex(SampleWorkflowWithMutexRequest) returns (SampleWorkflowWithMutexResponse) {
225225
option (temporal.v1.workflow) = {
226-
default_options {
227-
id: 'sample-workflow-with-mutex/${!resource}/${!uuid_v4()}'
228-
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
229-
execution_timeout: { seconds: 3600 }
230-
}
226+
id: 'sample-workflow-with-mutex/${!resource}/${!uuid_v4()}'
227+
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
228+
execution_timeout: { seconds: 3600 }
231229
signal: { ref: 'LeaseAcquired' }
232230
};
233231
}
@@ -435,7 +433,7 @@ func (wf *SampleWorkflowWithMutexWorkflow) Execute(ctx workflow.Context) (resp *
435433
wf.log.Info("started")
436434
437435
wf.log.Info("requesting lease")
438-
if err := mutexv1.Mutex(ctx, nil, &mutexv1.MutexRequest{Resource: wf.Req.GetResource()}).Get(ctx); err != nil {
436+
if err := mutexv1.Mutex(ctx, &mutexv1.MutexRequest{Resource: wf.Req.GetResource()}).Get(ctx); err != nil {
439437
return nil, fmt.Errorf("error requesting lease: %w", err)
440438
}
441439
@@ -479,10 +477,10 @@ func (a *Activites) Mutex(ctx context.Context, req *mutexv1.MutexRequest) error
479477

480478
## Options
481479

482-
See [temporal.proto](proto/temporal/v1/temporal.proto) for Service and Method options supported by this plugin.
480+
See [docs](./docs/) for Service and Method options supported by this plugin.
483481

484482
### ID Expressions
485-
Workflows can specify a default workflow ID that support [Bloblang](https://www.benthos.dev/docs/guides/bloblang/about) ID expressions. The expression is evaluated against a JSON-like input structure, allowing it to leverage fields from the Workflow's input parameter as well as Bloblang's native [functions](https://www.benthos.dev/docs/guides/bloblang/functions) and [methods](https://www.benthos.dev/docs/guides/bloblang/methods).
483+
**Workflows** and **Updates** can specify a default workflow ID as a [Bloblang](https://www.benthos.dev/docs/guides/bloblang/about) ID expression. The expression is evaluated against a JSON-like input structure, allowing it to leverage fields from the input parameter, as well as Bloblang's native [functions](https://www.benthos.dev/docs/guides/bloblang/functions) and [methods](https://www.benthos.dev/docs/guides/bloblang/methods).
486484

487485
**Example**
488486

@@ -516,10 +514,10 @@ Can be used like so:
516514
c, _ := client.Dial(client.Options{})
517515
example := examplev1.NewClient(c)
518516
519-
run, _ := example.ExecuteSayGreeting(context.Background(), nil, &examplev1.SayGreetingRequest{})
517+
run, _ := example.ExecuteSayGreeting(context.Background(), &examplev1.SayGreetingRequest{})
520518
require.Regexp(`^say-greeting/Hello/World/[a-f0-9-]{32}$`, run.ID())
521519

522-
run, _ := example.ExecuteSayGreeting(context.Background(), nil, &examplev1.SayGreetingRequest{
520+
run, _ := example.ExecuteSayGreeting(context.Background(), &examplev1.SayGreetingRequest{
523521
Greeting: "howdy",
524522
Subject: "stranger",
525523
})

0 commit comments

Comments
 (0)