Class: Temporalio::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/client.rb,
lib/temporalio/client/plugin.rb,
lib/temporalio/client/schedule.rb,
lib/temporalio/client/connection.rb,
lib/temporalio/client/interceptor.rb,
lib/temporalio/client/activity_handle.rb,
lib/temporalio/client/schedule_handle.rb,
lib/temporalio/client/workflow_handle.rb,
lib/temporalio/client/activity_execution.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/pending_activity_state.rb,
lib/temporalio/client/workflow_update_handle.rb,
lib/temporalio/client/connection/test_service.rb,
lib/temporalio/client/activity_execution_count.rb,
lib/temporalio/client/connection/cloud_service.rb,
lib/temporalio/client/workflow_execution_count.rb,
lib/temporalio/client/activity_execution_status.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: ActivityExecutionStatus, Interceptor, PendingActivityState, Plugin, WorkflowExecutionStatus, WorkflowQueryRejectCondition, WorkflowUpdateWaitStage Classes: ActivityExecution, ActivityExecutionCount, ActivityHandle, ActivityIDReference, AsyncActivityHandle, Connection, ListWorkflowPage, Options, RPCOptions, Schedule, ScheduleHandle, WithStartWorkflowOperation, WorkflowExecution, WorkflowExecutionCount, WorkflowHandle, WorkflowUpdateHandle

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection:, namespace:, data_converter: Converters::DataConverter.default, plugins: [], interceptors: [], logger: Logger.new($stdout, level: Logger::WARN), default_workflow_query_reject_condition: nil) ⇒ Client

Create a client from an existing connection. Most users will prefer connect instead. Parameters here match Options returned from #options by intention so options can be dup’d, altered, and splatted to create a new client.

Parameters:

  • connection (Connection)

    Existing connection to create a client from.

  • namespace (String)

    Namespace to use for client calls.

  • data_converter (Converters::DataConverter) (defaults to: Converters::DataConverter.default)

    Data converter to use for all data conversions to/from payloads.

  • plugins (Array<Plugin>) (defaults to: [])

    Plugins to use for configuring clients. Any plugins that also include Worker::Plugin will automatically be applied to the worker and should not be configured explicitly on the worker. WARNING: Plugins are experimental.

  • interceptors (Array<Interceptor>) (defaults to: [])

    Set of interceptors that are chained together to allow intercepting of client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker interceptor will be used as worker interceptors too so they should not be given separately when creating a worker.

  • logger (Logger) (defaults to: Logger.new($stdout, level: Logger::WARN))

    Logger to use for this client and any workers made from this client. Defaults to stdout with warn level. Callers setting this logger are responsible for closing it.

  • default_workflow_query_reject_condition (WorkflowQueryRejectCondition, nil) (defaults to: nil)

    Default rejection condition for workflow queries if not set during query. See Temporalio::Client::WorkflowHandle#query for details on the rejection condition.

See Also:



222
223
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
# File 'lib/temporalio/client.rb', line 222

def initialize(
  connection:,
  namespace:,
  data_converter: Converters::DataConverter.default,
  plugins: [],
  interceptors: [],
  logger: Logger.new($stdout, level: Logger::WARN),
  default_workflow_query_reject_condition: nil
)
  @options = Options.new(
    connection:,
    namespace:,
    data_converter:,
    plugins:,
    interceptors:,
    logger:,
    default_workflow_query_reject_condition:
  ).freeze

  # Apply plugins
  Client._validate_plugins!(plugins)
  @options = plugins.reduce(@options) { |options, plugin| plugin.configure_client(options) }

  # Initialize interceptors
  @impl = @options.interceptors.reverse_each.reduce(
    Internal::Client::Implementation.new(self)
  ) do |acc, int| # steep:ignore
    int.intercept_client(acc)
  end
end

Instance Attribute Details

#optionsOptions (readonly)

Returns Frozen options for this client which has the same attributes as #initialize.

Returns:

  • (Options)

    Frozen options for this client which has the same attributes as #initialize.



200
201
202
# File 'lib/temporalio/client.rb', line 200

def options
  @options
end

Class Method Details

.connect(target_host, namespace, api_key: nil, tls: nil, data_converter: Converters::DataConverter.default, plugins: [], 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, dns_load_balancing: nil) ⇒ Client

Connect to Temporal server. This is a shortcut for Connection.new followed by Client.new.

