Class: Temporalio::Client
- Inherits:
-
Object
- Object
- Temporalio::Client
- Defined in:
- lib/temporalio/client.rb,
lib/temporalio/client/schedule.rb,
lib/temporalio/client/connection.rb,
lib/temporalio/client/interceptor.rb,
lib/temporalio/client/schedule_handle.rb,
lib/temporalio/client/workflow_handle.rb,
lib/temporalio/client/connection/service.rb,
lib/temporalio/client/workflow_execution.rb,
lib/temporalio/client/activity_id_reference.rb,
lib/temporalio/client/async_activity_handle.rb,
lib/temporalio/client/workflow_update_handle.rb,
lib/temporalio/client/connection/test_service.rb,
lib/temporalio/client/connection/cloud_service.rb,
lib/temporalio/client/workflow_execution_count.rb,
lib/temporalio/client/workflow_execution_status.rb,
lib/temporalio/client/workflow_update_wait_stage.rb,
lib/temporalio/client/connection/operator_service.rb,
lib/temporalio/client/connection/workflow_service.rb,
lib/temporalio/client/with_start_workflow_operation.rb,
lib/temporalio/client/workflow_query_reject_condition.rb
Overview
Client for accessing Temporal.
Most users will use Client.connect to connect a client. The #workflow_service method provides access to a raw gRPC client. To create another client on the same connection, like for a different namespace, #options may be used to get the options as a struct which can then be dup’d, altered, and splatted as kwargs to the constructor (e.g. Client.new(**my_options.to_h)).
Clients are thread-safe and are meant to be reused for the life of the application. They are built to work in both synchronous and asynchronous contexts. Internally they use callbacks based on Queue which means they are Fiber-compatible.
Defined Under Namespace
Modules: Interceptor, WorkflowExecutionStatus, WorkflowQueryRejectCondition, WorkflowUpdateWaitStage Classes: ActivityIDReference, AsyncActivityHandle, Connection, Options, RPCOptions, Schedule, ScheduleHandle, WithStartWorkflowOperation, WorkflowExecution, WorkflowExecutionCount, WorkflowHandle, WorkflowUpdateHandle
Instance Attribute Summary collapse
-
#options ⇒ Options
readonly
Frozen options for this client which has the same attributes as #initialize.
Class Method Summary collapse
Instance Method Summary collapse
-
#async_activity_handle(task_token_or_id_reference) ⇒ AsyncActivityHandle
Get an async activity handle.
-
#connection ⇒ Connection
Underlying connection for this client.
-
#count_workflows(query = nil, rpc_options: nil) ⇒ WorkflowExecutionCount
Count workflows.
-
#create_schedule(id, schedule, trigger_immediately: false, backfills: [], memo: nil, search_attributes: nil, rpc_options: nil) ⇒ ScheduleHandle
Create a schedule and return its handle.
-
#data_converter ⇒ DataConverter
Data converter used by this client.
-
#execute_update_with_start_workflow(update, *args, start_workflow_operation:, id: SecureRandom.uuid, rpc_options: nil) ⇒ Object
Start an update, possibly starting the workflow at the same time if it doesn’t exist (depending upon ID conflict policy), and wait for update result.
-
#execute_workflow(workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil) ⇒ Object
Start a workflow and wait for its result.
-
#initialize(connection:, namespace:, data_converter: DataConverter.default, interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil) ⇒ Client
constructor
Create a client from an existing connection.
-
#list_schedules(query = nil, rpc_options: nil) ⇒ Enumerator<Schedule::List::Description>
List schedules.
-
#list_workflows(query = nil, rpc_options: nil) ⇒ Enumerator<WorkflowExecution>
List workflows.
-
#namespace ⇒ String
Namespace used in calls by this client.
-
#operator_service ⇒ Connection::OperatorService
Raw gRPC operator service.
-
#schedule_handle(id) ⇒ ScheduleHandle
Get a schedule handle to an existing schedule for the given ID.
-
#signal_with_start_workflow(signal, *args, start_workflow_operation:, rpc_options: nil) ⇒ WorkflowHandle
Send a signal, possibly starting the workflow at the same time if it doesn’t exist.
-
#start_update_with_start_workflow(update, *args, start_workflow_operation:, wait_for_stage:, id: SecureRandom.uuid, rpc_options: nil) ⇒ WorkflowUpdateHandle
Start an update, possibly starting the workflow at the same time if it doesn’t exist (depending upon ID conflict policy).
-
#start_workflow(workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil) ⇒ WorkflowHandle
Start a workflow and return its handle.
-
#workflow_handle(workflow_id, run_id: nil, first_execution_run_id: nil) ⇒ WorkflowHandle
Get a workflow handle to an existing workflow by its ID.
-
#workflow_service ⇒ Connection::WorkflowService
Raw gRPC workflow service.
Constructor Details
#initialize(connection:, namespace:, data_converter: DataConverter.default, interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil) ⇒ Client
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/temporalio/client.rb', line 144 def initialize( connection:, namespace:, data_converter: DataConverter.default, interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil ) @options = Options.new( connection:, namespace:, data_converter:, interceptors:, logger:, default_workflow_query_reject_condition: ).freeze # Initialize interceptors @impl = interceptors.reverse_each.reduce(Internal::Client::Implementation.new(self)) do |acc, int| # steep:ignore int.intercept_client(acc) end end |
Instance Attribute Details
#options ⇒ Options (readonly)
Returns Frozen options for this client which has the same attributes as #initialize.
125 126 127 |
# File 'lib/temporalio/client.rb', line 125 def @options end |
Class Method Details
.connect(target_host, namespace, api_key: nil, tls: false, data_converter: Converters::DataConverter.default, interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil, rpc_metadata: {}, rpc_retry: Connection::RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: Connection::KeepAliveOptions.new, http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false) ⇒ Client
Connect to Temporal server. This is a shortcut for Connection.new
followed by Client.new
.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/temporalio/client.rb', line 86 def self.connect( target_host, namespace, api_key: nil, tls: false, data_converter: Converters::DataConverter.default, interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil, rpc_metadata: {}, rpc_retry: Connection::RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: Connection::KeepAliveOptions.new, # Set to nil to disable http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false ) Client.new( connection: Connection.new( target_host:, api_key:, tls:, rpc_metadata:, rpc_retry:, identity:, keep_alive:, http_connect_proxy:, runtime:, lazy_connect: ), namespace:, data_converter:, interceptors:, logger:, default_workflow_query_reject_condition: ) end |
Instance Method Details
#async_activity_handle(task_token_or_id_reference) ⇒ AsyncActivityHandle
Get an async activity handle.
553 554 555 556 557 558 559 560 561 |
# File 'lib/temporalio/client.rb', line 553 def async_activity_handle(task_token_or_id_reference) if task_token_or_id_reference.is_a?(ActivityIDReference) AsyncActivityHandle.new(client: self, task_token: nil, id_reference: task_token_or_id_reference) elsif task_token_or_id_reference.is_a?(String) AsyncActivityHandle.new(client: self, task_token: task_token_or_id_reference, id_reference: nil) else raise ArgumentError, 'Must be a string task token or an ActivityIDReference' end end |
#connection ⇒ Connection
Returns Underlying connection for this client.
167 168 169 |
# File 'lib/temporalio/client.rb', line 167 def connection @options.connection end |
#count_workflows(query = nil, rpc_options: nil) ⇒ WorkflowExecutionCount
Count workflows.
484 485 486 |
# File 'lib/temporalio/client.rb', line 484 def count_workflows(query = nil, rpc_options: nil) @impl.count_workflows(Interceptor::CountWorkflowsInput.new(query:, rpc_options:)) end |
#create_schedule(id, schedule, trigger_immediately: false, backfills: [], memo: nil, search_attributes: nil, rpc_options: nil) ⇒ ScheduleHandle
Create a schedule and return its handle.
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/temporalio/client.rb', line 504 def create_schedule( id, schedule, trigger_immediately: false, backfills: [], memo: nil, search_attributes: nil, rpc_options: nil ) @impl.create_schedule(Interceptor::CreateScheduleInput.new( id:, schedule:, trigger_immediately:, backfills:, memo:, search_attributes:, rpc_options: )) end |
#data_converter ⇒ DataConverter
Returns Data converter used by this client.
177 178 179 |
# File 'lib/temporalio/client.rb', line 177 def data_converter @options.data_converter end |
#execute_update_with_start_workflow(update, *args, start_workflow_operation:, id: SecureRandom.uuid, rpc_options: nil) ⇒ Object
Start an update, possibly starting the workflow at the same time if it doesn’t exist (depending upon ID conflict policy), and wait for update result. This is a shortcut for #start_update_with_start_workflow + Temporalio::Client::WorkflowUpdateHandle#result.
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/temporalio/client.rb', line 416 def execute_update_with_start_workflow( update, *args, start_workflow_operation:, id: SecureRandom.uuid, rpc_options: nil ) start_update_with_start_workflow( update, *args, start_workflow_operation:, wait_for_stage: WorkflowUpdateWaitStage::COMPLETED, id:, rpc_options: ).result end |
#execute_workflow(workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil) ⇒ Object
Start a workflow and wait for its result. This is a shortcut for #start_workflow + Temporalio::Client::WorkflowHandle#result.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/temporalio/client.rb', line 301 def execute_workflow( workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil ) start_workflow( workflow, *args, id:, task_queue:, static_summary:, static_details:, execution_timeout:, run_timeout:, task_timeout:, id_reuse_policy:, id_conflict_policy:, retry_policy:, cron_schedule:, memo:, search_attributes:, start_delay:, request_eager_start:, rpc_options: ).result end |
#list_schedules(query = nil, rpc_options: nil) ⇒ Enumerator<Schedule::List::Description>
List schedules.
Note, this list is eventually consistent. Therefore if a schedule is added or deleted, it may not be available in the list immediately.
545 546 547 |
# File 'lib/temporalio/client.rb', line 545 def list_schedules(query = nil, rpc_options: nil) @impl.list_schedules(Interceptor::ListSchedulesInput.new(query:, rpc_options:)) end |
#list_workflows(query = nil, rpc_options: nil) ⇒ Enumerator<WorkflowExecution>
List workflows.
470 471 472 |
# File 'lib/temporalio/client.rb', line 470 def list_workflows(query = nil, rpc_options: nil) @impl.list_workflows(Interceptor::ListWorkflowsInput.new(query:, rpc_options:)) end |
#namespace ⇒ String
Returns Namespace used in calls by this client.
172 173 174 |
# File 'lib/temporalio/client.rb', line 172 def namespace @options.namespace end |
#operator_service ⇒ Connection::OperatorService
Returns Raw gRPC operator service.
187 188 189 |
# File 'lib/temporalio/client.rb', line 187 def operator_service connection.operator_service end |
#schedule_handle(id) ⇒ ScheduleHandle
Get a schedule handle to an existing schedule for the given ID.
528 529 530 |
# File 'lib/temporalio/client.rb', line 528 def schedule_handle(id) ScheduleHandle.new(client: self, id:) end |
#signal_with_start_workflow(signal, *args, start_workflow_operation:, rpc_options: nil) ⇒ WorkflowHandle
Send a signal, possibly starting the workflow at the same time if it doesn’t exist.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/temporalio/client.rb', line 444 def signal_with_start_workflow( signal, *args, start_workflow_operation:, rpc_options: nil ) @impl.signal_with_start_workflow( Interceptor::SignalWithStartWorkflowInput.new( signal:, args:, start_workflow_operation:, rpc_options: ) ) end |
#start_update_with_start_workflow(update, *args, start_workflow_operation:, wait_for_stage:, id: SecureRandom.uuid, rpc_options: nil) ⇒ WorkflowUpdateHandle
Start an update, possibly starting the workflow at the same time if it doesn’t exist (depending upon ID conflict policy). Note that in some cases this may fail but the workflow will still be started, and the handle can then be retrieved on the start workflow operation.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/temporalio/client.rb', line 378 def start_update_with_start_workflow( update, *args, start_workflow_operation:, wait_for_stage:, id: SecureRandom.uuid, rpc_options: nil ) @impl.start_update_with_start_workflow( Interceptor::StartUpdateWithStartWorkflowInput.new( update_id: id, update:, args:, wait_for_stage:, start_workflow_operation:, headers: {}, rpc_options: ) ) end |
#start_workflow(workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil) ⇒ WorkflowHandle
Start a workflow and return its handle.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/temporalio/client.rb', line 224 def start_workflow( workflow, *args, id:, task_queue:, static_summary: nil, static_details: nil, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED, retry_policy: nil, cron_schedule: nil, memo: nil, search_attributes: nil, start_delay: nil, request_eager_start: false, rpc_options: nil ) @impl.start_workflow(Interceptor::StartWorkflowInput.new( workflow:, args:, workflow_id: id, task_queue:, static_summary:, static_details:, execution_timeout:, run_timeout:, task_timeout:, id_reuse_policy:, id_conflict_policy:, retry_policy:, cron_schedule:, memo:, search_attributes:, start_delay:, request_eager_start:, headers: {}, rpc_options: )) end |
#workflow_handle(workflow_id, run_id: nil, first_execution_run_id: nil) ⇒ WorkflowHandle
Get a workflow handle to an existing workflow by its ID.
352 353 354 355 356 357 358 |
# File 'lib/temporalio/client.rb', line 352 def workflow_handle( workflow_id, run_id: nil, first_execution_run_id: nil ) WorkflowHandle.new(client: self, id: workflow_id, run_id:, result_run_id: run_id, first_execution_run_id:) end |
#workflow_service ⇒ Connection::WorkflowService
Returns Raw gRPC workflow service.
182 183 184 |
# File 'lib/temporalio/client.rb', line 182 def workflow_service connection.workflow_service end |