4
4
require 'securerandom'
5
5
require 'temporal/configuration'
6
6
require 'temporal/execution_options'
7
- require 'temporal/client '
7
+ require 'temporal/connection '
8
8
require 'temporal/activity'
9
9
require 'temporal/activity/async_token'
10
10
require 'temporal/workflow'
@@ -21,10 +21,10 @@ def start_workflow(workflow, *input, **args)
21
21
options = args . delete ( :options ) || { }
22
22
input << args unless args . empty?
23
23
24
- execution_options = ExecutionOptions . new ( workflow , options )
24
+ execution_options = ExecutionOptions . new ( workflow , options , config . default_execution_options )
25
25
workflow_id = options [ :workflow_id ] || SecureRandom . uuid
26
26
27
- response = client . start_workflow_execution (
27
+ response = connection . start_workflow_execution (
28
28
namespace : execution_options . namespace ,
29
29
workflow_id : workflow_id ,
30
30
workflow_name : execution_options . name ,
@@ -45,10 +45,10 @@ def schedule_workflow(workflow, cron_schedule, *input, **args)
45
45
options = args . delete ( :options ) || { }
46
46
input << args unless args . empty?
47
47
48
- execution_options = ExecutionOptions . new ( workflow , options )
48
+ execution_options = ExecutionOptions . new ( workflow , options , config . default_execution_options )
49
49
workflow_id = options [ :workflow_id ] || SecureRandom . uuid
50
50
51
- response = client . start_workflow_execution (
51
+ response = connection . start_workflow_execution (
52
52
namespace : execution_options . namespace ,
53
53
workflow_id : workflow_id ,
54
54
workflow_name : execution_options . name ,
@@ -69,13 +69,13 @@ def schedule_workflow(workflow, cron_schedule, *input, **args)
69
69
end
70
70
71
71
def register_namespace ( name , description = nil )
72
- client . register_namespace ( name : name , description : description )
72
+ connection . register_namespace ( name : name , description : description )
73
73
end
74
74
75
75
def signal_workflow ( workflow , signal , workflow_id , run_id , input = nil )
76
- execution_options = ExecutionOptions . new ( workflow )
76
+ execution_options = ExecutionOptions . new ( workflow , { } , config . default_execution_options )
77
77
78
- client . signal_workflow_execution (
78
+ connection . signal_workflow_execution (
79
79
namespace : execution_options . namespace , # TODO: allow passing namespace instead
80
80
workflow_id : workflow_id ,
81
81
run_id : run_id ,
@@ -95,11 +95,11 @@ def signal_workflow(workflow, signal, workflow_id, run_id, input = nil)
95
95
# namespace: if nil, choose the one declared on the Workflow, or the global default
96
96
def await_workflow_result ( workflow , workflow_id :, run_id : nil , timeout : nil , namespace : nil )
97
97
options = namespace ? { namespace : namespace } : { }
98
- execution_options = ExecutionOptions . new ( workflow , options )
99
- max_timeout = Temporal ::Client :: GRPCClient ::SERVER_MAX_GET_WORKFLOW_EXECUTION_HISTORY_POLL
98
+ execution_options = ExecutionOptions . new ( workflow , options , config . default_execution_options )
99
+ max_timeout = Temporal ::Connection :: GRPC ::SERVER_MAX_GET_WORKFLOW_EXECUTION_HISTORY_POLL
100
100
history_response = nil
101
101
begin
102
- history_response = client . get_workflow_execution_history (
102
+ history_response = connection . get_workflow_execution_history (
103
103
namespace : execution_options . namespace ,
104
104
workflow_id : workflow_id ,
105
105
run_id : run_id ,
@@ -143,7 +143,7 @@ def reset_workflow(namespace, workflow_id, run_id, workflow_task_id: nil, reason
143
143
workflow_task_id ||= get_last_completed_workflow_task_id ( namespace , workflow_id , run_id )
144
144
raise Error , 'Could not find a completed workflow task event' unless workflow_task_id
145
145
146
- response = client . reset_workflow_execution (
146
+ response = connection . reset_workflow_execution (
147
147
namespace : namespace ,
148
148
workflow_id : workflow_id ,
149
149
run_id : run_id ,
@@ -157,7 +157,7 @@ def reset_workflow(namespace, workflow_id, run_id, workflow_task_id: nil, reason
157
157
def terminate_workflow ( workflow_id , namespace : nil , run_id : nil , reason : nil , details : nil )
158
158
namespace ||= Temporal . configuration . namespace
159
159
160
- client . terminate_workflow_execution (
160
+ connection . terminate_workflow_execution (
161
161
namespace : namespace ,
162
162
workflow_id : workflow_id ,
163
163
run_id : run_id ,
@@ -167,7 +167,7 @@ def terminate_workflow(workflow_id, namespace: nil, run_id: nil, reason: nil, de
167
167
end
168
168
169
169
def fetch_workflow_execution_info ( namespace , workflow_id , run_id )
170
- response = client . describe_workflow_execution (
170
+ response = connection . describe_workflow_execution (
171
171
namespace : namespace ,
172
172
workflow_id : workflow_id ,
173
173
run_id : run_id
@@ -179,7 +179,7 @@ def fetch_workflow_execution_info(namespace, workflow_id, run_id)
179
179
def complete_activity ( async_token , result = nil )
180
180
details = Activity ::AsyncToken . decode ( async_token )
181
181
182
- client . respond_activity_task_completed_by_id (
182
+ connection . respond_activity_task_completed_by_id (
183
183
namespace : details . namespace ,
184
184
activity_id : details . activity_id ,
185
185
workflow_id : details . workflow_id ,
@@ -191,7 +191,7 @@ def complete_activity(async_token, result = nil)
191
191
def fail_activity ( async_token , exception )
192
192
details = Activity ::AsyncToken . decode ( async_token )
193
193
194
- client . respond_activity_task_failed_by_id (
194
+ connection . respond_activity_task_failed_by_id (
195
195
namespace : details . namespace ,
196
196
activity_id : details . activity_id ,
197
197
workflow_id : details . workflow_id ,
@@ -201,19 +201,20 @@ def fail_activity(async_token, exception)
201
201
end
202
202
203
203
def configure ( &block )
204
- yield configuration
204
+ yield config
205
205
end
206
206
207
207
def configuration
208
- @configuration ||= Configuration . new
208
+ warn '[DEPRECATION] This method is now deprecated without a substitution'
209
+ config
209
210
end
210
211
211
212
def logger
212
- configuration . logger
213
+ config . logger
213
214
end
214
215
215
216
def metrics
216
- @metrics ||= Metrics . new ( configuration . metrics_adapter )
217
+ @metrics ||= Metrics . new ( config . metrics_adapter )
217
218
end
218
219
219
220
class ResultConverter
@@ -222,13 +223,17 @@ class ResultConverter
222
223
private_constant :ResultConverter
223
224
224
225
private
226
+
227
+ def config
228
+ @config ||= Configuration . new
229
+ end
225
230
226
- def client
227
- @client ||= Temporal ::Client . generate
231
+ def connection
232
+ @connection ||= Temporal ::Connection . generate ( config . for_connection )
228
233
end
229
234
230
235
def get_last_completed_workflow_task_id ( namespace , workflow_id , run_id )
231
- history_response = client . get_workflow_execution_history (
236
+ history_response = connection . get_workflow_execution_history (
232
237
namespace : namespace ,
233
238
workflow_id : workflow_id ,
234
239
run_id : run_id
0 commit comments