Parameters:

  • target_host (String)

    host:port for the Temporal server. For local development, this is often localhost:7233.

  • namespace (String)

    Namespace to use for client calls.

  • api_key (String, nil) (defaults to: nil)

    API key for Temporal. This becomes the Authorization HTTP header with “Bearer ” prepended. This is only set if RPC metadata doesn’t already have an authorization key.

  • tls (Boolean, Connection::TLSOptions) (defaults to: nil)

    If false, do not use TLS. If true, use system default TLS options. If TLS options are present, those TLS options will be used.

  • data_converter (Converters::DataConverter) (defaults to: Converters::DataConverter.default)

    Data converter to use for all data conversions to/from payloads.

  • plugins (Array<Plugin>) (defaults to: [])

    Plugins to use for configuring clients and intercepting connection. Any plugins that also include Worker::Plugin will automatically be applied to the worker and should not be configured explicitly on the worker. WARNING: Plugins are experimental.

  • interceptors (Array<Interceptor>) (defaults to: [])

    Set of interceptors that are chained together to allow intercepting of client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker interceptor will be used as worker interceptors too so they should not be given separately when creating a worker.

  • logger (Logger) (defaults to: Logger.new($stdout, level: Logger::WARN))

    Logger to use for this client and any workers made from this client. Defaults to stdout with warn level. Callers setting this logger are responsible for closing it.

  • default_workflow_query_reject_condition (WorkflowQueryRejectCondition, nil) (defaults to: nil)

    Default rejection condition for workflow queries if not set during query. See Temporalio::Client::WorkflowHandle#query for details on the rejection condition.

  • rpc_metadata (Hash<String, String>) (defaults to: {})

    Headers to use for all calls to the server. Keys here can be overriden by per-call RPC metadata keys.

  • rpc_retry (Connection::RPCRetryOptions) (defaults to: Connection::RPCRetryOptions.new)

    Retry options for direct service calls (when opted in) or all high-level calls made by this client (which all opt-in to retries by default).

  • identity (String) (defaults to: "#{Process.pid}@#{Socket.gethostname}")

    Identity for this client.

  • keep_alive (Connection::KeepAliveOptions) (defaults to: Connection::KeepAliveOptions.new)

    Keep-alive options for the client connection. Can be set to nil to disable.

  • http_connect_proxy (Connection::HTTPConnectProxyOptions, nil) (defaults to: nil)

    Options for HTTP CONNECT proxy.

  • runtime (Runtime) (defaults to: Runtime.default)

    Runtime for this client.

  • lazy_connect (Boolean) (defaults to: false)

    If true, the client will not connect until the first call is attempted or a worker is created with it. Lazy clients cannot be used for workers if they have not performed a connection.

  • dns_load_balancing (Connection::DnsLoadBalancingOptions, nil) (defaults to: nil)

    DNS load balancing options for the connection. Default is nil (disabled). Silently disabled when http_connect_proxy is set, since the two are mutually exclusive.

Returns:

  • (Client)

    Connected client.

See Also:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/temporalio/client.rb', line 107

def self.connect(
  target_host,
  namespace,
  api_key: nil,
  tls: nil,
  data_converter: Converters::DataConverter.default,
  plugins: [],
  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,
  dns_load_balancing: nil
)
  # Prepare connection. The connection var is needed here so it can be used in callback for plugin.
  base_connection = nil
  final_connection = nil
  around_connect = if plugins.any?
                     _validate_plugins!(plugins)
                     # For plugins, we have to do an around_connect approach with Connection where we provide a
                     # no-return-value proc that is invoked with the built options and yields newly built options.
                     # The connection will have been created before, but we allow plugins to return a
                     # different/extended connection, possibly avoiding actual connection altogether.
                     proc do |options, &block|
                       # Steep simply can't comprehend these advanced inline procs
                       # steep:ignore:start

                       # Root next call
                       next_call_called = false
                       next_call = proc do |options|
                         raise 'next_call called more than once' if next_call_called

                         next_call_called = true
                         block&.call(options)
                         base_connection
                       end
                       # Go backwards, building up new next_call invocations on plugins
                       next_call = plugins.reverse_each.reduce(next_call) do |next_call, plugin|
                         proc { |options| plugin.connect_client(options, next_call) }
                       end
                       # Do call
                       final_connection = next_call.call(options)

                       # steep:ignore:end
                     end
                   end
  # Now create connection
  base_connection = Connection.new(
    target_host:,
    api_key:,
    tls:,
    rpc_metadata:,
    rpc_retry:,
    identity:,
    keep_alive:,
    http_connect_proxy:,
    runtime:,
    lazy_connect:,
    dns_load_balancing:,
    around_connect: # steep:ignore
  )

  # Create client
  Client.new(
    connection: final_connection || base_connection,
    namespace:,
    data_converter:,
    plugins:,
    interceptors:,
    logger:,
    default_workflow_query_reject_condition:
  )
end

