Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion activity_heartbeating/starter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'my_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

workflow_id = 'activity-heartbeating-workflow-id'
task_queue = 'activity-heartbeating-sample'
Expand Down
12 changes: 7 additions & 5 deletions activity_heartbeating/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
require_relative 'my_workflow'
require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a Temporal client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
logger: Logger.new($stdout, level: Logger::INFO)
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal since kwargs can never have logger in it, but usually in Ruby you would recommend the explicit args/kwargs to go before the splatting.


# Create worker with the activities and workflow
worker = Temporalio::Worker.new(
Expand Down
8 changes: 7 additions & 1 deletion activity_simple/starter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'my_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Run workflow
puts 'Executing workflow'
Expand Down
12 changes: 7 additions & 5 deletions activity_simple/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
require_relative 'my_workflow'
require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a Temporal client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
logger: Logger.new($stdout, level: Logger::INFO)
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))

# Use an instance for the stateful DB activity, other activity we will pass
# in as class meaning it is instantiated each attempt
Expand Down
8 changes: 7 additions & 1 deletion activity_worker/activity_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

require_relative 'say_hello_activity'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Create worker with the client and activity
worker = Temporalio::Worker.new(
Expand Down
8 changes: 7 additions & 1 deletion activity_worker/starter.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Run workflow
result = client.execute_workflow(
Expand Down
8 changes: 7 additions & 1 deletion coinbase_ruby/starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

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

require_relative 'coinbase_workflow'
require_relative 'temporal_workflow'
require 'logger'
require 'temporal-ruby'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create Temporal SDK client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Run Coinbase workflow
result = client.execute_workflow(
Expand Down
12 changes: 7 additions & 5 deletions coinbase_ruby/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

Expand All @@ -13,12 +14,13 @@
require 'temporal-ruby'
require 'temporal/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a Temporal client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
logger: Logger.new($stdout, level: Logger::INFO)
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))

# Create Temporal worker with the activity and workflow on the coinbase-ruby-sample-temporal task queue
worker = Temporalio::Worker.new(
Expand Down
19 changes: 11 additions & 8 deletions context_propagation/starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'interceptor'
require_relative 'say_hello_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
# Add the context propagation interceptor to propagate the :my_user
# thread/fiber local
interceptors = [ContextPropagation::Interceptor.new(:my_user)]

# Create a Temporal client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
logger: Logger.new($stdout, level: Logger::INFO),
# Add the context propagation interceptor to propagate the :my_user
# thread/fiber local
interceptors: [ContextPropagation::Interceptor.new(:my_user)]
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO),
interceptors:)

# Set user as "Alice" which will get propagated in a distributed way through
# the workflow and activity via Temporal headers
Expand Down
17 changes: 10 additions & 7 deletions context_propagation/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
require_relative 'say_hello_workflow'
require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
# Add the context propagation interceptor to propagate the :my_user thread/fiber local
interceptors = [ContextPropagation::Interceptor.new(:my_user)]

# Create a Temporal client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
logger: Logger.new($stdout, level: Logger::INFO),
# Add the context propagation interceptor to propagate the :my_user thread/fiber local
interceptors: [ContextPropagation::Interceptor.new(:my_user)]
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO),
interceptors: interceptors)

# Create worker with the activity and workflow
worker = Temporalio::Worker.new(
Expand Down
7 changes: 5 additions & 2 deletions dsl/starter.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'activities'
require_relative 'models'
require_relative 'dsl_workflow'

# Create a Temporal client
logger = Logger.new($stdout, level: Logger::INFO)
client = Temporalio::Client.connect('localhost:7233', 'default', logger:)
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))

# Load YAML file
yaml_str = File.read(ARGV.first || raise('Missing argument for YAML file'))
Expand Down
7 changes: 5 additions & 2 deletions dsl/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'
require_relative 'activities'
require_relative 'dsl_workflow'

# Create a Temporal client
logger = Logger.new($stdout, level: Logger::INFO)
client = Temporalio::Client.connect('localhost:7233', 'default', logger:)
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))

# Create worker with the activities and workflow
worker = Temporalio::Worker.new(
Expand Down
6 changes: 5 additions & 1 deletion eager_workflow_start/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

require 'securerandom'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'
require_relative 'eager_workflow'
require_relative 'greeting_activity'

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')
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
client = Temporalio::Client.connect(*args, **kwargs)

worker = Temporalio::Worker.new(
client:,
Expand Down
14 changes: 9 additions & 5 deletions encryption/starter.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'codec'
require_relative 'my_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
# Set data converter with our codec
data_converter = Temporalio::Converters::DataConverter.new(payload_codec: Encryption::Codec.new)

# Create a client
client = Temporalio::Client.connect(
'localhost:7233', 'default',
# Set data converter with our codec
data_converter: Temporalio::Converters::DataConverter.new(payload_codec: Encryption::Codec.new)
)
client = Temporalio::Client.connect(*args, **kwargs, data_converter: data_converter)

# Run workflow
puts 'Executing workflow'
Expand Down
15 changes: 9 additions & 6 deletions encryption/worker.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'
require_relative 'codec'
require_relative 'my_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
# Set data converter with our codec
data_converter = Temporalio::Converters::DataConverter.new(payload_codec: Encryption::Codec.new)

# Create a client
client = Temporalio::Client.connect(
'localhost:7233',
'default',
# Set data converter with our codec
data_converter: Temporalio::Converters::DataConverter.new(payload_codec: Encryption::Codec.new)
)
client = Temporalio::Client.connect(*args, **kwargs, data_converter: data_converter)

# Create worker with the workflow
worker = Temporalio::Worker.new(
Expand Down
8 changes: 7 additions & 1 deletion message_passing_simple/starter.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# frozen_string_literal: true

require 'temporalio/client'
require 'temporalio/env_config'
require_relative 'greeting_workflow'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Start the workflow
puts 'Starting workflow'
Expand Down
8 changes: 7 additions & 1 deletion message_passing_simple/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
require_relative 'greeting_workflow'
require 'logger'
require 'temporalio/client'
require 'temporalio/env_config'
require 'temporalio/worker'

# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace

# Create a client
client = Temporalio::Client.connect('localhost:7233', 'default')
client = Temporalio::Client.connect(*args, **kwargs)

# Create worker with the activity and workflow
worker = Temporalio::Worker.new(
Expand Down
11 changes: 6 additions & 5 deletions open_telemetry/starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'opentelemetry/sdk'
require 'temporalio/client'
require 'temporalio/contrib/open_telemetry'
require 'temporalio/env_config'
require 'temporalio/runtime'
require_relative 'greeting_workflow'
require_relative 'util'
Expand All @@ -17,11 +18,11 @@

# Create a client with the tracing interceptor set using the tracer
tracer = OpenTelemetry.tracer_provider.tracer('temporal_ruby_sample', '0.1.0')
client = Temporalio::Client.connect(
'localhost:7233',
'default',
interceptors: [Temporalio::Contrib::OpenTelemetry::TracingInterceptor.new(tracer)]
)
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
interceptors = [Temporalio::Contrib::OpenTelemetry::TracingInterceptor.new(tracer)]
client = Temporalio::Client.connect(*args, **kwargs, interceptors:)

# Demonstrate an arbitrary outer span. Most users may not explicitly create outer spans before using clients and rather
# solely rely on the implicit ones created in the client via interceptor, but this demonstrates that it can be done.
Expand Down
Loading