-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathstarter.rb
More file actions
32 lines (28 loc) · 998 Bytes
/
starter.rb
File metadata and controls
32 lines (28 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true
require 'temporalio/client'
require 'temporalio/env_config'
# Create a client
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)
command, workflow_id = ARGV
raise('Missing command argument. Valid commands are start and query') if command.nil?
raise('Missing workflow_id') if workflow_id.nil?
case command
when 'start'
# Start a workflow with the given id
client.start_workflow(
:MyWorkflow,
id: workflow_id,
task_queue: 'patching-sample'
)
puts "Started workflow with id #{workflow_id}"
when 'query'
# Obtain a workflow handle for the given id and query the result
handle = client.workflow_handle(workflow_id)
result = handle.query(:result)
puts "Query result for id #{workflow_id}: #{result}"
else
raise('Invalid command. Valid commands are start and query')
end