Instance Method Details

#activity_handle(activity_id, activity_run_id: nil, result_hint: nil) ⇒ ActivityHandle

Get a handle for an existing standalone activity. Useful when the activity was started elsewhere (a different process, or by another client) and you have only its ID.

WARNING: Standalone Activities are experimental.

Parameters:

  • activity_id (String)

    ID for the activity.

  • activity_run_id (String, nil) (defaults to: nil)

    Run ID for the activity execution. If nil, operations target the latest run of the given activity ID.

  • result_hint (Object, nil) (defaults to: nil)

    Converter hint for the activity’s result. Set this when you know what type the activity returns so Temporalio::Client::ActivityHandle#result‘s deserialization uses the right hint.

Returns:



494
495
496
# File 'lib/temporalio/client.rb', line 494

def activity_handle(activity_id, activity_run_id: nil, result_hint: nil)
  ActivityHandle.new(client: self, id: activity_id, run_id: activity_run_id, result_hint:)
end

#async_activity_handle(task_token_or_id_reference) ⇒ AsyncActivityHandle

Get an async activity handle.

Parameters:

  • task_token_or_id_reference (String, ActivityIDReference)

    Task token string or activity ID reference.

Returns:



933
934
935
936
937
938
939
940
941
# File 'lib/temporalio/client.rb', line 933

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

#connectionConnection

Returns Underlying connection for this client.

Returns:

  • (Connection)

    Underlying connection for this client.



254
255
256
# File 'lib/temporalio/client.rb', line 254

def connection
  @options.connection
end

#count_activities(query, rpc_options: nil) ⇒ ActivityExecutionCount

Count standalone activities matching a visibility query.

WARNING: Standalone Activities are experimental.

Parameters:

  • query (String)

    Visibility list filter.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (ActivityExecutionCount)

    Count of activities (with per-group counts if the query had a group-by clause).

Raises:



681
682
683
# File 'lib/temporalio/client.rb', line 681

def count_activities(query, rpc_options: nil)
  @impl.count_activities(Interceptor::CountActivitiesInput.new(query:, rpc_options:))
end

#count_workflows(query = nil, rpc_options: nil) ⇒ WorkflowExecutionCount

Count workflows.

Parameters:

  • query (String, nil) (defaults to: nil)

    A Temporal visibility list filter.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:

See Also:



864
865
866
# File 'lib/temporalio/client.rb', line 864

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.

Parameters:

  • id (String)

    Unique identifier of the schedule.

  • schedule (Schedule)

    Schedule to create.

  • trigger_immediately (Boolean) (defaults to: false)

    If true, trigger one action immediately when creating the schedule.

  • backfills (Array<Schedule::Backfill>) (defaults to: [])

    Set of time periods to take actions on as if that time passed right now.

  • memo (Hash<String, Object>, nil) (defaults to: nil)

    Memo for the schedule. Memo for a scheduled workflow is part of the schedule action.

  • search_attributes (SearchAttributes, nil) (defaults to: nil)

    Search attributes for the schedule. Search attributes for a scheduled workflow are part of the scheduled action.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# File 'lib/temporalio/client.rb', line 884

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_converterDataConverter

Returns Data converter used by this client.

Returns:

  • (DataConverter)

    Data converter used by this client.



264
265
266
# File 'lib/temporalio/client.rb', line 264

def data_converter
  @options.data_converter
end

#execute_activity(activity, *args, id:, task_queue:, schedule_to_close_timeout: nil, schedule_to_start_timeout: nil, start_to_close_timeout: nil, heartbeat_timeout: nil, id_reuse_policy: ActivityIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: ActivityIDConflictPolicy::FAIL, retry_policy: nil, search_attributes: nil, static_summary: nil, static_details: nil, priority: Priority.default, start_delay: nil, arg_hints: nil, result_hint: nil, rpc_options: nil) ⇒ Object?

Start a standalone activity execution and wait for its result. Shortcut for #start_activity + Temporalio::Client::ActivityHandle#result.

WARNING: Standalone Activities are experimental.

