Class: Temporalio::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/client.rb,
lib/temporalio/client/implementation.rb,
lib/temporalio/client/workflow_handle.rb

Defined Under Namespace

Classes: Implementation, WorkflowHandle

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, namespace, interceptors: [], data_converter: Temporalio::DataConverter.new) ⇒ Client

Create a Temporal client from a connection.

Parameters:

  • connection (Temporalio::Connection)

    A connection to the Temporal server.

  • namespace (String)

    Namespace to use for client calls.

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

    List of interceptors for intercepting client calls. Executed in their original order.

  • data_converter (Temporalio::DataConverter) (defaults to: Temporalio::DataConverter.new)

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

See Also:



28
29
30
31
32
33
34
35
36
# File 'lib/temporalio/client.rb', line 28

def initialize(
  connection,
  namespace,
  interceptors: [],
  data_converter: Temporalio::DataConverter.new
)
  @namespace = namespace
  @implementation = Client::Implementation.new(connection, namespace, data_converter, interceptors)
end

Instance Attribute Details

#namespaceString (readonly)

Returns Namespace used for client calls.

Returns:

  • (String)

    Namespace used for client calls.



15
16
17
# File 'lib/temporalio/client.rb', line 15

def namespace
  @namespace
end

Instance Method Details

#start_workflow(workflow, *args, id:, task_queue:, execution_timeout: nil, run_timeout: nil, task_timeout: nil, id_reuse_policy: Workflow::IDReusePolicy::ALLOW_DUPLICATE, retry_policy: nil, cron_schedule: '', memo: nil, search_attributes: nil, start_signal: nil, start_signal_args: [], rpc_metadata: {}, rpc_timeout: nil) ⇒ Temporalio::Client::WorkflowHandle

Start a workflow and return its handle.

Parameters:

  • workflow (String)

    Name of the workflow.

  • args (any)

    Arguments to the workflow.

  • id (String)

    Unique identifier for the workflow execution.

  • task_queue (String, Symbol)

    Task queue to run the workflow on.

  • execution_timeout (Integer) (defaults to: nil)

    Total workflow execution timeout including retries and continue as new.

  • run_timeout (Integer) (defaults to: nil)

    Timeout of a single workflow run.

  • task_timeout (Integer) (defaults to: nil)

    Timeout of a single workflow task.

  • id_reuse_policy (Symbol) (defaults to: Workflow::IDReusePolicy::ALLOW_DUPLICATE)

    How already-existing IDs are treated. Refer to Workflow::IDReusePolicy for the list of allowed values.

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

    Retry policy for the workflow. See RetryPolicy.

  • cron_schedule (String) (defaults to: '')
  • memo (Hash<String, any>) (defaults to: nil)

    Memo for the workflow.

  • search_attributes (Hash<String, any>) (defaults to: nil)

    Search attributes for the workflow.

  • start_signal (String, Symbol) (defaults to: nil)

    If present, this signal is sent as signal-with-start instead of traditional workflow start.

  • start_signal_args (Array<any>) (defaults to: [])

    Arguments for start_signal if ‘:start_signal` present.

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

    Headers used on the RPC call. Keys here override client-level RPC metadata keys.

  • rpc_timeout (Integer) (defaults to: nil)

    Optional RPC deadline to set for the RPC call.

Returns:

Raises:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/temporalio/client.rb', line 66

def start_workflow( # rubocop:disable Metrics/ParameterLists
  workflow,
  *args,
  id:,
  task_queue:,
  execution_timeout: nil,
  run_timeout: nil,
  task_timeout: nil,
  id_reuse_policy: Workflow::IDReusePolicy::ALLOW_DUPLICATE,
  retry_policy: nil,
  cron_schedule: '',
  memo: nil,
  search_attributes: nil,
  start_signal: nil,
  start_signal_args: [],
  rpc_metadata: {},
  rpc_timeout: nil
)
  input = Interceptor::Client::StartWorkflowInput.new(
    workflow: workflow,
    args: args,
    id: id,
    task_queue: task_queue,
    execution_timeout: execution_timeout,
    run_timeout: run_timeout,
    task_timeout: task_timeout,
    id_reuse_policy: id_reuse_policy,
    retry_policy: retry_policy,
    cron_schedule: cron_schedule,
    memo: memo,
    search_attributes: search_attributes,
    headers: {},
    start_signal: start_signal,
    start_signal_args: start_signal_args,
    rpc_metadata: ,
    rpc_timeout: rpc_timeout,
  )

  implementation.start_workflow(input)
end

#workflow_handle(id, run_id: nil, first_execution_run_id: nil) ⇒ Temporalio::Client::WorkflowHandle

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

Parameters:

  • 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. If omitted, the latest run for a given workflow ID will be referenced.

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

    A run ID referencing the first workflow execution in a chain. Workflows are chained when using continue-as-new, retries (as permitted by the retry policy) or cron executions.

Returns:



117
118
119
120
121
122
123
124
125
# File 'lib/temporalio/client.rb', line 117

def workflow_handle(id, run_id: nil, first_execution_run_id: nil)
  WorkflowHandle.new(
    implementation,
    id,
    run_id: run_id,
    result_run_id: run_id,
    first_execution_run_id: first_execution_run_id,
  )
end