Skip to content

Commit 6dc0df0

Browse files
committed
Add ContinueAsNew workflow input method
1 parent 4d2c8f3 commit 6dc0df0

41 files changed

Lines changed: 9786 additions & 4064 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Added
2+
body: Add ContinueAsNew workflow input method
3+
time: 2025-12-24T13:45:51.232748-07:00
4+
custom:
5+
Author: cludden
6+
PullRequest: "139"

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fetch-depth: 0
1616
- uses: actions/setup-node@v4
1717
with:
18-
node-version: 18
18+
node-version: 25
1919
cache: npm
2020
cache-dependency-path: ./docs/package-lock.json
2121

buf.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ deps:
88
commit: 76b304caf5984a3a978e9565ea71a2ac
99
digest: b5:72c441888d19ff57f824b75f59aba0346a16bfa3ef5da83a5da21c614f0763764e1d37511312dc82f54e1dae5937a5829e8c2c1b7f806c983046bbf624b04ac2
1010
- name: buf.build/cludden/protoc-gen-go-temporal
11-
commit: 82d9a66e89c24dc492936b1a29a7f605
12-
digest: b5:8f3671c822204f747a0ac55cde7c3f2b657d6bfc5ad14cc7057178741f258eac0d7f316f6f09a4689a8acf6b2eb746b239dcd87b72964bdc8220b368a046c006
11+
commit: 1d9b7e091b284c519a6ef7b799129547
12+
digest: b5:00d49833c1e03e0be1935743d5d279b1666b5725157dd6813b481d38a4a7c7abe5b64a7f78895672c6a458365486923d127cd4192cf8659fa931f520bbb48d48
1313
- name: buf.build/envoyproxy/protoc-gen-validate
1414
commit: daf171c6cdb54629b5f51e345a79e4dd
1515
digest: b5:c745e1521879f43740230b1df673d0729f55704efefdcfc489d4a0a2d40c92a26cacfeab62813403040a8b180142d53b398c7ca784a065e43823605ee49681de
1616
- name: buf.build/googleapis/googleapis
1717
commit: 28151c0d0a1641bf938a7672c500e01d
1818
digest: b5:93b70089baa4fc05a92d3e52db91a4b7812db3b57b9664f6cb301733938cb630e377a938e8a56779388171c749c1d42a2e9a6c6230f2ff45f127a8102a6a27d0
1919
- name: buf.build/temporalio/api
20-
commit: 54001d31c68a41dda97490fe01642301
21-
digest: b5:5d08f3a5ae4f6941df4c84b6bb33c3e1e93f3cb28c7ef7b09277148c574b9edcee4999662b81efd0a62ab70c92245d460c1bffafefeb7e54dbd5aa328d239175
20+
commit: ff85f03bb36a44b1b80c0c3b9f44637e
21+
digest: b5:d37fb2d41b87376e57da251fe569d7ee659a9723eee957f90c406ecff4995dde8e6fa5d1210b776afd78c28b53c8b8490cd6daa79a481f4734744c62c41b81c0