Parameters:

  • activity (Class<Activity::Definition>, Activity::Definition, Activity::Definition::Info, Symbol, String)

    Activity definition, definition class or activity name.

  • args (Array<Object>)

    Arguments to the activity.

  • id (String)

    Unique identifier for the activity execution.

  • task_queue (String)

    Task queue to run the activity on.

  • schedule_to_close_timeout (Float, nil) (defaults to: nil)

    Schedule-to-close timeout in seconds. Either this or ‘start_to_close_timeout` must be specified.

  • schedule_to_start_timeout (Float, nil) (defaults to: nil)

    Schedule-to-start timeout in seconds.

  • start_to_close_timeout (Float, nil) (defaults to: nil)

    Start-to-close timeout in seconds. Either this or ‘schedule_to_close_timeout` must be specified.

  • heartbeat_timeout (Float, nil) (defaults to: nil)

    Heartbeat timeout in seconds.

  • id_reuse_policy (ActivityIDReusePolicy) (defaults to: ActivityIDReusePolicy::ALLOW_DUPLICATE)

    Controls behavior when an activity with the same ID was previously run and has reached a terminal state. Defaults to ‘ALLOW_DUPLICATE`.

  • id_conflict_policy (ActivityIDConflictPolicy) (defaults to: ActivityIDConflictPolicy::FAIL)

    Controls behavior when an activity with the same ID is currently running. Defaults to ‘FAIL` (reject the start attempt).

  • retry_policy (RetryPolicy, nil) (defaults to: nil)

    Retry policy for the activity.

  • search_attributes (SearchAttributes, nil) (defaults to: nil)

    Search attributes for the activity.

  • static_summary (String, nil) (defaults to: nil)

    Fixed single-line summary for this activity execution.

  • static_details (String, nil) (defaults to: nil)

    Fixed details for this activity execution. May be in markdown format.

  • priority (Priority) (defaults to: Priority.default)

    Priority for the activity. This is currently experimental.

  • start_delay (Float, nil) (defaults to: nil)

    Time (in seconds) to wait before dispatching the first activity task. This delay is not applied to retry attempts. ‘nil` or `0` means no delay. Negative values raise `ArgumentError`. This is currently experimental.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Argument hints.

  • result_hint (Object, nil) (defaults to: nil)

    Result hint.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (Object, nil)

    Successful result of the activity.

Raises:



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/temporalio/client.rb', line 615

def execute_activity(
  activity,
  *args,
  id:,
  task_queue:,
  schedule_to_close_timeout: nil,
  schedule_to_start_timeout: nil,
  start_to_close_timeout: nil,
  heartbeat_timeout: nil,
  id_reuse_policy: ActivityIDReusePolicy::ALLOW_DUPLICATE,
  id_conflict_policy: ActivityIDConflictPolicy::FAIL,
  retry_policy: nil,
  search_attributes: nil,
  static_summary: nil,
  static_details: nil,
  priority: Priority.default,
  start_delay: nil,
  arg_hints: nil,
  result_hint: nil,
  rpc_options: nil
)
  start_activity(
    activity,
    *args,
    id:,
    task_queue:,
    schedule_to_close_timeout:,
    schedule_to_start_timeout:,
    start_to_close_timeout:,
    heartbeat_timeout:,
    id_reuse_policy:,
    id_conflict_policy:,
    retry_policy:,
    search_attributes:,
    static_summary:,
    static_details:,
    priority:,
    start_delay:,
    arg_hints:,
    result_hint:,
    rpc_options:
  ).result
end

#execute_update_with_start_workflow(update, *args, start_workflow_operation:, id: SecureRandom.uuid, arg_hints: nil, result_hint: nil, 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.

Parameters:

  • update (Workflow::Definition::Update, Symbol, String)

    Update definition or name.

  • args (Array<Object>)

    Update arguments.

  • start_workflow_operation (WithStartWorkflowOperation)

    Required with-start workflow operation. This must have an ‘id_conflict_policy` set.

  • id (String) (defaults to: SecureRandom.uuid)

    ID of the update.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Overrides converter hints for update arguments if any. If unset/nil and the update definition has arg hints, those are used by default.

  • result_hint (Object, nil) (defaults to: nil)

    Overrides converter hint for update result if any. If unset/nil and the update definition has result hint, it is used by default.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (Object)

    Successful update result.

Raises:



754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
# File 'lib/temporalio/client.rb', line 754

def execute_update_with_start_workflow(
  update,
  *args,
  start_workflow_operation:,
  id: SecureRandom.uuid,
  arg_hints: nil,
  result_hint: nil,
  rpc_options: nil
)
  start_update_with_start_workflow(
    update,
    *args,
    start_workflow_operation:,
    wait_for_stage: WorkflowUpdateWaitStage::COMPLETED,
    id:,
    arg_hints:,
    result_hint:,
    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, versioning_override: nil, priority: Priority.default, arg_hints: nil, result_hint: nil, rpc_options: nil) ⇒ Object

Start a workflow and wait for its result. This is a shortcut for #start_workflow + Temporalio::Client::WorkflowHandle#result.

