Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Prerequisites:
* [context_propagation](context_propagation) - Use interceptors to propagate thread/fiber local data from clients
through workflows/activities.
* [dsl](dsl) - Demonstrates having a workflow interpret/invoke arbitrary steps defined in a DSL.
* [eager_wf_start](eager_wf_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity.
Copy link
Member

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 workflow here?

* [encryption](encryption) - Demonstrates how to make a codec for end-to-end encryption.
* [env_config](env_config) - Load client configuration from TOML files with programmatic overrides.
* [message_passing_simple](message_passing_simple) - Simple workflow that accepts signals, queries, and updates.
Expand Down
14 changes: 14 additions & 0 deletions eager_wf_start/README.md
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
16 changes: 16 additions & 0 deletions eager_wf_start/eager_workflow.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
11 changes: 11 additions & 0 deletions eager_wf_start/greeting_activity.rb
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
32 changes: 32 additions & 0 deletions eager_wf_start/run.rb
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually our samples have a <sample-name>-sample task queue name, so can we remove -task-queue and add -sample?


# 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}",
Copy link
Member

Choose a reason for hiding this comment

The 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