Skip to content

Commit 51212f8

Browse files
author
Chris Ludden
authored
feat: final v1 adjustments (#25)
BREAKING CHANGE: service level features have been moved to plugin options * feat: adds <Signal>ExternalAsync methods * feat: replaces service features with plugin options * fix: uses WorkflowRegistry and ActivityRegistry to ease test and replay integrations * chore: updates README
1 parent ca8d05d commit 51212f8

21 files changed

Lines changed: 495 additions & 676 deletions

File tree

README.md

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A protoc plugin for generating typed Temporal clients and workers in Go from protobuf schemas. This plugin allows Workflow authors to configure sensible defaults and guardrails, simplifies the implementation and testing of Temporal workers, and streamlines integration by providing typed client SDKs and a generated CLI application.
44

5-
<small>inspired by [github.com/cretz/temporal-sdk-go-advanced](https://github.com/cretz/temporal-sdk-go-advanced) and Jacob Legrone's excellent Replay talk on [Temporal @ Datadog](https://youtu.be/LxgkAoTSI8Q)</small>
5+
<small>inspired by [Chad Retz's](https://github.com/cretz/) awesome [github.com/cretz/temporal-sdk-go-advanced](https://github.com/cretz/temporal-sdk-go-advanced) and [Jacob LeGrone's](https://github.com/jlegrone/) excellent Replay talk on [Temporal @ Datadog](https://youtu.be/LxgkAoTSI8Q)</small>
66

77
**Table of Contents**
88

@@ -11,6 +11,7 @@ A protoc plugin for generating typed Temporal clients and workers in Go from pro
1111
- [Features](#features)
1212
- [Getting Started](#getting-started)
1313
- [Options](#options)
14+
- [Plugin Options](#plugin-options)
1415
- [Service Options](#service-options)
1516
- [Method Options](#method-options)
1617
- [ID Expressions](#id-expressions)
@@ -45,7 +46,7 @@ Generated **Worker** resources with:
4546
Optional **CLI** with:
4647
- commands for executing workflows, synchronously or asynchronously
4748
- commands for starting workflows with signals, synchronously or asynchronously
48-
- commands for querying existing workflwos
49+
- commands for querying existing workflows
4950
- commands for sending signals to existing workflows
5051
- typed flags for conventiently specifying workflow, query, and signal inputs
5152

@@ -90,7 +91,7 @@ plugins:
9091
opt: paths=source_relative
9192
- plugin: go_temporal
9293
out: gen
93-
opt: paths=source_relative
94+
opt: paths=source_relative,cli-enabled=true,cli-categories=true,workflow-update-enabled=true
9495
strategy: all
9596
```
9697

@@ -108,16 +109,12 @@ import "temporal/v1/temporal.proto";
108109
service Example {
109110
option (temporal.v1.service) = {
110111
task_queue: "example-v1"
111-
features: {
112-
cli: { enabled: true, categories: true }
113-
workflow_update: { enabled: true }
114-
}
115112
};
116113
117114
// CreateFoo creates a new foo operation
118115
rpc CreateFoo(CreateFooRequest) returns (CreateFooResponse) {
119116
option (temporal.v1.workflow) = {
120-
execution_timeout: { seconds: 3600 }
117+
execution_timeout: { seconds: 3600 } // foos can take awhile to create
121118
id_reuse_policy: WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
122119
id: 'create-foo/${!name.slug()}'
123120
query: { ref: 'GetFooProgress' }
@@ -201,7 +198,7 @@ message SetFooProgressRequest {
201198
buf generate
202199
```
203200

204-
9. Implement your activities, workflows
201+
9. Implement the required Workflow and Activity interfaces
205202

206203
```go
207204
package main
@@ -349,7 +346,7 @@ temporal server start-dev --dynamic-config-value "frontend.enableUpdateWorkflowE
349346
go run example/main.go worker
350347
```
351348

352-
1. Execute workflows, queries, signals, and updates
349+
11. Execute workflows, queries, signals, and updates
353350

354351
*with generated client*
355352
```go
@@ -404,7 +401,7 @@ COMMANDS:
404401
update-foo-progress UpdateFooProgress sets the current status of a CreateFoo operation
405402
WORKFLOWS:
406403
create-foo CreateFoo creates a new foo operation
407-
create-foo-with-set-foo-progress sends a SetFooProgress signal to a CreateFoo worklow, starting it if necessary
404+
create-foo-with-set-foo-progress sends a SetFooProgress signal to a CreateFoo workflow, starting it if necessary
408405
409406
GLOBAL OPTIONS:
410407
--help, -h show help (default: false)
@@ -440,11 +437,38 @@ $ go run example/main.go get-foo-progress -w create-foo/test
440437

441438
See [reference documentation](./docs/api/temporal/v1/api.md) for all Service and Method options supported by this plugin.
442439

440+
### Plugin Options
441+
442+
Plugin options are used to globally configure this plugin's behavior at runtime. They can be specified
443+
via:
444+
- protoc commaond line flags
445+
446+
```shell
447+
--go_temporal_opt=<flag>=<value>,<flag>=<value>
448+
```
449+
450+
- buf generate options
451+
452+
```yaml
453+
# buf.gen.yaml
454+
plugins:
455+
# ..
456+
- plugin: go_temporal
457+
out: gen
458+
opt: <flag>=<value>,<flag>=<value>
459+
strategy: all
460+
```
461+
462+
| flag | type | description | default |
463+
| :--- | :---: | :--- | :---: |
464+
| cli-enabled | `bool` | enables cli generation | `false` |
465+
| cli-categories | `bool` | enables cli categories | `true` |
466+
| workflow-update-enabled | `bool` | enables experimental workflow update | `false` |
467+
443468
### Service Options
444469

445470
| field | type | description |
446471
| :--- | :---: | :--- |
447-
| features | [Features](./docs/api/temporal/v1/api.md#serviceoptionsfeatures) | specifies settings for optional features |
448472
| namespace | `string` | default namespace for child workflows, activities |
449473
| task_queue | `string` | default task queue for all workflows, activities |
450474

@@ -559,7 +583,7 @@ require.Regexp(`^say-greeting/Howdy/Stranger/[a-f0-9-]{32}$`, run.ID())
559583

560584
## CLI
561585

562-
This plugin can optionally generate a configurable CLI using [github.com/urfave/cli/v2](https://github.com/urfave/cli/v2). To enable this functionality, use the corresponding [service option](#service-options). When enabled, this plugin will generate a CLI command for each workflow, start-workflow-with-signal, query, and signal. Each command provides typed flags for configuring the corresponding inputs and options.
586+
This plugin can optionally generate a configurable CLI using [github.com/urfave/cli/v2](https://github.com/urfave/cli/v2). To enable this functionality, use the corresponding [plugin option](#plugin-options). When enabled, this plugin will generate a CLI command for each workflow, start-workflow-with-signal, query, and signal. Each command provides typed flags for configuring the corresponding inputs and options.
563587

564588
```go
565589
package main
@@ -599,7 +623,7 @@ func main() {
599623

600624
## Test Client
601625

602-
The generated code includes a resources that are compatible with the Temporal Go SDK's [testsuite](https://pkg.go.dev/go.temporal.io/sdk@v1.23.1/testsuite) module. See [tests](./test/simple/main_test.go) for example usage.
626+
The generated code includes resources that are compatible with the Temporal Go SDK's [testsuite](https://pkg.go.dev/go.temporal.io/sdk@v1.23.1/testsuite) module. See [tests](./test/simple/main_test.go) for example usage.
603627

604628
**_Note:_** that all queries, signals, and udpates must be called via the test environment's `RegisterDelayedCallback` method prior to invoking the test client's synchronous `<Workflow>` method or an asynchronous workflow run's `Get` method.
605629

buf.gen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins:
99
opt: paths=source_relative
1010
- plugin: go_temporal
1111
out: gen
12-
opt: paths=source_relative
12+
opt: paths=source_relative,cli-enabled=true,cli-categories=true,workflow-update-enabled=true
1313
strategy: all
1414
- plugin: doc
1515
out: docs/api

cmd/protoc-gen-go_temporal/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ func main() {
2323
return
2424
}
2525

26-
p := plugin.Plugin{
27-
Commit: commit,
28-
Version: version,
29-
}
26+
p := plugin.New(commit, version)
3027

3128
opts := protogen.Options{
3229
ParamFunc: p.Param,

docs/api/temporal/v1/api.md

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
- [QueryOptions](#temporal-v1-QueryOptions)
99
- [RetryPolicy](#temporal-v1-RetryPolicy)
1010
- [ServiceOptions](#temporal-v1-ServiceOptions)
11-
- [ServiceOptions.Features](#temporal-v1-ServiceOptions-Features)
12-
- [ServiceOptions.Features.CLI](#temporal-v1-ServiceOptions-Features-CLI)
13-
- [ServiceOptions.Features.WorkflowUpdate](#temporal-v1-ServiceOptions-Features-WorkflowUpdate)
1411
- [SignalOptions](#temporal-v1-SignalOptions)
1512
- [UpdateOptions](#temporal-v1-UpdateOptions)
1613
- [WorkflowOptions](#temporal-v1-WorkflowOptions)
@@ -107,7 +104,6 @@ shared by all methods
107104

108105
| Field | Type | Label | Description |
109106
| ----- | ---- | ----- | ----------- |
110-
| features | [ServiceOptions.Features](#temporal-v1-ServiceOptions-Features) | | Service-level features |
111107
| namespace | [string](#string) | | Default namespace for child workflows, activities |
112108
| task_queue | [string](#string) | | Default task queue for all workflows, activities |
113109

@@ -116,53 +112,6 @@ shared by all methods
116112

117113

118114

119-
<a name="temporal-v1-ServiceOptions-Features"></a>
120-
121-
### ServiceOptions.Features
122-
123-
124-
125-
| Field | Type | Label | Description |
126-
| ----- | ---- | ----- | ----------- |
127-
| cli | [ServiceOptions.Features.CLI](#temporal-v1-ServiceOptions-Features-CLI) | | Enable experimental CLI features |
128-
| workflow_update | [ServiceOptions.Features.WorkflowUpdate](#temporal-v1-ServiceOptions-Features-WorkflowUpdate) | | |
129-
130-
131-
132-
133-
134-
135-
<a name="temporal-v1-ServiceOptions-Features-CLI"></a>
136-
137-
### ServiceOptions.Features.CLI
138-
139-
140-
141-
| Field | Type | Label | Description |
142-
| ----- | ---- | ----- | ----------- |
143-
| enabled | [bool](#bool) | | |
144-
| categories | [bool](#bool) | | |
145-
146-
147-
148-
149-
150-
151-
<a name="temporal-v1-ServiceOptions-Features-WorkflowUpdate"></a>
152-
153-
### ServiceOptions.Features.WorkflowUpdate
154-
155-
156-
157-
| Field | Type | Label | Description |
158-
| ----- | ---- | ----- | ----------- |
159-
| enabled | [bool](#bool) | | |
160-
161-
162-
163-
164-
165-
166115
<a name="temporal-v1-SignalOptions"></a>
167116

168117
### SignalOptions

example/proto/example/v1/example.proto

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import "temporal/v1/temporal.proto";
88
service Example {
99
option (temporal.v1.service) = {
1010
task_queue: "example-v1"
11-
features: {
12-
cli: { enabled: true, categories: true }
13-
workflow_update: { enabled: true }
14-
}
1511
};
1612

1713
// CreateFoo creates a new foo operation

gen/example/v1/example.pb.go

Lines changed: 15 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/example/v1/example_temporal.pb.go

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)