Parameters:

  • workflow (Class<Workflow::Definition>, Symbol, String)

    Workflow definition class or workflow name.

  • args (Array<Object>)

    Arguments to the workflow.

  • id (String)

    Unique identifier for the workflow execution.

  • task_queue (String)

    Task queue to run the workflow on.

  • static_summary (String, nil) (defaults to: nil)

    Fixed single-line summary for this workflow execution that may appear in CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.

  • static_details (String, nil) (defaults to: nil)

    Fixed details for this workflow execution that may appear in CLI/UI. This can be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be updated. For details that can be updated, use Workflow.current_details= within the workflow. This is currently experimental.

  • execution_timeout (Float, nil) (defaults to: nil)

    Total workflow execution timeout in seconds including retries and continue as new.

  • run_timeout (Float, nil) (defaults to: nil)

    Timeout of a single workflow run in seconds.

  • task_timeout (Float, nil) (defaults to: nil)

    Timeout of a single workflow task in seconds.

  • id_reuse_policy (WorkflowIDReusePolicy) (defaults to: WorkflowIDReusePolicy::ALLOW_DUPLICATE)

    How already-existing IDs are treated.

  • id_conflict_policy (WorkflowIDConflictPolicy) (defaults to: WorkflowIDConflictPolicy::UNSPECIFIED)

    How already-running workflows of the same ID are treated. Default is unspecified which effectively means fail the start attempt. This cannot be set if ‘id_reuse_policy` is set to terminate if running.

  • retry_policy (RetryPolicy, nil) (defaults to: nil)

    Retry policy for the workflow.

  • cron_schedule (String, nil) (defaults to: nil)

    Cron schedule. Users should use schedules instead of this.

  • memo (Hash{String, Symbol => Object}, nil) (defaults to: nil)

    Memo for the workflow.

  • search_attributes (SearchAttributes, nil) (defaults to: nil)

    Search attributes for the workflow.

  • start_delay (Float, nil) (defaults to: nil)

    Amount of time in seconds to wait before starting the workflow. This does not work with ‘cron_schedule`.

  • request_eager_start (Boolean) (defaults to: false)

    Potentially reduce the latency to start this workflow by encouraging the server to start it on a local worker running with this same client. This is currently experimental.

  • versioning_override (VersioningOverride, nil) (defaults to: nil)

    Override the version of the workflow.

  • priority (Priority) (defaults to: Priority.default)

    Priority for the workflow. This is currently experimental.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Overrides converter hints for arguments if any. If unset/nil and the workflow definition has arg hints, those are used by default.

  • result_hint (Object, nil) (defaults to: nil)

    Overrides converter hint for result if any. If unset/nil and the workflow definition has result hint, it is used by default.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (Object)

    Successful result of the workflow.

Raises:



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/temporalio/client.rb', line 411

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,
  versioning_override: nil,
  priority: Priority.default,
  arg_hints: nil,
  result_hint: nil,
  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:,
    versioning_override:,
    priority:,
    arg_hints:,
    result_hint:,
    rpc_options:
  ).result
end

#list_activities(query, rpc_options: nil) ⇒ Enumerator<ActivityExecution>

List standalone activities matching a visibility query.

WARNING: Standalone Activities are experimental.

Parameters:

  • query (String)

    Visibility list filter.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (Enumerator<ActivityExecution>)

    Lazy enumerable of matching activity executions.

Raises:



668
669
670
# File 'lib/temporalio/client.rb', line 668

def list_activities(query, rpc_options: nil)
  @impl.list_activities(Interceptor::ListActivitiesInput.new(query:, rpc_options:))
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.

Parameters:

  • query (String) (defaults to: nil)

    A Temporal visibility list filter.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:

See Also:



925
926
927
# File 'lib/temporalio/client.rb', line 925

def list_schedules(query = nil, rpc_options: nil)
  @impl.list_schedules(Interceptor::ListSchedulesInput.new(query:, rpc_options:))
end

#list_workflow_page(query = nil, page_size: nil, next_page_token: nil, rpc_options: nil) ⇒ ListWorkflowPage

List workflows one page at a time.

Parameters:

  • query (String, nil) (defaults to: nil)

    A Temporal visibility list filter.

  • page_size (Integer, nil) (defaults to: nil)

    Maximum number of results to return.

  • next_page_token (String, nil) (defaults to: nil)

    Token for the next page of results. If not set, the first page is returned.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (ListWorkflowPage)

    Page of workflow executions, along with a next_page_token to keep fetching.

Raises:

See Also:



847
848
849
850
851
852
# File 'lib/temporalio/client.rb', line 847

def list_workflow_page(query = nil, page_size: nil, next_page_token: nil, rpc_options: nil)
  @impl.list_workflow_page(Interceptor::ListWorkflowPageInput.new(query:,
                                                                  next_page_token:,
                                                                  page_size:,
                                                                  rpc_options:))