docs/docs/guides/workflows.mdx

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,166 @@ service Example {
5151
</TabItem>
5252
</Tabs>
5353

54+
## Workflow Input
55+
56+
Every workflow definition generates a `<Workflow>WorkflowInput` struct that contains the workflow input and any registered signals. It is passed to the workflow constructor and should be embedded in the workflow struct to allow for query and update handlers to access the workflow input.
57+
58+
### Req
59+
60+
If the workflow specifies a non-empty input message type, the generated `<Workflow>WorkflowInput` struct will include a `Req` field that contains a reference to the workflow input.
61+
62+
<Tabs>
63+
<TabItem value="implementation-go" label="Go">
64+
```go title="example.go"
65+
package example
66+
67+
import (
68+
examplev1 "path/to/gen/example/v1"
69+
)
70+
71+
type HelloWorkflow struct {
72+
*examplev1.HelloWorkflowInput
73+
}
74+
75+
func (w *HelloWorkflow) Execute(ctx workflow.Context) (*examplev1.HelloOutput, error) {
76+
return &examplev1.HelloOutput{
77+
Result: fmt.Sprintf("Hello %s!", w.Req.GetName()),
78+
}, nil
79+
}
80+
```
81+
</TabItem>
82+
<TabItem value="implementation-schema" label="Schema">
83+
```protobuf title="example.proto"
84+
syntax="proto3";
85+
86+
package example.v1;
87+
88+
import "temporal/v1/temporal.proto";
89+
90+
service Example {
91+
rpc Hello(HelloInput) returns (HelloOutput) {
92+
option (temporal.v1.workflow) = {};
93+
}
94+
}
95+
96+
message HelloInput {
97+
string name = 1;
98+
}
99+
100+
message HelloOutput {
101+
string result = 1;
102+
}
103+
```
104+
</TabItem>
105+
</Tabs>
106+
107+
### \{Signal\}
108+
109+
If the workflow definition specifies one or more signals, the generated `<Workflow>WorkflowInput` struct will include a corresponding`{Signal}` field for each registered signalthat contains a reference to the [typed signal value](/docs/guides/signals).
110+
111+
<Tabs>
112+
<TabItem value="implementation-go" label="Go">
113+
```go title="example.go"
114+
package example
115+
116+
import (
117+
examplev1 "path/to/gen/example/v1"
118+
)
119+
120+
type HelloWorkflow struct {
121+
*examplev1.HelloWorkflowInput
122+
}
123+
124+
func (w *HelloWorkflow) Execute(ctx workflow.Context) (*examplev1.HelloOutput, error) {
125+
bar, _ := w.Bar.Receive(ctx)
126+
return &examplev1.HelloOutput{
127+
Result: fmt.Sprintf("%s %s!", bar.GetMessage(), w.Req.GetName()),
128+
}, nil
129+
}
130+
```
131+
</TabItem>
132+
<TabItem value="implementation-schema" label="Schema">
133+
```protobuf title="example.proto"
134+
syntax="proto3";
135+
136+
package example.v1;
137+
138+
import "google/protobuf/empty.proto";
139+
import "temporal/v1/temporal.proto";
140+
141+
service Example {
142+
rpc Hello(HelloInput) returns (HelloOutput) {
143+
option (temporal.v1.workflow) = {
144+
signal: {ref: "Bar"}
145+
};
146+
}
147+
148+
rpc Bar(BarInput) returns (google.protobuf.Empty) {
149+
option (temporal.v1.signal) = {};
150+
}
151+
}
152+
153+
message HelloInput {
154+
string name = 1;
155+
}
156+
157+
message HelloOutput {
158+
string result = 1;
159+
}
160+
161+
message BarInput {
162+
string message = 1;
163+
}
164+
```
165+
</TabItem>
166+
</Tabs>
167+
168+
### ContinueAsNew
169+
170+
The generated `<Workflow>WorkflowInput` struct includes a `ContinueAsNew` method that returns an appropriately configured `ContinueAsNewError`. This method is used to continue a workflow as a new workflow execution.
171+
172+
<Tabs>
173+
<TabItem value="implementation-go" label="Go">
174+
```go title="example.go"
175+
package example
176+
177+
import (
178+
examplev1 "path/to/gen/example/v1"
179+
)
180+
181+
type HelloWorkflow struct {
182+
*examplev1.HelloWorkflowInput
183+
}
184+
185+
func (w *HelloWorkflow) Execute(ctx workflow.Context) (*examplev1.HelloOutput, error) {
186+
if workflow.GetInfo(ctx).GetContinueAsNewSuggested() {
187+
return w.ContinueAsNew(ctx, &examplev1.HelloInput{
188+
Name: strings.ToUpper(w.Req.GetName()),
189+
})
190+
}
191+
return &examplev1.HelloOutput{
192+
Result: fmt.Sprintf("Hello %s!", w.Req.GetName()),
193+
}, nil
194+
}
195+
```
196+
</TabItem>
197+
<TabItem value="implementation-schema" label="Schema">
198+
```protobuf title="example.proto"
199+
syntax="proto3";
200+
201+
package example.v1;
202+
203+
import "temporal/v1/temporal.proto";
204+
205+
service Example {
206+
rpc Hello(HelloInput) returns (HelloOutput) {
207+
option (temporal.v1.workflow) = {};
208+
}
209+
}
210+
```
211+
</TabItem>
212+
</Tabs>
213+
54214
## Parameters
55215

56216
Every `<Workflow>Workflow` interface includes an `Execute` method that defines the workflow entrypoint. The signature of this method varies based on whether or not the workflow specifies a non-empty output message type.

0 commit comments

Comments
 (0)