From 8bbb66693dbf5eca5f885ffcdc65a7e3d3265a83 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 20 May 2026 13:49:38 -0400 Subject: [PATCH] fix(priority): expose priority on start_workflow_operation --- .../client/with_start_workflow_operation.rb | 6 ++++++ .../temporalio/internal/client/implementation.rb | 3 ++- .../client/with_start_workflow_operation.rbs | 5 ++++- temporalio/test/worker_workflow_handler_test.rb | 16 ++++++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/temporalio/lib/temporalio/client/with_start_workflow_operation.rb b/temporalio/lib/temporalio/client/with_start_workflow_operation.rb index 17743197..ce8c8e87 100644 --- a/temporalio/lib/temporalio/client/with_start_workflow_operation.rb +++ b/temporalio/lib/temporalio/client/with_start_workflow_operation.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'temporalio/common_enums' +require 'temporalio/priority' module Temporalio class Client @@ -24,6 +25,7 @@ class WithStartWorkflowOperation :memo, :search_attributes, :start_delay, + :priority, :arg_hints, :result_hint, :headers @@ -40,6 +42,8 @@ class Options; end # rubocop:disable Lint/EmptyClass # # Note, for {Client.start_update_with_start_workflow} and {Client.execute_update_with_start_workflow}, # `id_conflict_policy` is required. + # + # @param priority [Priority] Priority of the workflow that may be started. This is currently experimental. def initialize( workflow, *args, @@ -57,6 +61,7 @@ def initialize( memo: nil, search_attributes: nil, start_delay: nil, + priority: Priority.default, arg_hints: nil, result_hint: nil, headers: {} @@ -80,6 +85,7 @@ def initialize( memo:, search_attributes:, start_delay:, + priority:, arg_hints: arg_hints || defn_arg_hints, result_hint: result_hint || defn_result_hint, headers: diff --git a/temporalio/lib/temporalio/internal/client/implementation.rb b/temporalio/lib/temporalio/internal/client/implementation.rb index dcc0ae08..ac1e67ca 100644 --- a/temporalio/lib/temporalio/internal/client/implementation.rb +++ b/temporalio/lib/temporalio/internal/client/implementation.rb @@ -327,7 +327,8 @@ def _start_workflow_request_from_with_start_options(klass, start_options) user_metadata: ProtoUtils.to_user_metadata( start_options.static_summary, start_options.static_details, @client.data_converter ), - header: ProtoUtils.headers_to_proto(start_options.headers, @client.data_converter) + header: ProtoUtils.headers_to_proto(start_options.headers, @client.data_converter), + priority: start_options.priority._to_proto ) end diff --git a/temporalio/sig/temporalio/client/with_start_workflow_operation.rbs b/temporalio/sig/temporalio/client/with_start_workflow_operation.rbs index 7d66d74a..0efca424 100644 --- a/temporalio/sig/temporalio/client/with_start_workflow_operation.rbs +++ b/temporalio/sig/temporalio/client/with_start_workflow_operation.rbs @@ -18,6 +18,7 @@ module Temporalio attr_reader memo: Hash[String | Symbol, Object?]? attr_reader search_attributes: SearchAttributes? attr_reader start_delay: duration? + attr_reader priority: Priority attr_reader arg_hints: Array[Object]? attr_reader result_hint: Object? attr_reader headers: Hash[String, Object?] @@ -39,6 +40,7 @@ module Temporalio memo: Hash[String | Symbol, Object?]?, search_attributes: SearchAttributes?, start_delay: duration?, + priority: Priority, arg_hints: Array[Object]?, result_hint: Object?, headers: Hash[String, Object?] @@ -64,6 +66,7 @@ module Temporalio ?memo: Hash[String | Symbol, Object?]?, ?search_attributes: SearchAttributes?, ?start_delay: duration?, + ?priority: Priority, ?arg_hints: Array[Object]?, ?result_hint: Object?, ?headers: Hash[String, Object?] @@ -76,4 +79,4 @@ module Temporalio def _mark_used: -> void end end -end \ No newline at end of file +end diff --git a/temporalio/test/worker_workflow_handler_test.rb b/temporalio/test/worker_workflow_handler_test.rb index c4ab8880..b07a1dff 100644 --- a/temporalio/test/worker_workflow_handler_test.rb +++ b/temporalio/test/worker_workflow_handler_test.rb @@ -714,7 +714,8 @@ def test_update_with_start_simple id = "wf-#{SecureRandom.uuid}" start_workflow_operation = Temporalio::Client::WithStartWorkflowOperation.new( UpdateWithStartWorkflow, 123, - id:, task_queue: worker.task_queue, id_conflict_policy: Temporalio::WorkflowIDConflictPolicy::FAIL + id:, task_queue: worker.task_queue, id_conflict_policy: Temporalio::WorkflowIDConflictPolicy::FAIL, + priority: Temporalio::Priority.new(priority_key: 2, fairness_key: 'update-start', fairness_weight: 0.7) ) # Run and confirm result of update is pre-workflow-execute assert_equal 456, env.client.execute_update_with_start_workflow( @@ -723,6 +724,11 @@ def test_update_with_start_simple # Confirm query is total handle = start_workflow_operation.workflow_handle assert_equal 579, handle.query(UpdateWithStartWorkflow.counter) + started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes) + priority = started_event.workflow_execution_started_event_attributes.priority + assert_equal 2, priority.priority_key + assert_equal 'update-start', priority.fairness_key + assert_in_delta 0.7, priority.fairness_weight, 0.001 # Update with start 5 more times 5.times do @@ -902,7 +908,8 @@ def test_signal_with_start id = "wf-#{SecureRandom.uuid}" start_workflow_operation = Temporalio::Client::WithStartWorkflowOperation.new( SignalWithStartWorkflow, 'workflow-start', - id:, task_queue: worker.task_queue + id:, task_queue: worker.task_queue, + priority: Temporalio::Priority.new(priority_key: 4, fairness_key: 'signal-start', fairness_weight: 1.3) ) handle = env.client.signal_with_start_workflow( SignalWithStartWorkflow.add_event, 'signal', start_workflow_operation: @@ -911,6 +918,11 @@ def test_signal_with_start assert_same handle, start_workflow_operation.workflow_handle # Confirm signal event came first assert_equal %w[signal workflow-start], handle.query(SignalWithStartWorkflow.events) + started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes) + priority = started_event.workflow_execution_started_event_attributes.priority + assert_equal 4, priority.priority_key + assert_equal 'signal-start', priority.fairness_key + assert_in_delta 1.3, priority.fairness_weight, 0.001 # Signal with start 3 more times 3.times do |i|