Skip to content

Commit 51b6264

Browse files
authored
update samples to use env config (#50)
* update samples to use env config * update new samples * update temporalio in sorbet sample * sorbet typing fix - gen'd * update temporalio dep for rails_app * pr suggestions * address nits
1 parent de1ef96 commit 51b6264

45 files changed

Lines changed: 5642 additions & 3068 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

activity_heartbeating/starter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# frozen_string_literal: true
22

33
require 'temporalio/client'
4+
require 'temporalio/env_config'
45
require_relative 'my_workflow'
56

7+
# Load config and apply defaults
8+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
9+
args[0] ||= 'localhost:7233' # Default address
10+
args[1] ||= 'default' # Default namespace
11+
612
# Create a client
7-
client = Temporalio::Client.connect('localhost:7233', 'default')
13+
client = Temporalio::Client.connect(*args, **kwargs)
814

915
workflow_id = 'activity-heartbeating-workflow-id'
1016
task_queue = 'activity-heartbeating-sample'

activity_heartbeating/worker.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
require_relative 'my_workflow'
55
require 'logger'
66
require 'temporalio/client'
7+
require 'temporalio/env_config'
78
require 'temporalio/worker'
89

10+
# Load config and apply defaults
11+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
12+
args[0] ||= 'localhost:7233' # Default address
13+
args[1] ||= 'default' # Default namespace
14+
915
# Create a Temporal client
10-
client = Temporalio::Client.connect(
11-
'localhost:7233',
12-
'default',
13-
logger: Logger.new($stdout, level: Logger::INFO)
14-
)
16+
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))
1517

1618
# Create worker with the activities and workflow
1719
worker = Temporalio::Worker.new(

activity_simple/starter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# frozen_string_literal: true
22

33
require 'temporalio/client'
4+
require 'temporalio/env_config'
45
require_relative 'my_workflow'
56

7+
# Load config and apply defaults
8+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
9+
args[0] ||= 'localhost:7233' # Default address
10+
args[1] ||= 'default' # Default namespace
11+
612
# Create a client
7-
client = Temporalio::Client.connect('localhost:7233', 'default')
13+
client = Temporalio::Client.connect(*args, **kwargs)
814

915
# Run workflow
1016
puts 'Executing workflow'

activity_simple/worker.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
require_relative 'my_workflow'
55
require 'logger'
66
require 'temporalio/client'
7+
require 'temporalio/env_config'
78
require 'temporalio/worker'
89

10+
# Load config and apply defaults
11+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
12+
args[0] ||= 'localhost:7233' # Default address
13+
args[1] ||= 'default' # Default namespace
14+
915
# Create a Temporal client
10-
client = Temporalio::Client.connect(
11-
'localhost:7233',
12-
'default',
13-
logger: Logger.new($stdout, level: Logger::INFO)
14-
)
16+
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))
1517

1618
# Use an instance for the stateful DB activity, other activity we will pass
1719
# in as class meaning it is instantiated each attempt

activity_worker/activity_worker.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
require_relative 'say_hello_activity'
44
require 'temporalio/client'
5+
require 'temporalio/env_config'
56
require 'temporalio/worker'
67

8+
# Load config and apply defaults
9+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
10+
args[0] ||= 'localhost:7233' # Default address
11+
args[1] ||= 'default' # Default namespace
12+
713
# Create a client
8-
client = Temporalio::Client.connect('localhost:7233', 'default')
14+
client = Temporalio::Client.connect(*args, **kwargs)
915

