Skip to content

Commit f41efb7

Browse files
authored
[Refactor] Remove global config references (coinbase#317)
* Remove global config from client specs * Remove global configuration from client and connection * Remove global configuration from integration specs * Remove global config from error messages and comments * Remove global config from specs * Remove global config from worker spec * Add README section on global vs local configuration
1 parent c73a07e commit f41efb7

26 files changed

+129
-83
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,47 @@ Temporal.configure do |config|
179179
end
180180
```
181181

182+
## Configuration
183+
184+
This gem is optimised for the smoothest out-of-the-box experience, which is achieved using a global
185+
configuration:
186+
187+
```ruby
188+
Temporal.configure do |config|
189+
config.host = '127.0.0.1' # sets global host
190+
...
191+
end
192+
193+
Temporal::Worker.new # uses global host
194+
Temporal.start_workflow(...) # uses global host
195+
```
196+
197+
This will work just fine for simpler use-cases, however at some point you might need to setup
198+
multiple clients and workers within the same instance of your app (e.g. you have different Temporal
199+
hosts, need to use different codecs/converters for different parts of your app, etc). Should this be
200+
the case we recommend using explicit local configurations for each client/worker:
201+
202+
```ruby
203+
config_1 = Temporal::Configuration.new
204+
config_1.host = 'temporal-01'
205+
206+
config_2 = Temporal::Configuration.new
207+
config_2.host = 'temporal-01'
208+
209+
worker_1 = Temporal::Worker.new(config_1)
210+
worker_2 = Temporal::Worker.new(config_2)
211+
212+
client_1 = Temporal::Client.new(config_1)
213+
client_1.start_workflow(...)
214+
215+
client_2 = Temporal::Client.new(config_2)
216+
client_2.start_workflow(...)
217+
```
218+
219+
*NOTE: Almost all the methods on the `Temporal` module are delegated to the default client that's
220+
initialized using global configuration. The same methods can be used directly on your own client
221+
instances.*
222+
182223
## Workflows
183224

184225
A workflow is defined using pure Ruby code, however it should contain only a high-level

examples/init.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
metrics_logger = Logger.new(STDOUT, progname: 'metrics')
1010

11+
DEFAULT_NAMESPACE = 'ruby-samples'.freeze
12+
DEFAULT_TASK_QUEUE = 'general'.freeze
13+
1114
Temporal.configure do |config|
1215
config.host = ENV.fetch('TEMPORAL_HOST', 'localhost')
1316
config.port = ENV.fetch('TEMPORAL_PORT', 7233).to_i
14-
config.namespace = ENV.fetch('TEMPORAL_NAMESPACE', 'ruby-samples')
15-
config.task_queue = ENV.fetch('TEMPORAL_TASK_QUEUE', 'general')
17+
config.namespace = ENV.fetch('TEMPORAL_NAMESPACE', DEFAULT_NAMESPACE)
18+
config.task_queue = ENV.fetch('TEMPORAL_TASK_QUEUE', DEFAULT_TASK_QUEUE)
1619
config.metrics_adapter = Temporal::MetricsAdapters::Log.new(metrics_logger)
1720
end

examples/spec/helpers.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def wait_for_workflow_completion(workflow_id, run_id)
2121
def fetch_history(workflow_id, run_id, options = {})
2222
connection = Temporal.send(:default_client).send(:connection)
2323
options = {
24-
namespace: Temporal.configuration.namespace,
24+
namespace: integration_spec_namespace,
2525
workflow_id: workflow_id,
2626
run_id: run_id,
2727
}.merge(options)
@@ -30,6 +30,10 @@ def fetch_history(workflow_id, run_id, options = {})
3030
end
3131

3232
def integration_spec_namespace
33-
ENV.fetch('TEMPORAL_NAMESPACE', 'ruby-samples')
33+
ENV.fetch('TEMPORAL_NAMESPACE', DEFAULT_NAMESPACE)
34+
end
35+
36+
def integration_spec_task_queue
37+
ENV.fetch('TEMPORAL_TASK_QUEUE', DEFAULT_TASK_QUEUE)
3438
end
3539
end

examples/spec/integration/converter_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
end
1313

1414
around(:each) do |example|
15-
task_queue = Temporal.configuration.task_queue
16-
1715
Temporal.configure do |config|
1816
config.task_queue = 'crypt'
1917
config.payload_codec = codec
@@ -22,7 +20,7 @@
2220
example.run
2321
ensure
2422
Temporal.configure do |config|
25-
config.task_queue = task_queue
23+
config.task_queue = integration_spec_task_queue
2624
config.payload_codec = Temporal::Configuration::DEFAULT_PAYLOAD_CODEC
2725
end
2826
end

examples/spec/integration/create_schedule_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"Test",
2626
options: {
2727
workflow_id: workflow_id,
28-
task_queue: Temporal.configuration.task_queue
28+
task_queue: integration_spec_task_queue
2929
}
3030
),
3131
policies: Temporal::Schedule::SchedulePolicies.new(
@@ -74,7 +74,7 @@
7474
action: Temporal::Schedule::StartWorkflowAction.new(
7575
"HelloWorldWorkflow",
7676
"Test",
77-
options: {task_queue: Temporal.configuration.task_queue}
77+
options: {task_queue: integration_spec_task_queue}
7878
)
7979
)
8080

examples/spec/integration/delete_schedule_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"HelloWorldWorkflow",
1616
"Test",
1717
options: {
18-
task_queue: Temporal.configuration.task_queue
18+
task_queue: integration_spec_task_queue
1919
}
2020
)
2121
)

examples/spec/integration/handling_structured_error_workflow_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
# That worker runs a task queue, error_serialization_v2. This setup code will
66
# route workflow requests to that task queue.
77
around(:each) do |example|
8-
task_queue = Temporal.configuration.task_queue
9-
108
Temporal.configure do |config|
119
config.task_queue = 'error_serialization_v2'
1210
end
1311

1412
example.run
1513
ensure
1614
Temporal.configure do |config|
17-
config.task_queue = task_queue
15+
config.task_queue = integration_spec_task_queue
1816
end
1917
end
2018

examples/spec/integration/list_schedules_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"HelloWorldWorkflow",
2323
"Test",
2424
options: {
25-
task_queue: Temporal.configuration.task_queue
25+
task_queue: integration_spec_task_queue
2626
}
2727
)
2828
)

examples/spec/integration/metadata_workflow_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
run_id: run_id,
1717
)
1818

19-
expect(actual_result.task_queue).to eq(Temporal.configuration.task_queue)
19+
expect(actual_result.task_queue).to eq(integration_spec_task_queue)
2020
end
2121

2222
it 'workflow can retrieve its headers' do

examples/spec/integration/pause_schedule_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"HelloWorldWorkflow",
1818
"Test",
1919
options: {
20-
task_queue: Temporal.configuration.task_queue
20+
task_queue: integration_spec_task_queue
2121
}
2222
)
2323
)

0 commit comments

Comments
 (0)