end

#list_workflows(query = nil, rpc_options: nil) ⇒ Enumerator<WorkflowExecution>

List workflows.

Parameters:

  • query (String, nil) (defaults to: nil)

    A Temporal visibility list filter.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:

See Also:



817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/temporalio/client.rb', line 817

def list_workflows(query = nil, rpc_options: nil)
  next_page_token = nil
  Enumerator.new do |yielder|
    loop do
      list_workflow_page_input = Interceptor::ListWorkflowPageInput.new(
        query: query,
        rpc_options: rpc_options,
        next_page_token: next_page_token,
        page_size: nil
      )
      page = @impl.list_workflow_page(list_workflow_page_input)
      page.executions.each { |execution| yielder << execution }
      next_page_token = page.next_page_token
      break if (next_page_token || '').empty?
    end
  end
end

#namespaceString

Returns Namespace used in calls by this client.

Returns:

  • (String)

    Namespace used in calls by this client.



259
260
261
# File 'lib/temporalio/client.rb', line 259

def namespace
  @options.namespace
end

#operator_serviceConnection::OperatorService

Returns Raw gRPC operator service.

Returns:



274
275
276
# File 'lib/temporalio/client.rb', line 274

def operator_service
  connection.operator_service
end

#schedule_handle(id) ⇒ ScheduleHandle

Get a schedule handle to an existing schedule for the given ID.

Parameters:

  • id (String)

    Schedule ID to get a handle to.

Returns:



908
909
910
# File 'lib/temporalio/client.rb', line 908

def schedule_handle(id)
  ScheduleHandle.new(client: self, id:)
end

#signal_with_start_workflow(signal, *args, start_workflow_operation:, arg_hints: nil, rpc_options: nil) ⇒ WorkflowHandle

Send a signal, possibly starting the workflow at the same time if it doesn’t exist.

Parameters:

  • signal (Workflow::Definition::Signal, Symbol, String)

    Signal definition or name.

  • args (Array<Object>)

    Signal arguments.

  • start_workflow_operation (WithStartWorkflowOperation)

    Required with-start workflow operation. This may not support all ‘id_conflict_policy` options.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Overrides converter hints for signal arguments if any. If unset/nil and the signal definition has arg hints, those are used by default.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
# File 'lib/temporalio/client.rb', line 788

def signal_with_start_workflow(
  signal,
  *args,
  start_workflow_operation:,
  arg_hints: nil,
  rpc_options: nil
)
  signal, defn_arg_hints = Workflow::Definition::Signal._name_and_hints_from_parameter(signal)
  @impl.signal_with_start_workflow(
    Interceptor::SignalWithStartWorkflowInput.new(
      signal:,
      args:,
      start_workflow_operation:,
      arg_hints: arg_hints || defn_arg_hints,
      rpc_options:
    )
  )
end

#start_activity(activity, *args, id:, task_queue:, schedule_to_close_timeout: nil, schedule_to_start_timeout: nil, start_to_close_timeout: nil, heartbeat_timeout: nil, id_reuse_policy: ActivityIDReusePolicy::ALLOW_DUPLICATE, id_conflict_policy: ActivityIDConflictPolicy::FAIL, retry_policy: nil, search_attributes: nil, static_summary: nil, static_details: nil, priority: Priority.default, start_delay: nil, arg_hints: nil, result_hint: nil, rpc_options: nil) ⇒ ActivityHandle

Start a standalone activity execution and return its handle.

WARNING: Standalone Activities are experimental.

Parameters:

  • activity (Class<Activity::Definition>, Activity::Definition, Activity::Definition::Info, Symbol, String)

    Activity definition, definition class or activity name.

  • args (Array<Object>)

    Arguments to the activity.

  • id (String)

    Unique identifier for the activity execution.

  • task_queue (String)

    Task queue to run the activity on.

  • schedule_to_close_timeout (Float, nil) (defaults to: nil)

    Schedule-to-close timeout in seconds. Either this or ‘start_to_close_timeout` must be specified.

  • schedule_to_start_timeout (Float, nil) (defaults to: nil)

    Schedule-to-start timeout in seconds.

  • start_to_close_timeout (Float, nil) (defaults to: nil)

    Start-to-close timeout in seconds. Either this or ‘schedule_to_close_timeout` must be specified.

  • heartbeat_timeout (Float, nil) (defaults to: nil)

    Heartbeat timeout in seconds.

  • id_reuse_policy (ActivityIDReusePolicy) (defaults to: ActivityIDReusePolicy::ALLOW_DUPLICATE)

    Controls behavior when an activity with the same ID was previously run and has reached a terminal state. Defaults to ‘ALLOW_DUPLICATE`.

  • id_conflict_policy (ActivityIDConflictPolicy) (defaults to: ActivityIDConflictPolicy::FAIL)

    Controls behavior when an activity with the same ID is currently running. Defaults to ‘FAIL` (reject the start attempt).

  • retry_policy (RetryPolicy, nil) (defaults to: nil)

    Retry policy for the activity.

  • search_attributes (SearchAttributes, nil) (defaults to: nil)

    Search attributes for the activity.

  • static_summary (String, nil) (defaults to: nil)

    Fixed single-line summary for this activity execution.

  • static_details (String, nil) (defaults to: nil)

    Fixed details for this activity execution. May be in markdown format.

  • priority (Priority) (defaults to: Priority.default)

    Priority for the activity. This is currently experimental.

  • start_delay (Float, nil) (defaults to: nil)

    Time (in seconds) to wait before dispatching the first activity task. This delay is not applied to retry attempts. ‘nil` or `0` means no delay. Negative values raise `ArgumentError`. This is currently experimental.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Argument hints.

  • result_hint (Object, nil) (defaults to: nil)

    Result hint.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/temporalio/client.rb', line 532