1016
# Create worker with the client and activity
1117
worker = Temporalio::Worker.new(

activity_worker/starter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# frozen_string_literal: true
22

33
require 'temporalio/client'
4+
require 'temporalio/env_config'
5+
6+
# Load config and apply defaults
7+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
8+
args[0] ||= 'localhost:7233' # Default address
9+
args[1] ||= 'default' # Default namespace
410

511
# Create a client
6-
client = Temporalio::Client.connect('localhost:7233', 'default')
12+
client = Temporalio::Client.connect(*args, **kwargs)
713

814
# Run workflow
915
result = client.execute_workflow(

coinbase_ruby/starter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
# We must require Temporal SDK first and set the env var to prevent Coinbase SDK from trying to load its protos
44
require 'temporalio/client'
5+
require 'temporalio/env_config'
56
ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] = '1'
67

78
require_relative 'coinbase_workflow'
89
require_relative 'temporal_workflow'
910
require 'logger'
1011
require 'temporal-ruby'
1112

13+
# Load config and apply defaults
14+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
15+
args[0] ||= 'localhost:7233' # Default address
16+
args[1] ||= 'default' # Default namespace
17+
1218
# Create Temporal SDK client
13-
client = Temporalio::Client.connect('localhost:7233', 'default')
19+
client = Temporalio::Client.connect(*args, **kwargs)
1420

1521
# Run Coinbase workflow
1622
result = client.execute_workflow(

coinbase_ruby/worker.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# We must require Temporal SDK first and set the env var to prevent Coinbase SDK from trying to load its protos
44
require 'temporalio/client'
5+
require 'temporalio/env_config'
56
require 'temporalio/worker'
67
ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] = '1'
78

@@ -13,12 +14,13 @@
1314
require 'temporal-ruby'
1415
require 'temporal/worker'
1516

17+
# Load config and apply defaults
18+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
19+
args[0] ||= 'localhost:7233' # Default address
20+
args[1] ||= 'default' # Default namespace
21+
1622
# Create a Temporal client
17-
client = Temporalio::Client.connect(
18-
'localhost:7233',
19-
'default',
20-
logger: Logger.new($stdout, level: Logger::INFO)
21-
)
23+
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))
2224

2325
# Create Temporal worker with the activity and workflow on the coinbase-ruby-sample-temporal task queue
2426
worker = Temporalio::Worker.new(

context_propagation/starter.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
require 'logger'
44
require 'temporalio/client'
5+
require 'temporalio/env_config'
56
require_relative 'interceptor'
67
require_relative 'say_hello_workflow'
78

9+
# Load config and apply defaults
10+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
11+
args[0] ||= 'localhost:7233' # Default address
12+
args[1] ||= 'default' # Default namespace
13+
# Add the context propagation interceptor to propagate the :my_user
14+
# thread/fiber local
15+
interceptors = [ContextPropagation::Interceptor.new(:my_user)]
16+
817
# Create a Temporal client
9-
client = Temporalio::Client.connect(
10-
'localhost:7233',
11-
'default',
12-
logger: Logger.new($stdout, level: Logger::INFO),
13-
# Add the context propagation interceptor to propagate the :my_user
14-
# thread/fiber local
15-
interceptors: [ContextPropagation::Interceptor.new(:my_user)]
16-
)
18+
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO),
19+
interceptors:)
1720

1821
# Set user as "Alice" which will get propagated in a distributed way through
1922
# the workflow and activity via Temporal headers

context_propagation/worker.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
require_relative 'say_hello_workflow'
66
require 'logger'
77
require 'temporalio/client'
8+
require 'temporalio/env_config'
89
require 'temporalio/worker'
910

11+
# Load config and apply defaults
12+
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
13+
args[0] ||= 'localhost:7233' # Default address
14+
args[1] ||= 'default' # Default namespace
15+
# Add the context propagation interceptor to propagate the :my_user thread/fiber local
16+
interceptors = [ContextPropagation::Interceptor.new(:my_user)]
17+
1018
# Create a Temporal client
11-
client = Temporalio::Client.connect(
12-
'localhost:7233',
13-
'default',
14-
logger: Logger.new($stdout, level: Logger::INFO),
15-
# Add the context propagation interceptor to propagate the :my_user thread/fiber local
16-
interceptors: [ContextPropagation::Interceptor.new(:my_user)]
17-
)
19+
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO),
20+
interceptors: interceptors)
1821

1922
# Create worker with the activity and workflow
2023
worker = Temporalio::Worker.new(

0 commit comments

Comments
 (0)