amit-temporalio 0.3.0-aarch64-linux-musl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +2 -0
- data/Gemfile +23 -0
- data/Rakefile +101 -0
- data/lib/temporalio/activity/complete_async_error.rb +11 -0
- data/lib/temporalio/activity/context.rb +116 -0
- data/lib/temporalio/activity/definition.rb +189 -0
- data/lib/temporalio/activity/info.rb +64 -0
- data/lib/temporalio/activity.rb +12 -0
- data/lib/temporalio/api/activity/v1/message.rb +25 -0
- data/lib/temporalio/api/batch/v1/message.rb +31 -0
- data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
- data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +126 -0
- data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
- data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
- data/lib/temporalio/api/cloud/identity/v1/message.rb +41 -0
- data/lib/temporalio/api/cloud/namespace/v1/message.rb +42 -0
- data/lib/temporalio/api/cloud/nexus/v1/message.rb +31 -0
- data/lib/temporalio/api/cloud/operation/v1/message.rb +28 -0
- data/lib/temporalio/api/cloud/region/v1/message.rb +24 -0
- data/lib/temporalio/api/cloud/resource/v1/message.rb +23 -0
- data/lib/temporalio/api/cloud/sink/v1/message.rb +24 -0
- data/lib/temporalio/api/cloud/usage/v1/message.rb +31 -0
- data/lib/temporalio/api/command/v1/message.rb +46 -0
- data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
- data/lib/temporalio/api/common/v1/message.rb +47 -0
- data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
- data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
- data/lib/temporalio/api/enums/v1/common.rb +26 -0
- data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
- data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
- data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
- data/lib/temporalio/api/enums/v1/query.rb +22 -0
- data/lib/temporalio/api/enums/v1/reset.rb +23 -0
- data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
- data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
- data/lib/temporalio/api/enums/v1/update.rb +22 -0
- data/lib/temporalio/api/enums/v1/workflow.rb +30 -0
- data/lib/temporalio/api/errordetails/v1/message.rb +42 -0
- data/lib/temporalio/api/export/v1/message.rb +24 -0
- data/lib/temporalio/api/failure/v1/message.rb +35 -0
- data/lib/temporalio/api/filter/v1/message.rb +27 -0
- data/lib/temporalio/api/history/v1/message.rb +90 -0
- data/lib/temporalio/api/namespace/v1/message.rb +31 -0
- data/lib/temporalio/api/nexus/v1/message.rb +40 -0
- data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
- data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
- data/lib/temporalio/api/operatorservice.rb +3 -0
- data/lib/temporalio/api/payload_visitor.rb +1513 -0
- data/lib/temporalio/api/protocol/v1/message.rb +23 -0
- data/lib/temporalio/api/query/v1/message.rb +27 -0
- data/lib/temporalio/api/replication/v1/message.rb +26 -0
- data/lib/temporalio/api/schedule/v1/message.rb +43 -0
- data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
- data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
- data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
- data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
- data/lib/temporalio/api/taskqueue/v1/message.rb +45 -0
- data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
- data/lib/temporalio/api/testservice/v1/service.rb +23 -0
- data/lib/temporalio/api/update/v1/message.rb +33 -0
- data/lib/temporalio/api/version/v1/message.rb +26 -0
- data/lib/temporalio/api/workflow/v1/message.rb +43 -0
- data/lib/temporalio/api/workflowservice/v1/request_response.rb +204 -0
- data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
- data/lib/temporalio/api/workflowservice.rb +3 -0
- data/lib/temporalio/api.rb +14 -0
- data/lib/temporalio/cancellation.rb +170 -0
- data/lib/temporalio/client/activity_id_reference.rb +32 -0
- data/lib/temporalio/client/async_activity_handle.rb +85 -0
- data/lib/temporalio/client/connection/cloud_service.rb +726 -0
- data/lib/temporalio/client/connection/operator_service.rb +201 -0
- data/lib/temporalio/client/connection/service.rb +42 -0
- data/lib/temporalio/client/connection/test_service.rb +111 -0
- data/lib/temporalio/client/connection/workflow_service.rb +1041 -0
- data/lib/temporalio/client/connection.rb +316 -0
- data/lib/temporalio/client/interceptor.rb +416 -0
- data/lib/temporalio/client/schedule.rb +967 -0
- data/lib/temporalio/client/schedule_handle.rb +126 -0
- data/lib/temporalio/client/workflow_execution.rb +100 -0
- data/lib/temporalio/client/workflow_execution_count.rb +36 -0
- data/lib/temporalio/client/workflow_execution_status.rb +18 -0
- data/lib/temporalio/client/workflow_handle.rb +389 -0
- data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
- data/lib/temporalio/client/workflow_update_handle.rb +65 -0
- data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
- data/lib/temporalio/client.rb +484 -0
- data/lib/temporalio/common_enums.rb +41 -0
- data/lib/temporalio/converters/data_converter.rb +99 -0
- data/lib/temporalio/converters/failure_converter.rb +202 -0
- data/lib/temporalio/converters/payload_codec.rb +26 -0
- data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
- data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
- data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
- data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
- data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
- data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
- data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
- data/lib/temporalio/converters/payload_converter.rb +71 -0
- data/lib/temporalio/converters/raw_value.rb +20 -0
- data/lib/temporalio/converters.rb +9 -0
- data/lib/temporalio/error/failure.rb +219 -0
- data/lib/temporalio/error.rb +155 -0
- data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
- data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
- data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
- data/lib/temporalio/internal/bridge/api/common/common.rb +26 -0
- data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
- data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
- data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +33 -0
- data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
- data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +57 -0
- data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +30 -0
- data/lib/temporalio/internal/bridge/api.rb +3 -0
- data/lib/temporalio/internal/bridge/client.rb +95 -0
- data/lib/temporalio/internal/bridge/runtime.rb +53 -0
- data/lib/temporalio/internal/bridge/temporalio_bridge.so +0 -0
- data/lib/temporalio/internal/bridge/testing.rb +66 -0
- data/lib/temporalio/internal/bridge/worker.rb +85 -0
- data/lib/temporalio/internal/bridge.rb +36 -0
- data/lib/temporalio/internal/client/implementation.rb +700 -0
- data/lib/temporalio/internal/metric.rb +122 -0
- data/lib/temporalio/internal/proto_utils.rb +133 -0
- data/lib/temporalio/internal/worker/activity_worker.rb +376 -0
- data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
- data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
- data/lib/temporalio/internal/worker/workflow_instance/context.rb +333 -0
- data/lib/temporalio/internal/worker/workflow_instance/details.rb +44 -0
- data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
- data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
- data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
- data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
- data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
- data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
- data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +415 -0
- data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
- data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
- data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +163 -0
- data/lib/temporalio/internal/worker/workflow_instance.rb +730 -0
- data/lib/temporalio/internal/worker/workflow_worker.rb +236 -0
- data/lib/temporalio/internal.rb +7 -0
- data/lib/temporalio/metric.rb +109 -0
- data/lib/temporalio/retry_policy.rb +74 -0
- data/lib/temporalio/runtime.rb +314 -0
- data/lib/temporalio/scoped_logger.rb +96 -0
- data/lib/temporalio/search_attributes.rb +343 -0
- data/lib/temporalio/testing/activity_environment.rb +136 -0
- data/lib/temporalio/testing/workflow_environment.rb +383 -0
- data/lib/temporalio/testing.rb +10 -0
- data/lib/temporalio/version.rb +5 -0
- data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
- data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
- data/lib/temporalio/worker/activity_executor.rb +55 -0
- data/lib/temporalio/worker/interceptor.rb +362 -0
- data/lib/temporalio/worker/thread_pool.rb +237 -0
- data/lib/temporalio/worker/tuner.rb +189 -0
- data/lib/temporalio/worker/workflow_executor/thread_pool.rb +230 -0
- data/lib/temporalio/worker/workflow_executor.rb +26 -0
- data/lib/temporalio/worker/workflow_replayer.rb +343 -0
- data/lib/temporalio/worker.rb +569 -0
- data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
- data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
- data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
- data/lib/temporalio/workflow/definition.rb +566 -0
- data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
- data/lib/temporalio/workflow/future.rb +151 -0
- data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
- data/lib/temporalio/workflow/info.rb +82 -0
- data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
- data/lib/temporalio/workflow/update_info.rb +20 -0
- data/lib/temporalio/workflow.rb +529 -0
- data/lib/temporalio/workflow_history.rb +47 -0
- data/lib/temporalio.rb +11 -0
- data/temporalio.gemspec +28 -0
- metadata +236 -0
@@ -0,0 +1,213 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
require 'temporalio/internal/bridge/worker'
|
5
|
+
|
6
|
+
module Temporalio
|
7
|
+
module Internal
|
8
|
+
module Worker
|
9
|
+
# Primary worker (re)actor-style event handler. This handles multiple workers, receiving events from the bridge,
|
10
|
+
# and handling a user block.
|
11
|
+
class MultiRunner
|
12
|
+
def initialize(workers:, shutdown_signals:)
|
13
|
+
@workers = workers
|
14
|
+
@queue = Queue.new
|
15
|
+
|
16
|
+
@shutdown_initiated_mutex = Mutex.new
|
17
|
+
@shutdown_initiated = false
|
18
|
+
|
19
|
+
# Trap signals to push to queue
|
20
|
+
shutdown_signals.each do |signal|
|
21
|
+
Signal.trap(signal) { @queue.push(Event::ShutdownSignalReceived.new) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Start pollers
|
25
|
+
Bridge::Worker.async_poll_all(workers.map(&:_bridge_worker), @queue)
|
26
|
+
end
|
27
|
+
|
28
|
+
def apply_thread_or_fiber_block(&)
|
29
|
+
return unless block_given?
|
30
|
+
|
31
|
+
@thread_or_fiber = if Fiber.current_scheduler
|
32
|
+
Fiber.schedule do
|
33
|
+
@queue.push(Event::BlockSuccess.new(result: yield))
|
34
|
+
rescue InjectEventForTesting => e
|
35
|
+
@queue.push(e.event)
|
36
|
+
@queue.push(Event::BlockSuccess.new(result: e))
|
37
|
+
rescue Exception => e # rubocop:disable Lint/RescueException Intentionally catch all
|
38
|
+
@queue.push(Event::BlockFailure.new(error: e))
|
39
|
+
end
|
40
|
+
else
|
41
|
+
Thread.new do
|
42
|
+
@queue.push(Event::BlockSuccess.new(result: yield))
|
43
|
+
rescue InjectEventForTesting => e
|
44
|
+
@queue.push(e.event)
|
45
|
+
@queue.push(Event::BlockSuccess.new(result: e))
|
46
|
+
rescue Exception => e # rubocop:disable Lint/RescueException Intentionally catch all
|
47
|
+
@queue.push(Event::BlockFailure.new(error: e))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def apply_workflow_activation_decoded(workflow_worker:, activation:)
|
53
|
+
@queue.push(Event::WorkflowActivationDecoded.new(workflow_worker:, activation:))
|
54
|
+
end
|
55
|
+
|
56
|
+
def apply_workflow_activation_complete(workflow_worker:, activation_completion:, encoded:)
|
57
|
+
@queue.push(Event::WorkflowActivationComplete.new(
|
58
|
+
workflow_worker:, activation_completion:, encoded:, completion_complete_queue: @queue
|
59
|
+
))
|
60
|
+
end
|
61
|
+
|
62
|
+
def raise_in_thread_or_fiber_block(error)
|
63
|
+
@thread_or_fiber&.raise(error)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Clarify this is the only thread-safe function here
|
67
|
+
def initiate_shutdown
|
68
|
+
should_call = @shutdown_initiated_mutex.synchronize do
|
69
|
+
break false if @shutdown_initiated
|
70
|
+
|
71
|
+
@shutdown_initiated = true
|
72
|
+
end
|
73
|
+
return unless should_call
|
74
|
+
|
75
|
+
@workers.each(&:_initiate_shutdown)
|
76
|
+
end
|
77
|
+
|
78
|
+
def wait_complete_and_finalize_shutdown
|
79
|
+
# Wait for them all to complete
|
80
|
+
@workers.each(&:_wait_all_complete)
|
81
|
+
|
82
|
+
# Finalize them all
|
83
|
+
Bridge::Worker.finalize_shutdown_all(@workers.map(&:_bridge_worker))
|
84
|
+
end
|
85
|
+
|
86
|
+
# Intentionally not an enumerable/enumerator since stop semantics are
|
87
|
+
# caller determined
|
88
|
+
def next_event
|
89
|
+
# Queue value is one of the following:
|
90
|
+
# * Event - non-poller event
|
91
|
+
# * [worker index, :activity/:workflow, bytes] - poll success
|
92
|
+
# * [worker index, :activity/:workflow, error] - poll fail
|
93
|
+
# * [worker index, :activity/:workflow, nil] - worker shutdown
|
94
|
+
# * [nil, nil, nil] - all pollers done
|
95
|
+
# * [-1, run_id_string, error_or_nil] - workflow activation completion complete
|
96
|
+
result = @queue.pop
|
97
|
+
if result.is_a?(Event)
|
98
|
+
result
|
99
|
+
else
|
100
|
+
first, second, third = result
|
101
|
+
if first.nil? || second.nil?
|
102
|
+
Event::AllPollersShutDown.instance
|
103
|
+
elsif first == -1
|
104
|
+
Event::WorkflowActivationCompletionComplete.new(run_id: second, error: third)
|
105
|
+
else
|
106
|
+
worker = @workers[first]
|
107
|
+
case third
|
108
|
+
when nil
|
109
|
+
Event::PollerShutDown.new(worker:, worker_type: second)
|
110
|
+
when Exception
|
111
|
+
Event::PollFailure.new(worker:, worker_type: second, error: third)
|
112
|
+
else
|
113
|
+
Event::PollSuccess.new(worker:, worker_type: second, bytes: third)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class Event
|
120
|
+
class PollSuccess < Event
|
121
|
+
attr_reader :worker, :worker_type, :bytes
|
122
|
+
|
123
|
+
def initialize(worker:, worker_type:, bytes:) # rubocop:disable Lint/MissingSuper
|
124
|
+
@worker = worker
|
125
|
+
@worker_type = worker_type
|
126
|
+
@bytes = bytes
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class PollFailure < Event
|
131
|
+
attr_reader :worker, :worker_type, :error
|
132
|
+
|
133
|
+
def initialize(worker:, worker_type:, error:) # rubocop:disable Lint/MissingSuper
|
134
|
+
@worker = worker
|
135
|
+
@worker_type = worker_type
|
136
|
+
@error = error
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class WorkflowActivationDecoded < Event
|
141
|
+
attr_reader :workflow_worker, :activation
|
142
|
+
|
143
|
+
def initialize(workflow_worker:, activation:) # rubocop:disable Lint/MissingSuper
|
144
|
+
@workflow_worker = workflow_worker
|
145
|
+
@activation = activation
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class WorkflowActivationComplete < Event
|
150
|
+
attr_reader :workflow_worker, :activation_completion, :encoded, :completion_complete_queue
|
151
|
+
|
152
|
+
def initialize(workflow_worker:, activation_completion:, encoded:, completion_complete_queue:) # rubocop:disable Lint/MissingSuper
|
153
|
+
@workflow_worker = workflow_worker
|
154
|
+
@activation_completion = activation_completion
|
155
|
+
@encoded = encoded
|
156
|
+
@completion_complete_queue = completion_complete_queue
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class WorkflowActivationCompletionComplete < Event
|
161
|
+
attr_reader :run_id, :error
|
162
|
+
|
163
|
+
def initialize(run_id:, error:) # rubocop:disable Lint/MissingSuper
|
164
|
+
@run_id = run_id
|
165
|
+
@error = error
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
class PollerShutDown < Event
|
170
|
+
attr_reader :worker, :worker_type
|
171
|
+
|
172
|
+
def initialize(worker:, worker_type:) # rubocop:disable Lint/MissingSuper
|
173
|
+
@worker = worker
|
174
|
+
@worker_type = worker_type
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class AllPollersShutDown < Event
|
179
|
+
include Singleton
|
180
|
+
end
|
181
|
+
|
182
|
+
class BlockSuccess < Event
|
183
|
+
attr_reader :result
|
184
|
+
|
185
|
+
def initialize(result:) # rubocop:disable Lint/MissingSuper
|
186
|
+
@result = result
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
class BlockFailure < Event
|
191
|
+
attr_reader :error
|
192
|
+
|
193
|
+
def initialize(error:) # rubocop:disable Lint/MissingSuper
|
194
|
+
@error = error
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
class ShutdownSignalReceived < Event
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class InjectEventForTesting < Temporalio::Error
|
203
|
+
attr_reader :event
|
204
|
+
|
205
|
+
def initialize(event)
|
206
|
+
super('Injecting event for testing')
|
207
|
+
@event = event
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temporalio/cancellation'
|
4
|
+
require 'temporalio/workflow'
|
5
|
+
require 'temporalio/workflow/child_workflow_handle'
|
6
|
+
|
7
|
+
module Temporalio
|
8
|
+
module Internal
|
9
|
+
module Worker
|
10
|
+
class WorkflowInstance
|
11
|
+
# Implementation of the child workflow handle.
|
12
|
+
class ChildWorkflowHandle < Workflow::ChildWorkflowHandle
|
13
|
+
attr_reader :id, :first_execution_run_id
|
14
|
+
|
15
|
+
def initialize(id:, first_execution_run_id:, instance:, cancellation:, cancel_callback_key:) # rubocop:disable Lint/MissingSuper
|
16
|
+
@id = id
|
17
|
+
@first_execution_run_id = first_execution_run_id
|
18
|
+
@instance = instance
|
19
|
+
@cancellation = cancellation
|
20
|
+
@cancel_callback_key = cancel_callback_key
|
21
|
+
@resolution = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def result
|
25
|
+
# Notice that we actually provide a detached cancellation here instead of defaulting to workflow
|
26
|
+
# cancellation because we don't want workflow cancellation (or a user-provided cancellation to this result
|
27
|
+
# call) to be able to interrupt waiting on a child that may be processing the cancellation.
|
28
|
+
Workflow.wait_condition(cancellation: Cancellation.new) { @resolution }
|
29
|
+
|
30
|
+
case @resolution.status
|
31
|
+
when :completed
|
32
|
+
@instance.payload_converter.from_payload(@resolution.completed.result)
|
33
|
+
when :failed
|
34
|
+
raise @instance.failure_converter.from_failure(@resolution.failed.failure, @instance.payload_converter)
|
35
|
+
when :cancelled
|
36
|
+
raise @instance.failure_converter.from_failure(@resolution.cancelled.failure, @instance.payload_converter)
|
37
|
+
else
|
38
|
+
raise "Unrecognized resolution status: #{@resolution.status}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def _resolve(resolution)
|
43
|
+
@cancellation.remove_cancel_callback(@cancel_callback_key)
|
44
|
+
@resolution = resolution
|
45
|
+
end
|
46
|
+
|
47
|
+
def signal(signal, *args, cancellation: Workflow.cancellation)
|
48
|
+
@instance.context._signal_child_workflow(id:, signal:, args:, cancellation:)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temporalio/cancellation'
|
4
|
+
require 'temporalio/error'
|
5
|
+
require 'temporalio/internal/bridge/api'
|
6
|
+
require 'temporalio/internal/proto_utils'
|
7
|
+
require 'temporalio/internal/worker/workflow_instance'
|
8
|
+
require 'temporalio/internal/worker/workflow_instance/external_workflow_handle'
|
9
|
+
require 'temporalio/worker/interceptor'
|
10
|
+
require 'temporalio/workflow'
|
11
|
+
|
12
|
+
module Temporalio
|
13
|
+
module Internal
|
14
|
+
module Worker
|
15
|
+
class WorkflowInstance
|
16
|
+
# Context for all workflow calls. All calls in the {Workflow} class should call a method on this class and then
|
17
|
+
# this class can delegate the call as needed to other parts of the workflow instance system.
|
18
|
+
class Context
|
19
|
+
def initialize(instance)
|
20
|
+
@instance = instance
|
21
|
+
end
|
22
|
+
|
23
|
+
def all_handlers_finished?
|
24
|
+
@instance.in_progress_handlers.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def cancellation
|
28
|
+
@instance.cancellation
|
29
|
+
end
|
30
|
+
|
31
|
+
def continue_as_new_suggested
|
32
|
+
@instance.continue_as_new_suggested
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_history_length
|
36
|
+
@instance.current_history_length
|
37
|
+
end
|
38
|
+
|
39
|
+
def current_history_size
|
40
|
+
@instance.current_history_size
|
41
|
+
end
|
42
|
+
|
43
|
+
def current_update_info
|
44
|
+
Fiber[:__temporal_update_info]
|
45
|
+
end
|
46
|
+
|
47
|
+
def deprecate_patch(patch_id)
|
48
|
+
@instance.patch(patch_id:, deprecated: true)
|
49
|
+
end
|
50
|
+
|
51
|
+
def execute_activity(
|
52
|
+
activity,
|
53
|
+
*args,
|
54
|
+
task_queue:,
|
55
|
+
schedule_to_close_timeout:,
|
56
|
+
schedule_to_start_timeout:,
|
57
|
+
start_to_close_timeout:,
|
58
|
+
heartbeat_timeout:,
|
59
|
+
retry_policy:,
|
60
|
+
cancellation:,
|
61
|
+
cancellation_type:,
|
62
|
+
activity_id:,
|
63
|
+
disable_eager_execution:
|
64
|
+
)
|
65
|
+
@outbound.execute_activity(
|
66
|
+
Temporalio::Worker::Interceptor::Workflow::ExecuteActivityInput.new(
|
67
|
+
activity:,
|
68
|
+
args:,
|
69
|
+
task_queue: task_queue || info.task_queue,
|
70
|
+
schedule_to_close_timeout:,
|
71
|
+
schedule_to_start_timeout:,
|
72
|
+
start_to_close_timeout:,
|
73
|
+
heartbeat_timeout:,
|
74
|
+
retry_policy:,
|
75
|
+
cancellation:,
|
76
|
+
cancellation_type:,
|
77
|
+
activity_id:,
|
78
|
+
disable_eager_execution: disable_eager_execution || @instance.disable_eager_activity_execution,
|
79
|
+
headers: {}
|
80
|
+
)
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def execute_local_activity(
|
85
|
+
activity,
|
86
|
+
*args,
|
87
|
+
schedule_to_close_timeout:,
|
88
|
+
schedule_to_start_timeout:,
|
89
|
+
start_to_close_timeout:,
|
90
|
+
retry_policy:,
|
91
|
+
local_retry_threshold:,
|
92
|
+
cancellation:,
|
93
|
+
cancellation_type:,
|
94
|
+
activity_id:
|
95
|
+
)
|
96
|
+
@outbound.execute_local_activity(
|
97
|
+
Temporalio::Worker::Interceptor::Workflow::ExecuteLocalActivityInput.new(
|
98
|
+
activity:,
|
99
|
+
args:,
|
100
|
+
schedule_to_close_timeout:,
|
101
|
+
schedule_to_start_timeout:,
|
102
|
+
start_to_close_timeout:,
|
103
|
+
retry_policy:,
|
104
|
+
local_retry_threshold:,
|
105
|
+
cancellation:,
|
106
|
+
cancellation_type:,
|
107
|
+
activity_id:,
|
108
|
+
headers: {}
|
109
|
+
)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
def external_workflow_handle(workflow_id, run_id: nil)
|
114
|
+
ExternalWorkflowHandle.new(id: workflow_id, run_id:, instance: @instance)
|
115
|
+
end
|
116
|
+
|
117
|
+
def illegal_call_tracing_disabled(&)
|
118
|
+
@instance.illegal_call_tracing_disabled(&)
|
119
|
+
end
|
120
|
+
|
121
|
+
def info
|
122
|
+
@instance.info
|
123
|
+
end
|
124
|
+
|
125
|
+
def instance
|
126
|
+
@instance.instance
|
127
|
+
end
|
128
|
+
|
129
|
+
def initialize_continue_as_new_error(error)
|
130
|
+
@outbound.initialize_continue_as_new_error(
|
131
|
+
Temporalio::Worker::Interceptor::Workflow::InitializeContinueAsNewErrorInput.new(error:)
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
def logger
|
136
|
+
@instance.logger
|
137
|
+
end
|
138
|
+
|
139
|
+
def memo
|
140
|
+
@instance.memo
|
141
|
+
end
|
142
|
+
|
143
|
+
def metric_meter
|
144
|
+
@instance.metric_meter
|
145
|
+
end
|
146
|
+
|
147
|
+
def now
|
148
|
+
@instance.now
|
149
|
+
end
|
150
|
+
|
151
|
+
def patched(patch_id)
|
152
|
+
@instance.patch(patch_id:, deprecated: false)
|
153
|
+
end
|
154
|
+
|
155
|
+
def payload_converter
|
156
|
+
@instance.payload_converter
|
157
|
+
end
|
158
|
+
|
159
|
+
def query_handlers
|
160
|
+
@instance.query_handlers
|
161
|
+
end
|
162
|
+
|
163
|
+
def random
|
164
|
+
@instance.random
|
165
|
+
end
|
166
|
+
|
167
|
+
def replaying?
|
168
|
+
@instance.replaying
|
169
|
+
end
|
170
|
+
|
171
|
+
def search_attributes
|
172
|
+
@instance.search_attributes
|
173
|
+
end
|
174
|
+
|
175
|
+
def signal_handlers
|
176
|
+
@instance.signal_handlers
|
177
|
+
end
|
178
|
+
|
179
|
+
def sleep(duration, summary:, cancellation:)
|
180
|
+
@outbound.sleep(
|
181
|
+
Temporalio::Worker::Interceptor::Workflow::SleepInput.new(
|
182
|
+
duration:,
|
183
|
+
summary:,
|
184
|
+
cancellation:
|
185
|
+
)
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
def start_child_workflow(
|
190
|
+
workflow,
|
191
|
+
*args,
|
192
|
+
id:,
|
193
|
+
task_queue:,
|
194
|
+
cancellation:,
|
195
|
+
cancellation_type:,
|
196
|
+
parent_close_policy:,
|
197
|
+
execution_timeout:,
|
198
|
+
run_timeout:,
|
199
|
+
task_timeout:,
|
200
|
+
id_reuse_policy:,
|
201
|
+
retry_policy:,
|
202
|
+
cron_schedule:,
|
203
|
+
memo:,
|
204
|
+
search_attributes:
|
205
|
+
)
|
206
|
+
@outbound.start_child_workflow(
|
207
|
+
Temporalio::Worker::Interceptor::Workflow::StartChildWorkflowInput.new(
|
208
|
+
workflow:,
|
209
|
+
args:,
|
210
|
+
id:,
|
211
|
+
task_queue:,
|
212
|
+
cancellation:,
|
213
|
+
cancellation_type:,
|
214
|
+
parent_close_policy:,
|
215
|
+
execution_timeout:,
|
216
|
+
run_timeout:,
|
217
|
+
task_timeout:,
|
218
|
+
id_reuse_policy:,
|
219
|
+
retry_policy:,
|
220
|
+
cron_schedule:,
|
221
|
+
memo:,
|
222
|
+
search_attributes:,
|
223
|
+
headers: {}
|
224
|
+
)
|
225
|
+
)
|
226
|
+
end
|
227
|
+
|
228
|
+
def timeout(duration, exception_class, *exception_args, summary:, &)
|
229
|
+
raise 'Block required for timeout' unless block_given?
|
230
|
+
|
231
|
+
# Run timer in background and block in foreground. This gives better stack traces than a future any-of race.
|
232
|
+
# We make a detached cancellation because we don't want to link to workflow cancellation.
|
233
|
+
sleep_cancel, sleep_cancel_proc = Cancellation.new
|
234
|
+
fiber = Fiber.current
|
235
|
+
Workflow::Future.new do
|
236
|
+
Workflow.sleep(duration, summary:, cancellation: sleep_cancel)
|
237
|
+
fiber.raise(exception_class, *exception_args) if fiber.alive? # steep:ignore
|
238
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
239
|
+
# Re-raise in fiber
|
240
|
+
fiber.raise(e) if fiber.alive?
|
241
|
+
end
|
242
|
+
|
243
|
+
begin
|
244
|
+
yield
|
245
|
+
ensure
|
246
|
+
sleep_cancel_proc.call
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def update_handlers
|
251
|
+
@instance.update_handlers
|
252
|
+
end
|
253
|
+
|
254
|
+
def upsert_memo(hash)
|
255
|
+
# Convert to memo, apply updates, then add the command (so command adding is post validation)
|
256
|
+
upserted_memo = ProtoUtils.memo_to_proto(hash, payload_converter)
|
257
|
+
memo._update do |new_hash|
|
258
|
+
hash.each do |key, val|
|
259
|
+
# Nil means delete
|
260
|
+
if val.nil?
|
261
|
+
new_hash.delete(key.to_s)
|
262
|
+
else
|
263
|
+
new_hash[key.to_s] = val
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
@instance.add_command(
|
268
|
+
Bridge::Api::WorkflowCommands::WorkflowCommand.new(
|
269
|
+
modify_workflow_properties: Bridge::Api::WorkflowCommands::ModifyWorkflowProperties.new(
|
270
|
+
upserted_memo:
|
271
|
+
)
|
272
|
+
)
|
273
|
+
)
|
274
|
+
end
|
275
|
+
|
276
|
+
def upsert_search_attributes(*updates)
|
277
|
+
# Apply updates then add the command (so command adding is post validation)
|
278
|
+
search_attributes._disable_mutations = false
|
279
|
+
search_attributes.update!(*updates)
|
280
|
+
@instance.add_command(
|
281
|
+
Bridge::Api::WorkflowCommands::WorkflowCommand.new(
|
282
|
+
upsert_workflow_search_attributes: Bridge::Api::WorkflowCommands::UpsertWorkflowSearchAttributes.new(
|
283
|
+
search_attributes: updates.to_h(&:_to_proto_pair)
|
284
|
+
)
|
285
|
+
)
|
286
|
+
)
|
287
|
+
ensure
|
288
|
+
search_attributes._disable_mutations = true
|
289
|
+
end
|
290
|
+
|
291
|
+
def wait_condition(cancellation:, &)
|
292
|
+
@instance.scheduler.wait_condition(cancellation:, &)
|
293
|
+
end
|
294
|
+
|
295
|
+
def _cancel_external_workflow(id:, run_id:)
|
296
|
+
@outbound.cancel_external_workflow(
|
297
|
+
Temporalio::Worker::Interceptor::Workflow::CancelExternalWorkflowInput.new(id:, run_id:)
|
298
|
+
)
|
299
|
+
end
|
300
|
+
|
301
|
+
def _outbound=(outbound)
|
302
|
+
@outbound = outbound
|
303
|
+
end
|
304
|
+
|
305
|
+
def _signal_child_workflow(id:, signal:, args:, cancellation:)
|
306
|
+
@outbound.signal_child_workflow(
|
307
|
+
Temporalio::Worker::Interceptor::Workflow::SignalChildWorkflowInput.new(
|
308
|
+
id:,
|
309
|
+
signal:,
|
310
|
+
args:,
|
311
|
+
cancellation:,
|
312
|
+
headers: {}
|
313
|
+
)
|
314
|
+
)
|
315
|
+
end
|
316
|
+
|
317
|
+
def _signal_external_workflow(id:, run_id:, signal:, args:, cancellation:)
|
318
|
+
@outbound.signal_external_workflow(
|
319
|
+
Temporalio::Worker::Interceptor::Workflow::SignalExternalWorkflowInput.new(
|
320
|
+
id:,
|
321
|
+
run_id:,
|
322
|
+
signal:,
|
323
|
+
args:,
|
324
|
+
cancellation:,
|
325
|
+
headers: {}
|
326
|
+
)
|
327
|
+
)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Internal
|
5
|
+
module Worker
|
6
|
+
class WorkflowInstance
|
7
|
+
# Details needed to instantiate a {WorkflowInstance}.
|
8
|
+
class Details
|
9
|
+
attr_reader :namespace, :task_queue, :definition, :initial_activation, :logger, :metric_meter,
|
10
|
+
:payload_converter, :failure_converter, :interceptors, :disable_eager_activity_execution,
|
11
|
+
:illegal_calls, :workflow_failure_exception_types
|
12
|
+
|
13
|
+
def initialize(
|
14
|
+
namespace:,
|
15
|
+
task_queue:,
|
16
|
+
definition:,
|
17
|
+
initial_activation:,
|
18
|
+
logger:,
|
19
|
+
metric_meter:,
|
20
|
+
payload_converter:,
|
21
|
+
failure_converter:,
|
22
|
+
interceptors:,
|
23
|
+
disable_eager_activity_execution:,
|
24
|
+
illegal_calls:,
|
25
|
+
workflow_failure_exception_types:
|
26
|
+
)
|
27
|
+
@namespace = namespace
|
28
|
+
@task_queue = task_queue
|
29
|
+
@definition = definition
|
30
|
+
@initial_activation = initial_activation
|
31
|
+
@logger = logger
|
32
|
+
@metric_meter = metric_meter
|
33
|
+
@payload_converter = payload_converter
|
34
|
+
@failure_converter = failure_converter
|
35
|
+
@interceptors = interceptors
|
36
|
+
@disable_eager_activity_execution = disable_eager_activity_execution
|
37
|
+
@illegal_calls = illegal_calls
|
38
|
+
@workflow_failure_exception_types = workflow_failure_exception_types
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temporalio/cancellation'
|
4
|
+
require 'temporalio/workflow'
|
5
|
+
require 'temporalio/workflow/external_workflow_handle'
|
6
|
+
|
7
|
+
module Temporalio
|
8
|
+
module Internal
|
9
|
+
module Worker
|
10
|
+
class WorkflowInstance
|
11
|
+
# Implementation of the external workflow handle.
|
12
|
+
class ExternalWorkflowHandle < Workflow::ExternalWorkflowHandle
|
13
|
+
attr_reader :id, :run_id
|
14
|
+
|
15
|
+
def initialize(id:, run_id:, instance:) # rubocop:disable Lint/MissingSuper
|
16
|
+
@id = id
|
17
|
+
@run_id = run_id
|
18
|
+
@instance = instance
|
19
|
+
end
|
20
|
+
|
21
|
+
def signal(signal, *args, cancellation: Workflow.cancellation)
|
22
|
+
@instance.context._signal_external_workflow(id:, run_id:, signal:, args:, cancellation:)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cancel
|
26
|
+
@instance.context._cancel_external_workflow(id:, run_id:)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Internal
|
5
|
+
module Worker
|
6
|
+
class WorkflowInstance
|
7
|
+
# Delegator to a hash that does not allow external mutations. Used for memo.
|
8
|
+
class ExternallyImmutableHash < SimpleDelegator
|
9
|
+
def initialize(initial_hash)
|
10
|
+
super(initial_hash.freeze)
|
11
|
+
end
|
12
|
+
|
13
|
+
def _update(&)
|
14
|
+
new_hash = __getobj__.dup
|
15
|
+
yield new_hash
|
16
|
+
__setobj__(new_hash.freeze)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|