def start_activity(
  activity,
  *args,
  id:,
  task_queue:,
  schedule_to_close_timeout: nil,
  schedule_to_start_timeout: nil,
  start_to_close_timeout: nil,
  heartbeat_timeout: nil,
  id_reuse_policy: ActivityIDReusePolicy::ALLOW_DUPLICATE,
  id_conflict_policy: ActivityIDConflictPolicy::FAIL,
  retry_policy: nil,
  search_attributes: nil,
  static_summary: nil,
  static_details: nil,
  priority: Priority.default,
  start_delay: nil,
  arg_hints: nil,
  result_hint: nil,
  rpc_options: nil
)
  activity_name, defn_arg_hints, defn_result_hint =
    Activity::Definition::Info._type_and_hints_from_parameter(activity)
  @impl.start_activity(Interceptor::StartActivityInput.new(
                         activity: activity_name,
                         args:,
                         activity_id: id,
                         task_queue:,
                         schedule_to_close_timeout:,
                         schedule_to_start_timeout:,
                         start_to_close_timeout:,
                         heartbeat_timeout:,
                         id_reuse_policy:,
                         id_conflict_policy:,
                         retry_policy:,
                         search_attributes:,
                         static_summary:,
                         static_details:,
                         headers: {},
                         priority:,
                         start_delay:,
                         arg_hints: arg_hints || defn_arg_hints,
                         result_hint: result_hint || defn_result_hint,
                         rpc_options:
                       ))
end

#start_update_with_start_workflow(update, *args, start_workflow_operation:, wait_for_stage:, id: SecureRandom.uuid, arg_hints: nil, result_hint: nil, 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.

