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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +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.
* [eager_workflow_start](eager_workflow_start) - Demonstrates Eager Workflow Start to reduce latency for workflows that start with a local activity.
* [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
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ You can read more about Eager Workflow Start in our:

To run, first see [README.md](../README.md) for prerequisites. Then run the sample via:

bundle exec ruby eager_wf_start/run.rb
bundle exec ruby run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'temporalio/workflow'
require_relative 'greeting_activity'

module EagerWfStart
module EagerWorkflowStart
class EagerWorkflow < Temporalio::Workflow::Definition
def execute(name)
Temporalio::Workflow.execute_local_activity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'temporalio/activity'

module EagerWfStart
module EagerWorkflowStart
class GreetingActivity < Temporalio::Activity::Definition
def execute(name)
"Hello, #{name}!"
Expand Down
10 changes: 5 additions & 5 deletions eager_wf_start/run.rb → eager_workflow_start/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
require_relative 'eager_workflow'
require_relative 'greeting_activity'

TASK_QUEUE = 'eager-wf-start-task-queue'
TASK_QUEUE = 'eager-workflow-start-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]
workflows: [EagerWorkflowStart::EagerWorkflow],
activities: [EagerWorkflowStart::GreetingActivity]
)

# Run worker in the background while we start the workflow
worker.run do
handle = client.start_workflow(
EagerWfStart::EagerWorkflow,
EagerWorkflowStart::EagerWorkflow,
'Temporal',
id: "eager-workflow-id-#{SecureRandom.uuid}",
id: 'eager-workflow-start-sample-workflow-id',
task_queue: TASK_QUEUE,
request_eager_start: true
)
Expand Down
41 changes: 41 additions & 0 deletions test/eager_workflow_start/eager_workflow_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require 'test'
require 'eager_workflow_start/eager_workflow'
require 'securerandom'
require 'temporalio/testing'
require 'temporalio/worker'

module EagerWorkflowStart
class EagerWorkflowTest < Test
def test_workflow
# Run test server until completion of the block
Temporalio::Testing::WorkflowEnvironment.start_local(
dev_server_download_version: 'latest'
) do |env|
# Run worker until completion of the block
worker = Temporalio::Worker.new(
client: env.client,
task_queue: "tq-#{SecureRandom.uuid}",
activities: [GreetingActivity],
workflows: [EagerWorkflow]
)
worker.run do
# Start workflow with eager start
handle = env.client.start_workflow(
EagerWorkflow,
'Temporal',
id: "wf-#{SecureRandom.uuid}",
task_queue: worker.task_queue,
request_eager_start: true
)
assert_equal('Hello, Temporal!', handle.result)

# Verify workflow was eagerly executed
started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes)
assert(started_event.workflow_execution_started_event_attributes.eager_execution_accepted)
end
end
end
end
end