-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add eager workflow start sample #334
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ vendor/ | |
# Executables produced by temporal-go-samples repo | ||
bin/ | ||
.fossa.yml | ||
*~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
### Eager Workflow Start Sample | ||
|
||
Eager Workflow Start (EWS) is an experimental latency optimization with the goal of reducing the time it takes to start a workflow. | ||
|
||
When the starter and worker are collocated and aware of each other, they can interact while bypassing the server, saving a few time-intensive operations. | ||
|
||
Here we modify the `helloworld` sample, ensuring that starter and worker run in the same process, and share the client. Also, the request eager mode flag is set in the start workflow options. | ||
|
||
### Steps to run this sample: | ||
|
||
1) Run a [Temporal service](https://github.com/temporalio/samples-go/tree/main/#how-to-use) with eager workflow start enabled by a dynamic config value. | ||
``` | ||
temporal server start-dev --dynamic-config-value system.enableEagerWorkflowStart=true | ||
``` | ||
2) Run the following command to start the combined worker and example | ||
``` | ||
go run eager-workflow-start/main.go | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/pborman/uuid" | ||
"go.temporal.io/sdk/client" | ||
"go.temporal.io/sdk/worker" | ||
|
||
"github.com/temporalio/samples-go/helloworld" | ||
) | ||
|
||
const taskQueueName = "eager_wf_start" | ||
|
||
func main() { | ||
// 1. Create the shared client. | ||
c, err := client.Dial(client.Options{}) | ||
if err != nil { | ||
log.Fatalln("Unable to create client", err) | ||
} | ||
defer c.Close() | ||
|
||
// 2. Start the worker in a non-blocking manner before the workflow. | ||
workerOptions := worker.Options{ | ||
OnFatalError: func(err error) { log.Fatalln("Worker error", err) }, | ||
} | ||
w := worker.New(c, taskQueueName, workerOptions) | ||
w.RegisterWorkflow(helloworld.Workflow) | ||
w.RegisterActivity(helloworld.Activity) | ||
err = w.Start() | ||
if err != nil { | ||
log.Fatalln("Unable to start worker", err) | ||
} | ||
defer w.Stop() | ||
|
||
workflowOptions := client.StartWorkflowOptions{ | ||
ID: "eager_wf" + uuid.New(), | ||
TaskQueue: taskQueueName, | ||
|
||
// 3. Set this flag to true to enable EWS. | ||
EnableEagerStart: true, | ||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrmm, wonder if it's a bit much to have an entire sample just to set true on a single workflow option (I wouldn't expect separate samples for every other start option). But I don't mind I guess if it makes sense generally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is worth making a sample for since it also shows you have to reuse the client |
||
} | ||
|
||
// 4. Reuse the client connection. | ||
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, | ||
helloworld.Workflow, "Temporal") | ||
if err != nil { | ||
log.Fatalln("Unable to execute workflow", err) | ||
} | ||
|
||
// 5. Wait for workflow completion. | ||
var result string | ||
err = we.Get(context.Background(), &result) | ||
if err != nil { | ||
log.Fatalln("Unable to get workflow result", err) | ||
} | ||
log.Println("Workflow result:", result) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a short description here about eager workflow start and how the sample works like some of our other samples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done