-
Notifications
You must be signed in to change notification settings - Fork 6
Eager workflow start sample #55
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
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Eager Workflow Start | ||
|
|
||
| This sample shows how to create a workflow that uses Eager Workflow Start. | ||
|
|
||
| The target use case is workflows whose first task needs to execute quickly (ex: payment verification in an online checkout workflow). That work typically can't be done directly in the workflow (ex: using web APIs, databases, etc.), and also needs to avoid the overhead of dispatching another task. Using a Local Activity suffices both needs, which this sample demonstrates. | ||
|
|
||
| You can read more about Eager Workflow Start in our: | ||
|
|
||
| - [Eager Workflow Start blog](https://temporal.io/blog/improving-latency-with-eager-workflow-start) | ||
| - [Worker Performance Docs](https://docs.temporal.io/develop/worker-performance#eager-workflow-start) | ||
|
|
||
| To run, first see [README.md](../README.md) for prerequisites. Then run the sample via: | ||
|
|
||
| bundle exec ruby eager_wf_start/run.rb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'temporalio/workflow' | ||
| require_relative 'greeting_activity' | ||
|
|
||
| module EagerWfStart | ||
| class EagerWorkflow < Temporalio::Workflow::Definition | ||
| def execute(name) | ||
| Temporalio::Workflow.execute_local_activity( | ||
| GreetingActivity, | ||
| name, | ||
| schedule_to_close_timeout: 5 | ||
| ) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'temporalio/activity' | ||
|
|
||
| module EagerWfStart | ||
| class GreetingActivity < Temporalio::Activity::Definition | ||
| def execute(name) | ||
| "Hello, #{name}!" | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'securerandom' | ||
| require 'temporalio/client' | ||
| require 'temporalio/worker' | ||
| require_relative 'eager_workflow' | ||
| require_relative 'greeting_activity' | ||
|
|
||
| TASK_QUEUE = 'eager-wf-start-task-queue' | ||
|
Member
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. Usually our samples have a |
||
|
|
||
| # Note that the worker and client run in the same process and share the same client connection | ||
| client = Temporalio::Client.connect('localhost:7233', 'default') | ||
|
|
||
| worker = Temporalio::Worker.new( | ||
| client:, | ||
| task_queue: TASK_QUEUE, | ||
| workflows: [EagerWfStart::EagerWorkflow], | ||
| activities: [EagerWfStart::GreetingActivity] | ||
| ) | ||
|
|
||
| # Run worker in the background while we start the workflow | ||
| worker.run do | ||
| handle = client.start_workflow( | ||
| EagerWfStart::EagerWorkflow, | ||
| 'Temporal', | ||
| id: "eager-workflow-id-#{SecureRandom.uuid}", | ||
|
Member
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. Our samples have traditionally not used random identifiers |
||
| task_queue: TASK_QUEUE, | ||
| request_eager_start: true | ||
| ) | ||
|
|
||
| puts handle.result | ||
| end | ||
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.
Similar to .NET suggestion, can we use the full term
workflowhere?