diff --git a/README.md b/README.md index 356ffba..7c8376f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/eager_wf_start/README.md b/eager_workflow_start/README.md similarity index 95% rename from eager_wf_start/README.md rename to eager_workflow_start/README.md index 8603375..077e639 100644 --- a/eager_wf_start/README.md +++ b/eager_workflow_start/README.md @@ -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 diff --git a/eager_wf_start/eager_workflow.rb b/eager_workflow_start/eager_workflow.rb similarity index 92% rename from eager_wf_start/eager_workflow.rb rename to eager_workflow_start/eager_workflow.rb index 8b64134..def7861 100644 --- a/eager_wf_start/eager_workflow.rb +++ b/eager_workflow_start/eager_workflow.rb @@ -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( diff --git a/eager_wf_start/greeting_activity.rb b/eager_workflow_start/greeting_activity.rb similarity index 87% rename from eager_wf_start/greeting_activity.rb rename to eager_workflow_start/greeting_activity.rb index 1d61bce..9b312c8 100644 --- a/eager_wf_start/greeting_activity.rb +++ b/eager_workflow_start/greeting_activity.rb @@ -2,7 +2,7 @@ require 'temporalio/activity' -module EagerWfStart +module EagerWorkflowStart class GreetingActivity < Temporalio::Activity::Definition def execute(name) "Hello, #{name}!" diff --git a/eager_wf_start/run.rb b/eager_workflow_start/run.rb similarity index 72% rename from eager_wf_start/run.rb rename to eager_workflow_start/run.rb index 76b46d5..677040f 100644 --- a/eager_wf_start/run.rb +++ b/eager_workflow_start/run.rb @@ -6,7 +6,7 @@ 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') @@ -14,16 +14,16 @@ 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 ) diff --git a/test/eager_workflow_start/eager_workflow_test.rb b/test/eager_workflow_start/eager_workflow_test.rb new file mode 100644 index 0000000..9461ee4 --- /dev/null +++ b/test/eager_workflow_start/eager_workflow_test.rb @@ -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