Parameters:

  • update (Workflow::Definition::Update, Symbol, String)

    Update definition or name.

  • args (Array<Object>)

    Update arguments.

  • start_workflow_operation (WithStartWorkflowOperation)

    Required with-start workflow operation. This must have an ‘id_conflict_policy` set.

  • wait_for_stage (WorkflowUpdateWaitStage)

    Required stage to wait until returning. ADMITTED is not currently supported. See docs.temporal.io/workflows#update for more details.

  • id (String) (defaults to: SecureRandom.uuid)

    ID of the update.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Overrides converter hints for update arguments if any. If unset/nil and the update definition has arg hints, those are used by default.

  • result_hint (Object, nil) (defaults to: nil)

    Overrides converter hint for update result if any. If unset/nil and the update definition has result hint, it is used by default.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/temporalio/client.rb', line 707

def start_update_with_start_workflow(
  update,
  *args,
  start_workflow_operation:,
  wait_for_stage:,
  id: SecureRandom.uuid,
  arg_hints: nil,
  result_hint: nil,
  rpc_options: nil
)
  update, defn_arg_hints, defn_result_hint = Workflow::Definition::Update._name_and_hints_from_parameter(update)
  @impl.start_update_with_start_workflow(
    Interceptor::StartUpdateWithStartWorkflowInput.new(
      update_id: id,
      update:,
      args:,
      wait_for_stage:,
      start_workflow_operation:,
      arg_hints: arg_hints || defn_arg_hints,
      result_hint: result_hint || defn_result_hint,
      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, versioning_override: nil, priority: Priority.default, arg_hints: nil, result_hint: nil, rpc_options: nil) ⇒ WorkflowHandle

Start a workflow and return its handle.

Parameters:

  • workflow (Class<Workflow::Definition>, String, Symbol)

    Workflow definition class or workflow name.

  • args (Array<Object>)

    Arguments to the workflow.

  • id (String)

    Unique identifier for the workflow execution.

  • task_queue (String)

    Task queue to run the workflow on.

  • static_summary (String, nil) (defaults to: nil)

    Fixed single-line summary for this workflow execution that may appear in CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.

  • static_details (String, nil) (defaults to: nil)

    Fixed details for this workflow execution that may appear in CLI/UI. This can be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be updated. For details that can be updated, use Workflow.current_details= within the workflow. This is currently experimental.

  • execution_timeout (Float, nil) (defaults to: nil)

    Total workflow execution timeout in seconds including retries and continue as new.

  • run_timeout (Float, nil) (defaults to: nil)

    Timeout of a single workflow run in seconds.

  • task_timeout (Float, nil) (defaults to: nil)

    Timeout of a single workflow task in seconds.

  • id_reuse_policy (WorkflowIDReusePolicy) (defaults to: WorkflowIDReusePolicy::ALLOW_DUPLICATE)

    How already-existing IDs are treated.

  • id_conflict_policy (WorkflowIDConflictPolicy) (defaults to: WorkflowIDConflictPolicy::UNSPECIFIED)

    How already-running workflows of the same ID are treated. Default is unspecified which effectively means fail the start attempt. This cannot be set if ‘id_reuse_policy` is set to terminate if running.

  • retry_policy (RetryPolicy, nil) (defaults to: nil)

    Retry policy for the workflow.

  • cron_schedule (String, nil) (defaults to: nil)

    Cron schedule. Users should use schedules instead of this.

  • memo (Hash{String, Symbol => Object}, nil) (defaults to: nil)

    Memo for the workflow.

  • search_attributes (SearchAttributes, nil) (defaults to: nil)

    Search attributes for the workflow.

  • start_delay (Float, nil) (defaults to: nil)

    Amount of time in seconds to wait before starting the workflow. This does not work with ‘cron_schedule`.

  • request_eager_start (Boolean) (defaults to: false)

    Potentially reduce the latency to start this workflow by encouraging the server to start it on a local worker running with this same client. This is currently experimental.

  • versioning_override (VersioningOverride, nil) (defaults to: nil)

    Override the version of the workflow.

  • priority (Priority) (defaults to: Priority.default)

    Priority of the workflow. This is currently experimental.

  • arg_hints (Array<Object>, nil) (defaults to: nil)

    Overrides converter hints for arguments if any. If unset/nil and the workflow definition has arg hints, those are used by default.

  • result_hint (Object, nil) (defaults to: nil)

    Overrides converter hint for result if any. If unset/nil and the workflow definition has result hint, it is used by default.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/temporalio/client.rb', line 317

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,
  versioning_override: nil,
  priority: Priority.default,
  arg_hints: nil,
  result_hint: nil,
  rpc_options: nil
)
  # Take hints from definition if there is a definition
  workflow, defn_arg_hints, defn_result_hint =
    Workflow::Definition._workflow_type_and_hints_from_workflow_parameter(workflow)
  @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: {},
                         versioning_override:,
                         priority:,
                         arg_hints: arg_hints || defn_arg_hints,
                         result_hint: result_hint || defn_result_hint,
                         rpc_options:
                       ))
end

#workflow_handle(workflow_id, run_id: nil, first_execution_run_id: nil, result_hint: nil) ⇒ WorkflowHandle

Get a workflow handle to an existing workflow by its ID.

Parameters:

  • workflow_id (String)

    Workflow ID to get a handle to.

  • run_id (String, nil) (defaults to: nil)

    Run ID that will be used for all calls. Many choose to leave this unset which ensures interactions occur on the latest of the workflow ID.

  • first_execution_run_id (String, nil) (defaults to: nil)

    First execution run ID used for some calls like cancellation and termination to ensure the affected workflow is only within the same chain as this given run ID.

  • result_hint (Object, nil) (defaults to: nil)

    Converter hint for the workflow’s result.

Returns:



471
472
473
474
475
476
477
478
479
480
# File 'lib/temporalio/client.rb', line 471

def workflow_handle(
  workflow_id,
  run_id: nil,
  first_execution_run_id: nil,
  result_hint: nil
)
  WorkflowHandle.new(
    client: self, id: workflow_id, run_id:, result_run_id: run_id, first_execution_run_id:, result_hint:
  )
end

#workflow_serviceConnection::WorkflowService

Returns Raw gRPC workflow service.

Returns:



269
270
271
# File 'lib/temporalio/client.rb', line 269

def workflow_service
  connection.workflow_service
end