Class: Temporalio::Client::Connection
- Inherits:
-
Object
- Object
- Temporalio::Client::Connection
- Defined in:
- lib/temporalio/client/connection.rb,
lib/temporalio/client/connection/service.rb,
lib/temporalio/client/connection/test_service.rb,
lib/temporalio/client/connection/cloud_service.rb,
lib/temporalio/client/connection/operator_service.rb,
lib/temporalio/client/connection/workflow_service.rb
Overview
Connection to Temporal server that is not namespace specific. Most users will use connect instead of this directly.
Defined Under Namespace
Classes: CloudService, HTTPConnectProxyOptions, KeepAliveOptions, OperatorService, Options, RPCRetryOptions, Service, TLSOptions, TestService, WorkflowService
Instance Attribute Summary collapse
-
#cloud_service ⇒ CloudService
readonly
Raw gRPC cloud service.
-
#operator_service ⇒ OperatorService
readonly
Raw gRPC operator service.
-
#options ⇒ Options
readonly
Frozen options for this client which has the same attributes as #initialize.
-
#workflow_service ⇒ WorkflowService
readonly
Raw gRPC workflow service.
Instance Method Summary collapse
-
#api_key ⇒ String?
API key.
-
#api_key=(new_key) ⇒ Object
Set the API key for all future calls.
-
#connected? ⇒ Boolean
Whether this connection is connected.
-
#identity ⇒ String
Client identity.
-
#initialize(target_host:, api_key: nil, tls: nil, rpc_metadata: {}, rpc_retry: RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: KeepAliveOptions.new, http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false, around_connect: nil) ⇒ Connection
constructor
Connect to Temporal server.
-
#rpc_metadata ⇒ Hash<String, String>
RPC metadata (aka HTTP headers).
-
#rpc_metadata=(rpc_metadata) ⇒ Object
Set the RPC metadata (aka HTTP headers) for all future calls.
-
#target_host ⇒ String
Target host this connection is connected to.
Constructor Details
#initialize(target_host:, api_key: nil, tls: nil, rpc_metadata: {}, rpc_retry: RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: KeepAliveOptions.new, http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false, around_connect: nil) ⇒ Connection
Connect to Temporal server. Most users will use Temporalio::Client.connect instead of this directly. Parameters here match Options returned from #options by intention so options can be dup’d, altered, splatted to create a new connection.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/temporalio/client/connection.rb', line 177 def initialize( target_host:, api_key: nil, tls: nil, rpc_metadata: {}, rpc_retry: RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: KeepAliveOptions.new, http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false, around_connect: nil ) @options = Options.new( target_host:, api_key:, tls:, rpc_metadata:, rpc_retry:, identity:, keep_alive:, http_connect_proxy:, runtime:, lazy_connect: ).freeze @core_client_mutex = Mutex.new # Create core client now if not lazy, applying around_connect if present if around_connect # Technically around_connect can never run the block for whatever reason (i.e. plugin returning a mock # connection), so we don't enforce it around_connect.call(@options) do || @options = _core_client unless lazy_connect nil end else _core_client unless lazy_connect end # Create service instances @workflow_service = WorkflowService.new(self) @operator_service = OperatorService.new(self) @cloud_service = CloudService.new(self) end |
Instance Attribute Details
#cloud_service ⇒ CloudService (readonly)
Returns Raw gRPC cloud service.
147 148 149 |
# File 'lib/temporalio/client/connection.rb', line 147 def cloud_service @cloud_service end |
#operator_service ⇒ OperatorService (readonly)
Returns Raw gRPC operator service.
144 145 146 |
# File 'lib/temporalio/client/connection.rb', line 144 def operator_service @operator_service end |
#options ⇒ Options (readonly)
Returns Frozen options for this client which has the same attributes as #initialize. Note that if #api_key= or #rpc_metadata= are updated, the options object is replaced with those changes (it is not mutated in place).
138 139 140 |
# File 'lib/temporalio/client/connection.rb', line 138 def @options end |
#workflow_service ⇒ WorkflowService (readonly)
Returns Raw gRPC workflow service.
141 142 143 |
# File 'lib/temporalio/client/connection.rb', line 141 def workflow_service @workflow_service end |
Instance Method Details
#api_key ⇒ String?
Returns API key. This is a shortcut for options.api_key.
238 239 240 |
# File 'lib/temporalio/client/connection.rb', line 238 def api_key @options.api_key end |
#api_key=(new_key) ⇒ Object
Set the API key for all future calls. This also makes a new object for #options with the changes.
245 246 247 248 249 250 251 |
# File 'lib/temporalio/client/connection.rb', line 245 def api_key=(new_key) # Mutate the client if connected then mutate options @core_client_mutex.synchronize do @core_client&.update_api_key(new_key) @options = @options.with(api_key: new_key) end end |
#connected? ⇒ Boolean
Returns Whether this connection is connected. This is always true unless lazy_connect option was originally set, in which case this will be false until the first call is made.
233 234 235 |
# File 'lib/temporalio/client/connection.rb', line 233 def connected? !@core_client.nil? end |
#identity ⇒ String
Returns Client identity.
227 228 229 |
# File 'lib/temporalio/client/connection.rb', line 227 def identity @options.identity end |
#rpc_metadata ⇒ Hash<String, String>
Returns RPC metadata (aka HTTP headers). This is a shortcut for options.rpc_metadata.
254 255 256 |
# File 'lib/temporalio/client/connection.rb', line 254 def @options. end |
#rpc_metadata=(rpc_metadata) ⇒ Object
Set the RPC metadata (aka HTTP headers) for all future calls. This also makes a new object for #options with the changes.
262 263 264 265 266 267 268 |
# File 'lib/temporalio/client/connection.rb', line 262 def () # Mutate the client if connected then mutate options @core_client_mutex.synchronize do @core_client&.() @options = @options.with(rpc_metadata: ) end end |
#target_host ⇒ String
Returns Target host this connection is connected to.
222 223 224 |
# File 'lib/temporalio/client/connection.rb', line 222 def target_host @options.target_host end |