diff --git a/README.md b/README.md index 63888d8b..a64c1159 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,47 @@ Temporal.configure do |config| end ``` +## Configuration + +This gem is optimised for the smoothest out-of-the-box experience, which is achieved using a global +configuration: + +```ruby +Temporal.configure do |config| + config.host = '127.0.0.1' # sets global host + ... +end + +Temporal::Worker.new # uses global host +Temporal.start_workflow(...) # uses global host +``` + +This will work just fine for simpler use-cases, however at some point you might need to setup +multiple clients and workers within the same instance of your app (e.g. you have different Temporal +hosts, need to use different codecs/converters for different parts of your app, etc). Should this be +the case we recommend using explicit local configurations for each client/worker: + +```ruby +config_1 = Temporal::Configuration.new +config_1.host = 'temporal-01' + +config_2 = Temporal::Configuration.new +config_2.host = 'temporal-01' + +worker_1 = Temporal::Worker.new(config_1) +worker_2 = Temporal::Worker.new(config_2) + +client_1 = Temporal::Client.new(config_1) +client_1.start_workflow(...) + +client_2 = Temporal::Client.new(config_2) +client_2.start_workflow(...) +``` + +*NOTE: Almost all the methods on the `Temporal` module are delegated to the default client that's +initialized using global configuration. The same methods can be used directly on your own client +instances.* + ## Workflows A workflow is defined using pure Ruby code, however it should contain only a high-level diff --git a/examples/init.rb b/examples/init.rb index ab4e1b3a..053c0e14 100644 --- a/examples/init.rb +++ b/examples/init.rb @@ -8,10 +8,13 @@ metrics_logger = Logger.new(STDOUT, progname: 'metrics') +DEFAULT_NAMESPACE = 'ruby-samples'.freeze +DEFAULT_TASK_QUEUE = 'general'.freeze + Temporal.configure do |config| config.host = ENV.fetch('TEMPORAL_HOST', 'localhost') config.port = ENV.fetch('TEMPORAL_PORT', 7233).to_i - config.namespace = ENV.fetch('TEMPORAL_NAMESPACE', 'ruby-samples') - config.task_queue = ENV.fetch('TEMPORAL_TASK_QUEUE', 'general') + config.namespace = ENV.fetch('TEMPORAL_NAMESPACE', DEFAULT_NAMESPACE) + config.task_queue = ENV.fetch('TEMPORAL_TASK_QUEUE', DEFAULT_TASK_QUEUE) config.metrics_adapter = Temporal::MetricsAdapters::Log.new(metrics_logger) end diff --git a/examples/spec/helpers.rb b/examples/spec/helpers.rb index f2e614e4..4d4c65a4 100644 --- a/examples/spec/helpers.rb +++ b/examples/spec/helpers.rb @@ -21,7 +21,7 @@ def wait_for_workflow_completion(workflow_id, run_id) def fetch_history(workflow_id, run_id, options = {}) connection = Temporal.send(:default_client).send(:connection) options = { - namespace: Temporal.configuration.namespace, + namespace: integration_spec_namespace, workflow_id: workflow_id, run_id: run_id, }.merge(options) @@ -30,6 +30,10 @@ def fetch_history(workflow_id, run_id, options = {}) end def integration_spec_namespace - ENV.fetch('TEMPORAL_NAMESPACE', 'ruby-samples') + ENV.fetch('TEMPORAL_NAMESPACE', DEFAULT_NAMESPACE) + end + + def integration_spec_task_queue + ENV.fetch('TEMPORAL_TASK_QUEUE', DEFAULT_TASK_QUEUE) end end diff --git a/examples/spec/integration/converter_spec.rb b/examples/spec/integration/converter_spec.rb index 6c6672c4..576ff55f 100644 --- a/examples/spec/integration/converter_spec.rb +++ b/examples/spec/integration/converter_spec.rb @@ -12,8 +12,6 @@ end around(:each) do |example| - task_queue = Temporal.configuration.task_queue - Temporal.configure do |config| config.task_queue = 'crypt' config.payload_codec = codec @@ -22,7 +20,7 @@ example.run ensure Temporal.configure do |config| - config.task_queue = task_queue + config.task_queue = integration_spec_task_queue config.payload_codec = Temporal::Configuration::DEFAULT_PAYLOAD_CODEC end end diff --git a/examples/spec/integration/create_schedule_spec.rb b/examples/spec/integration/create_schedule_spec.rb index 02f3e0b4..a7ae3a40 100644 --- a/examples/spec/integration/create_schedule_spec.rb +++ b/examples/spec/integration/create_schedule_spec.rb @@ -25,7 +25,7 @@ "Test", options: { workflow_id: workflow_id, - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ), policies: Temporal::Schedule::SchedulePolicies.new( @@ -74,7 +74,7 @@ action: Temporal::Schedule::StartWorkflowAction.new( "HelloWorldWorkflow", "Test", - options: {task_queue: Temporal.configuration.task_queue} + options: {task_queue: integration_spec_task_queue} ) ) diff --git a/examples/spec/integration/delete_schedule_spec.rb b/examples/spec/integration/delete_schedule_spec.rb index b12d7220..c621710d 100644 --- a/examples/spec/integration/delete_schedule_spec.rb +++ b/examples/spec/integration/delete_schedule_spec.rb @@ -15,7 +15,7 @@ "HelloWorldWorkflow", "Test", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ) ) diff --git a/examples/spec/integration/handling_structured_error_workflow_spec.rb b/examples/spec/integration/handling_structured_error_workflow_spec.rb index 094fb139..91096453 100644 --- a/examples/spec/integration/handling_structured_error_workflow_spec.rb +++ b/examples/spec/integration/handling_structured_error_workflow_spec.rb @@ -5,8 +5,6 @@ # That worker runs a task queue, error_serialization_v2. This setup code will # route workflow requests to that task queue. around(:each) do |example| - task_queue = Temporal.configuration.task_queue - Temporal.configure do |config| config.task_queue = 'error_serialization_v2' end @@ -14,7 +12,7 @@ example.run ensure Temporal.configure do |config| - config.task_queue = task_queue + config.task_queue = integration_spec_task_queue end end diff --git a/examples/spec/integration/list_schedules_spec.rb b/examples/spec/integration/list_schedules_spec.rb index cfdc97b6..abd6b862 100644 --- a/examples/spec/integration/list_schedules_spec.rb +++ b/examples/spec/integration/list_schedules_spec.rb @@ -22,7 +22,7 @@ "HelloWorldWorkflow", "Test", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ) ) diff --git a/examples/spec/integration/metadata_workflow_spec.rb b/examples/spec/integration/metadata_workflow_spec.rb index 508c3af8..2fd0b1e6 100644 --- a/examples/spec/integration/metadata_workflow_spec.rb +++ b/examples/spec/integration/metadata_workflow_spec.rb @@ -16,7 +16,7 @@ run_id: run_id, ) - expect(actual_result.task_queue).to eq(Temporal.configuration.task_queue) + expect(actual_result.task_queue).to eq(integration_spec_task_queue) end it 'workflow can retrieve its headers' do diff --git a/examples/spec/integration/pause_schedule_spec.rb b/examples/spec/integration/pause_schedule_spec.rb index 12a750f4..46e8b8ce 100644 --- a/examples/spec/integration/pause_schedule_spec.rb +++ b/examples/spec/integration/pause_schedule_spec.rb @@ -17,7 +17,7 @@ "HelloWorldWorkflow", "Test", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ) ) diff --git a/examples/spec/integration/reset_workflow_spec.rb b/examples/spec/integration/reset_workflow_spec.rb index 57f41d82..7305fae4 100644 --- a/examples/spec/integration/reset_workflow_spec.rb +++ b/examples/spec/integration/reset_workflow_spec.rb @@ -2,7 +2,7 @@ require 'workflows/query_workflow' require 'temporal/reset_reapply_type' -describe 'Temporal.reset_workflow' do +describe 'Temporal.reset_workflow', :integration do it 'can reset a closed workflow to the beginning' do workflow_id = SecureRandom.uuid original_run_id = Temporal.start_workflow( @@ -19,7 +19,7 @@ expect(original_result).to eq('Hello World, Test') new_run_id = Temporal.reset_workflow( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, original_run_id, strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK @@ -36,7 +36,7 @@ def reset_hello_world_workflow_twice(workflow_id, original_run_id, request_id:) 2.times.map do new_run_id = Temporal.reset_workflow( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, original_run_id, strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK, @@ -130,7 +130,7 @@ def start_query_workflow_and_signal_three_times workflow_id, original_run_id = start_query_workflow_and_signal_three_times.values_at(:workflow_id, :run_id) new_run_id = Temporal.reset_workflow( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, original_run_id, strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK, @@ -147,7 +147,7 @@ def start_query_workflow_and_signal_three_times workflow_id, original_run_id = start_query_workflow_and_signal_three_times.values_at(:workflow_id, :run_id) new_run_id = Temporal.reset_workflow( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, original_run_id, strategy: Temporal::ResetStrategy::FIRST_WORKFLOW_TASK, @@ -160,4 +160,4 @@ def start_query_workflow_and_signal_three_times Temporal.terminate_workflow(workflow_id, run_id: new_run_id) end end - \ No newline at end of file + diff --git a/examples/spec/integration/start_workflow_spec.rb b/examples/spec/integration/start_workflow_spec.rb index 99d0d7c4..8cf6a46c 100644 --- a/examples/spec/integration/start_workflow_spec.rb +++ b/examples/spec/integration/start_workflow_spec.rb @@ -1,7 +1,7 @@ require 'workflows/hello_world_workflow' require 'workflows/long_workflow' -describe 'Temporal.start_workflow' do +describe 'Temporal.start_workflow', :integration do let(:workflow_id) { SecureRandom.uuid } it 'starts a workflow using a class reference' do @@ -21,15 +21,15 @@ it 'starts a workflow using a string reference' do run_id = Temporal.start_workflow('HelloWorldWorkflow', 'Test', options: { workflow_id: workflow_id, - namespace: Temporal.configuration.namespace, - task_queue: Temporal.configuration.task_queue + namespace: integration_spec_namespace, + task_queue: integration_spec_task_queue }) result = Temporal.await_workflow_result( 'HelloWorldWorkflow', workflow_id: workflow_id, run_id: run_id, - namespace: Temporal.configuration.namespace + namespace: integration_spec_namespace ) expect(result).to eq('Hello World, Test') @@ -82,11 +82,11 @@ }) execution_1 = Temporal.fetch_workflow_execution_info( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, run_id_1) execution_2 = Temporal.fetch_workflow_execution_info( - Temporal.configuration.namespace, + integration_spec_namespace, workflow_id, run_id_2) diff --git a/examples/spec/integration/trigger_schedule_spec.rb b/examples/spec/integration/trigger_schedule_spec.rb index ffa3e5c8..f90c8f0b 100644 --- a/examples/spec/integration/trigger_schedule_spec.rb +++ b/examples/spec/integration/trigger_schedule_spec.rb @@ -17,7 +17,7 @@ "HelloWorldWorkflow", "Test", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ) ) diff --git a/examples/spec/integration/update_schedule_spec.rb b/examples/spec/integration/update_schedule_spec.rb index 4aa358c6..5623894d 100644 --- a/examples/spec/integration/update_schedule_spec.rb +++ b/examples/spec/integration/update_schedule_spec.rb @@ -18,7 +18,7 @@ "HelloWorldWorkflow", "Test", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ), policies: Temporal::Schedule::SchedulePolicies.new( @@ -42,7 +42,7 @@ "HelloWorldWorkflow", "UpdatedInput", options: { - task_queue: Temporal.configuration.task_queue + task_queue: integration_spec_task_queue } ), policies: Temporal::Schedule::SchedulePolicies.new( diff --git a/lib/temporal/client.rb b/lib/temporal/client.rb index 9b537a9d..fc390e92 100644 --- a/lib/temporal/client.rb +++ b/lib/temporal/client.rb @@ -331,7 +331,7 @@ def reset_workflow(namespace, workflow_id, run_id, strategy: nil, workflow_task_ # for reference # @param details [String, Array, nil] optional details to be stored in history def terminate_workflow(workflow_id, namespace: nil, run_id: nil, reason: nil, details: nil) - namespace ||= Temporal.configuration.namespace + namespace ||= config.namespace connection.terminate_workflow_execution( namespace: namespace, diff --git a/lib/temporal/configuration.rb b/lib/temporal/configuration.rb index 101ad956..0506b61f 100644 --- a/lib/temporal/configuration.rb +++ b/lib/temporal/configuration.rb @@ -126,7 +126,7 @@ def for_connection credentials: credentials, identity: identity || default_identity, converter: converter, - connection_options: connection_options.merge(use_error_serialization_v2: @use_error_serialization_v2) + connection_options: connection_options.merge(use_error_serialization_v2: use_error_serialization_v2) ).freeze end diff --git a/lib/temporal/connection/grpc.rb b/lib/temporal/connection/grpc.rb index 5392f62a..1f817f51 100644 --- a/lib/temporal/connection/grpc.rb +++ b/lib/temporal/connection/grpc.rb @@ -315,7 +315,7 @@ def respond_activity_task_completed_by_id(namespace:, activity_id:, workflow_id: end def respond_activity_task_failed(namespace:, task_token:, exception:) - serialize_whole_error = options.fetch(:use_error_serialization_v2, Temporal.configuration.use_error_serialization_v2) + serialize_whole_error = options.fetch(:use_error_serialization_v2) request = Temporalio::Api::WorkflowService::V1::RespondActivityTaskFailedRequest.new( namespace: namespace, identity: identity, diff --git a/lib/temporal/errors.rb b/lib/temporal/errors.rb index a13ada62..1c423a6c 100644 --- a/lib/temporal/errors.rb +++ b/lib/temporal/errors.rb @@ -26,7 +26,7 @@ class ChildWorkflowTerminatedError < Error; end # A superclass for activity exceptions raised explicitly # with the intent to propagate to a workflow - # With v2 serialization (set with Temporal.configuration set with use_error_serialization_v2=true) you can + # With v2 serialization (set with Temporal::Configuration#use_error_serialization_v2=true) you can # throw any exception from an activity and expect that it can be handled by the workflow. class ActivityException < ClientError; end diff --git a/lib/temporal/workflow/errors.rb b/lib/temporal/workflow/errors.rb index 832c2ac3..f13f03bf 100644 --- a/lib/temporal/workflow/errors.rb +++ b/lib/temporal/workflow/errors.rb @@ -26,7 +26,7 @@ def self.generate_error(failure, converter, default_exception_class = StandardEr exception_or_message = converter.from_details_payloads(details) # v1 serialization only supports StandardErrors with a single "message" argument. # v2 serialization supports complex errors using our converters to serialize them. - # enable v2 serialization in activities with Temporal.configuration.use_error_serialization_v2 + # enable v2 serialization in activities with Temporal::Configuration#use_error_serialization_v2 if exception_or_message.is_a?(Exception) exception = exception_or_message else @@ -37,7 +37,7 @@ def self.generate_error(failure, converter, default_exception_class = StandardEr exception = default_exception_class.new(message) Temporal.logger.error( "Could not instantiate original error. Defaulting to StandardError. Make sure the worker running " \ - "your activities is setting Temporal.configuration.use_error_serialization_v2. If so, make sure the " \ + "your activities is configured with use_error_serialization_v2. If so, make sure the " \ "original error serialized by searching your logs for 'unserializable_error'. If not, you're using "\ "legacy serialization, and it's likely that "\ "your error's initializer takes something other than exactly one positional argument.", diff --git a/spec/config/temporal.rb b/spec/config/temporal.rb deleted file mode 100644 index 0d868ffe..00000000 --- a/spec/config/temporal.rb +++ /dev/null @@ -1,5 +0,0 @@ -RSpec.configure do |config| - config.before(:each) do - Temporal.configuration.error_handlers.clear - end -end \ No newline at end of file diff --git a/spec/unit/lib/temporal/client_spec.rb b/spec/unit/lib/temporal/client_spec.rb index bc970f31..a0ba4dc1 100644 --- a/spec/unit/lib/temporal/client_spec.rb +++ b/spec/unit/lib/temporal/client_spec.rb @@ -58,9 +58,9 @@ def inject!(header) workflow_name: 'TestStartWorkflow', task_queue: 'default-test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: { 'test' => 'asdf' }, memo: {}, @@ -87,9 +87,9 @@ def inject!(header) workflow_name: 'TestStartWorkflow', task_queue: 'default-test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: {}, memo: {}, @@ -120,9 +120,9 @@ def inject!(header) workflow_name: 'test-workflow', task_queue: 'test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: :reject, headers: { 'Foo' => 'Bar' }, memo: { 'MemoKey1' => 'MemoValue1' }, @@ -147,9 +147,9 @@ def inject!(header) workflow_name: 'test-workflow', task_queue: 'default-test-task-queue', input: [42, { arg_1: 1, arg_2: 2 }], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: {}, memo: {}, @@ -168,9 +168,9 @@ def inject!(header) workflow_name: 'TestStartWorkflow', task_queue: 'default-test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: {}, memo: {}, @@ -191,9 +191,9 @@ def inject!(header) workflow_name: 'TestStartWorkflow', task_queue: 'default-test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: :allow, headers: {}, memo: {}, @@ -218,9 +218,9 @@ def inject!(header) workflow_name: 'test-workflow', task_queue: 'test-task-queue', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: {}, memo: {}, @@ -246,9 +246,9 @@ def expect_signal_with_start(expected_arguments, expected_signal_argument) workflow_name: 'TestStartWorkflow', task_queue: 'default-test-task-queue', input: expected_arguments, - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, headers: {}, memo: {}, @@ -328,9 +328,9 @@ def expect_signal_with_start(expected_arguments, expected_signal_argument) task_queue: 'default-test-task-queue', cron_schedule: '* * * * *', input: [42], - task_timeout: Temporal.configuration.timeouts[:task], - run_timeout: Temporal.configuration.timeouts[:run], - execution_timeout: Temporal.configuration.timeouts[:execution], + task_timeout: config.timeouts[:task], + run_timeout: config.timeouts[:run], + execution_timeout: config.timeouts[:execution], workflow_id_reuse_policy: nil, memo: {}, search_attributes: {}, @@ -482,7 +482,7 @@ class NamespacedWorkflow < Temporal::Workflow it "completes and returns a #{type}" do payload = Temporalio::Api::Common::V1::Payloads.new( payloads: [ - Temporal.configuration.converter.to_payload(expected_result) + config.converter.to_payload(expected_result) ], ) completed_event = Fabricate(:workflow_completed_event, result: payload) @@ -759,7 +759,7 @@ class NamespacedWorkflow < Temporal::Workflow expect(connection) .to have_received(:terminate_workflow_execution) .with( - namespace: 'default-namespace', + namespace: 'default-test-namespace', workflow_id: 'my-workflow', reason: 'just stop it', details: nil, diff --git a/spec/unit/lib/temporal/testing/local_workflow_context_spec.rb b/spec/unit/lib/temporal/testing/local_workflow_context_spec.rb index 66c68769..75600fb3 100644 --- a/spec/unit/lib/temporal/testing/local_workflow_context_spec.rb +++ b/spec/unit/lib/temporal/testing/local_workflow_context_spec.rb @@ -9,6 +9,7 @@ let(:run_id) { 'run_id_1' } let(:execution) { Temporal::Testing::WorkflowExecution.new } let(:task_queue) { 'my_test_queue' } + let(:config) { Temporal::Configuration.new } let(:workflow_context) do Temporal::Testing::LocalWorkflowContext.new( execution, @@ -27,13 +28,14 @@ headers: {}, run_started_at: Time.now, memo: {}, - ) + ), + config ) end let(:async_token) do # Generate the async token Temporal::Activity::AsyncToken.encode( - Temporal.configuration.namespace, + config.namespace, 1, # activity ID starts at 1 for each workflow workflow_id, run_id diff --git a/spec/unit/lib/temporal/worker_spec.rb b/spec/unit/lib/temporal/worker_spec.rb index 4fffc5d8..2c379567 100644 --- a/spec/unit/lib/temporal/worker_spec.rb +++ b/spec/unit/lib/temporal/worker_spec.rb @@ -344,7 +344,7 @@ def start_and_stop(worker) .to receive(:new) .and_return(workflow_poller) - worker = Temporal::Worker.new(activity_thread_pool_size: 10) + worker = Temporal::Worker.new(config, activity_thread_pool_size: 10) worker.register_workflow(TestWorkerWorkflow) worker.register_activity(TestWorkerActivity) @@ -389,7 +389,7 @@ def start_and_stop(worker) ) .and_return(workflow_poller) - worker = Temporal::Worker.new(binary_checksum: binary_checksum) + worker = Temporal::Worker.new(config, binary_checksum: binary_checksum) worker.register_workflow(TestWorkerWorkflow) worker.register_activity(TestWorkerActivity) @@ -412,7 +412,7 @@ def start_and_stop(worker) ) .and_return(activity_poller) - worker = Temporal::Worker.new(activity_poll_retry_seconds: 10) + worker = Temporal::Worker.new(config, activity_poll_retry_seconds: 10) worker.register_activity(TestWorkerActivity) start_and_stop(worker) @@ -435,7 +435,7 @@ def start_and_stop(worker) ) .and_return(workflow_poller) - worker = Temporal::Worker.new(workflow_poll_retry_seconds: 10) + worker = Temporal::Worker.new(config, workflow_poll_retry_seconds: 10) worker.register_workflow(TestWorkerWorkflow) start_and_stop(worker) @@ -457,7 +457,7 @@ def start_and_stop(worker) ) .and_return(activity_poller) - worker = Temporal::Worker.new(activity_max_tasks_per_second: 5) + worker = Temporal::Worker.new(config, activity_max_tasks_per_second: 5) worker.register_activity(TestWorkerActivity) start_and_stop(worker) diff --git a/spec/unit/lib/temporal/workflow/context_spec.rb b/spec/unit/lib/temporal/workflow/context_spec.rb index 6dddf3b2..05a61282 100644 --- a/spec/unit/lib/temporal/workflow/context_spec.rb +++ b/spec/unit/lib/temporal/workflow/context_spec.rb @@ -27,7 +27,7 @@ def execute end let(:metadata_hash) { Fabricate(:workflow_metadata).to_h } let(:metadata) { Temporal::Metadata::Workflow.new(**metadata_hash) } - let(:config) { Temporal.configuration } + let(:config) { Temporal::Configuration.new } let(:workflow_context) do Temporal::Workflow::Context.new( diff --git a/spec/unit/lib/temporal/workflow/errors_spec.rb b/spec/unit/lib/temporal/workflow/errors_spec.rb index 82fb6924..bce9d477 100644 --- a/spec/unit/lib/temporal/workflow/errors_spec.rb +++ b/spec/unit/lib/temporal/workflow/errors_spec.rb @@ -109,7 +109,7 @@ def initialize(foo, bar) .to have_received(:error) .with( "Could not instantiate original error. Defaulting to StandardError. "\ - "Make sure the worker running your activities is setting Temporal.configuration.use_error_serialization_v2. "\ + "Make sure the worker running your activities is configured with use_error_serialization_v2. "\ "If so, make sure the original error serialized by searching your logs for 'unserializable_error'. "\ "If not, you're using legacy serialization, and it's likely that "\ "your error's initializer takes something other than exactly one positional argument.", @@ -142,7 +142,7 @@ def initialize(foo, bar) .to have_received(:error) .with( "Could not instantiate original error. Defaulting to StandardError. "\ - "Make sure the worker running your activities is setting Temporal.configuration.use_error_serialization_v2. "\ + "Make sure the worker running your activities is configured with use_error_serialization_v2. "\ "If so, make sure the original error serialized by searching your logs for 'unserializable_error'. "\ "If not, you're using legacy serialization, and it's likely that "\ "your error's initializer takes something other than exactly one positional argument.", diff --git a/spec/unit/lib/temporal_spec.rb b/spec/unit/lib/temporal_spec.rb index 47ccd73d..49e57664 100644 --- a/spec/unit/lib/temporal_spec.rb +++ b/spec/unit/lib/temporal_spec.rb @@ -67,19 +67,24 @@ it 'calls a block with the configuration' do expect do |block| described_class.configure(&block) - end.to yield_with_args(described_class.configuration) + end.to yield_with_args(described_class.send(:config)) end end describe '.configuration' do + before { allow(described_class).to receive(:warn) } + it 'returns Temporal::Configuration object' do expect(described_class.configuration).to be_an_instance_of(Temporal::Configuration) + expect(described_class) + .to have_received(:warn) + .with('[DEPRECATION] This method is now deprecated without a substitution') end end describe '.logger' do it 'returns preconfigured Temporal logger' do - expect(described_class.logger).to eq(described_class.configuration.logger) + expect(described_class.logger).to eq(described_class.send(:config).logger) end end