temporalio 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/Cargo.lock +659 -370
- data/Cargo.toml +2 -2
- data/Gemfile +3 -3
- data/README.md +589 -47
- data/Rakefile +10 -296
- data/ext/Cargo.toml +1 -0
- data/lib/temporalio/activity/complete_async_error.rb +1 -1
- data/lib/temporalio/activity/context.rb +5 -2
- data/lib/temporalio/activity/definition.rb +163 -65
- data/lib/temporalio/activity/info.rb +22 -21
- data/lib/temporalio/activity.rb +2 -59
- data/lib/temporalio/api/activity/v1/message.rb +25 -0
- data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
- data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +34 -1
- data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +1 -1
- data/lib/temporalio/api/cloud/identity/v1/message.rb +6 -1
- data/lib/temporalio/api/cloud/namespace/v1/message.rb +8 -1
- data/lib/temporalio/api/cloud/nexus/v1/message.rb +31 -0
- data/lib/temporalio/api/cloud/operation/v1/message.rb +2 -1
- data/lib/temporalio/api/cloud/region/v1/message.rb +2 -1
- 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/common/v1/message.rb +7 -1
- data/lib/temporalio/api/enums/v1/event_type.rb +1 -1
- data/lib/temporalio/api/enums/v1/failed_cause.rb +1 -1
- data/lib/temporalio/api/enums/v1/reset.rb +1 -1
- data/lib/temporalio/api/history/v1/message.rb +1 -1
- data/lib/temporalio/api/nexus/v1/message.rb +2 -2
- data/lib/temporalio/api/operatorservice/v1/service.rb +1 -1
- data/lib/temporalio/api/payload_visitor.rb +1513 -0
- data/lib/temporalio/api/schedule/v1/message.rb +2 -1
- 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/workflow/v1/message.rb +1 -1
- data/lib/temporalio/api/workflowservice/v1/request_response.rb +17 -2
- data/lib/temporalio/api/workflowservice/v1/service.rb +1 -1
- data/lib/temporalio/api.rb +1 -0
- data/lib/temporalio/cancellation.rb +34 -14
- data/lib/temporalio/client/async_activity_handle.rb +12 -37
- data/lib/temporalio/client/connection/cloud_service.rb +309 -231
- data/lib/temporalio/client/connection/operator_service.rb +36 -84
- data/lib/temporalio/client/connection/service.rb +6 -5
- data/lib/temporalio/client/connection/test_service.rb +111 -0
- data/lib/temporalio/client/connection/workflow_service.rb +264 -441
- data/lib/temporalio/client/connection.rb +90 -44
- data/lib/temporalio/client/interceptor.rb +160 -60
- data/lib/temporalio/client/schedule.rb +967 -0
- data/lib/temporalio/client/schedule_handle.rb +126 -0
- data/lib/temporalio/client/workflow_execution.rb +7 -10
- data/lib/temporalio/client/workflow_handle.rb +38 -95
- data/lib/temporalio/client/workflow_update_handle.rb +3 -5
- data/lib/temporalio/client.rb +122 -42
- data/lib/temporalio/common_enums.rb +17 -0
- data/lib/temporalio/converters/data_converter.rb +4 -7
- data/lib/temporalio/converters/failure_converter.rb +5 -3
- data/lib/temporalio/converters/payload_converter/composite.rb +4 -0
- data/lib/temporalio/converters/payload_converter.rb +6 -8
- data/lib/temporalio/converters/raw_value.rb +20 -0
- data/lib/temporalio/error/failure.rb +1 -1
- data/lib/temporalio/error.rb +10 -2
- data/lib/temporalio/internal/bridge/api/core_interface.rb +5 -1
- data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +33 -0
- data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +5 -1
- data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +4 -1
- data/lib/temporalio/internal/bridge/client.rb +11 -6
- data/lib/temporalio/internal/bridge/testing.rb +20 -0
- data/lib/temporalio/internal/bridge/worker.rb +2 -0
- data/lib/temporalio/internal/bridge.rb +1 -1
- data/lib/temporalio/internal/client/implementation.rb +245 -70
- data/lib/temporalio/internal/metric.rb +122 -0
- data/lib/temporalio/internal/proto_utils.rb +86 -7
- data/lib/temporalio/internal/worker/activity_worker.rb +52 -24
- data/lib/temporalio/internal/worker/multi_runner.rb +51 -7
- data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
- data/lib/temporalio/internal/worker/workflow_instance/context.rb +329 -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 +196 -0
- data/lib/temporalio/metric.rb +109 -0
- data/lib/temporalio/retry_policy.rb +37 -14
- data/lib/temporalio/runtime.rb +118 -75
- data/lib/temporalio/search_attributes.rb +80 -37
- data/lib/temporalio/testing/activity_environment.rb +2 -2
- data/lib/temporalio/testing/workflow_environment.rb +251 -5
- data/lib/temporalio/version.rb +1 -1
- data/lib/temporalio/worker/activity_executor/thread_pool.rb +9 -217
- data/lib/temporalio/worker/activity_executor.rb +3 -3
- data/lib/temporalio/worker/interceptor.rb +340 -66
- data/lib/temporalio/worker/thread_pool.rb +237 -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.rb +201 -30
- 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 +523 -0
- data/lib/temporalio.rb +4 -0
- data/temporalio.gemspec +2 -2
- metadata +50 -8
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temporalio/workflow'
|
4
|
+
|
5
|
+
module Temporalio
|
6
|
+
module Workflow
|
7
|
+
# Asynchronous future for use in workflows to do concurrent and background work. This can only be used inside
|
8
|
+
# workflows.
|
9
|
+
class Future
|
10
|
+
# Return a future that completes when any of the given futures complete. The returned future will return the first
|
11
|
+
# completed futures value or raise the first completed futures exception. To not raise the exception, see
|
12
|
+
# {try_any_of}.
|
13
|
+
#
|
14
|
+
# @param futures [Array<Future<Object>>] Futures to wait for the first to complete.
|
15
|
+
# @return [Future<Object>] Future that relays the first completed future's result/failure.
|
16
|
+
def self.any_of(*futures)
|
17
|
+
Future.new do
|
18
|
+
Workflow.wait_condition(cancellation: nil) { futures.any?(&:done?) }
|
19
|
+
# We know a future is always returned from find, the & just helps type checker
|
20
|
+
(futures.find(&:done?) || raise).wait
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return a future that completes when all of the given futures complete or any future fails. The returned future
|
25
|
+
# will return nil on success or raise an exception if any of the futures failed. This means if any future fails,
|
26
|
+
# this will not wait for the other futures to complete. To wait for all futures to complete no matter what, see
|
27
|
+
# {try_all_of}.
|
28
|
+
#
|
29
|
+
# @param futures [Array<Future<Object>>] Futures to wait for all to complete (or first to fail).
|
30
|
+
# @return [Future<nil>] Future that completes successfully with nil when all futures complete, or raises on first
|
31
|
+
# future failure.
|
32
|
+
def self.all_of(*futures)
|
33
|
+
Future.new do
|
34
|
+
Workflow.wait_condition(cancellation: nil) { futures.all?(&:done?) || futures.any?(&:failure?) }
|
35
|
+
# Raise on error if any
|
36
|
+
futures.find(&:failure?)&.wait
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return a future that completes when the first future completes. The result of the future is the future from the
|
42
|
+
# list that completed first. The future returned will never raise even if the first completed future fails.
|
43
|
+
#
|
44
|
+
# @param futures [Array<Future<Object>>] Futures to wait for the first to complete.
|
45
|
+
# @return [Future<Future<Object>>] Future with the first completing future regardless of success/fail.
|
46
|
+
def self.try_any_of(*futures)
|
47
|
+
Future.new do
|
48
|
+
Workflow.wait_condition(cancellation: nil) { futures.any?(&:done?) }
|
49
|
+
futures.find(&:done?) || raise
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return a future that completes when all of the given futures complete regardless of success/fail. The returned
|
54
|
+
# future will return nil when all futures are complete.
|
55
|
+
#
|
56
|
+
# @param futures [Array<Future<Object>>] Futures to wait for all to complete (regardless of success/fail).
|
57
|
+
# @return [Future<nil>] Future that completes successfully with nil when all futures complete.
|
58
|
+
def self.try_all_of(*futures)
|
59
|
+
Future.new do
|
60
|
+
Workflow.wait_condition(cancellation: nil) { futures.all?(&:done?) }
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Object, nil] Result if the future is done or nil if it is not. This will return nil if the result is
|
66
|
+
# nil too. Users can use {done?} to differentiate the situations.
|
67
|
+
attr_reader :result
|
68
|
+
|
69
|
+
# @return [Exception, nil] Failure if this future failed or nil if it didn't or hasn't yet completed.
|
70
|
+
attr_reader :failure
|
71
|
+
|
72
|
+
# Create a new future. If created with a block, the block is started in the background and its success/raise is
|
73
|
+
# the result of the future. If created without a block, the result or failure can be set on it.
|
74
|
+
def initialize(&block)
|
75
|
+
@done = false
|
76
|
+
@result = nil
|
77
|
+
@failure = nil
|
78
|
+
@block_given = block_given?
|
79
|
+
return unless block_given?
|
80
|
+
|
81
|
+
@fiber = Fiber.schedule do
|
82
|
+
@result = block.call # steep:ignore
|
83
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
84
|
+
@failure = e
|
85
|
+
ensure
|
86
|
+
@done = true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return [Boolean] True if the future is done, false otherwise.
|
91
|
+
def done?
|
92
|
+
@done
|
93
|
+
end
|
94
|
+
|
95
|
+
# @return [Boolean] True if done and not a failure, false if still running or failed.
|
96
|
+
def result?
|
97
|
+
done? && !failure
|
98
|
+
end
|
99
|
+
|
100
|
+
# Mark the future as done and set the result. Does nothing if the future is already done. This cannot be invoked
|
101
|
+
# if the future was constructed with a block.
|
102
|
+
#
|
103
|
+
# @param result [Object] The result, which can be nil.
|
104
|
+
def result=(result)
|
105
|
+
Kernel.raise 'Cannot set result if block given in constructor' if @block_given
|
106
|
+
return if done?
|
107
|
+
|
108
|
+
@result = result
|
109
|
+
@done = true
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [Boolean] True if done and failed, false if still running or succeeded.
|
113
|
+
def failure?
|
114
|
+
done? && !failure.nil?
|
115
|
+
end
|
116
|
+
|
117
|
+
# Mark the future as done and set the failure. Does nothing if the future is already done. This cannot be invoked
|
118
|
+
# if the future was constructed with a block.
|
119
|
+
#
|
120
|
+
# @param failure [Exception] The failure.
|
121
|
+
def failure=(failure)
|
122
|
+
Kernel.raise 'Cannot set result if block given in constructor' if @block_given
|
123
|
+
Kernel.raise 'Cannot set nil failure' if failure.nil?
|
124
|
+
return if done?
|
125
|
+
|
126
|
+
@failure = failure
|
127
|
+
@done = true
|
128
|
+
end
|
129
|
+
|
130
|
+
# Wait on the future to complete. This will return the success or raise the failure. To not raise, use
|
131
|
+
# {wait_no_raise}.
|
132
|
+
#
|
133
|
+
# @return [Object] Result on success.
|
134
|
+
# @raise [Exception] Failure if occurred.
|
135
|
+
def wait
|
136
|
+
Workflow.wait_condition(cancellation: nil) { done? }
|
137
|
+
Kernel.raise failure if failure? # steep:ignore
|
138
|
+
|
139
|
+
result #: untyped
|
140
|
+
end
|
141
|
+
|
142
|
+
# Wait on the future to complete. This will return the success or nil if it failed, this will not raise.
|
143
|
+
#
|
144
|
+
# @return [Object, nil] Result on success or nil on failure.
|
145
|
+
def wait_no_raise
|
146
|
+
Workflow.wait_condition(cancellation: nil) { done? }
|
147
|
+
result
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Workflow
|
5
|
+
# Actions taken if a workflow completes with running handlers.
|
6
|
+
module HandlerUnfinishedPolicy
|
7
|
+
# Issue a warning in addition to abandoning.
|
8
|
+
WARN_AND_ABANDON = 1
|
9
|
+
# Abandon the handler with no warning.
|
10
|
+
ABANDON = 2
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Workflow
|
5
|
+
Info = Struct.new(
|
6
|
+
:attempt,
|
7
|
+
:continued_run_id,
|
8
|
+
:cron_schedule,
|
9
|
+
:execution_timeout,
|
10
|
+
:last_failure,
|
11
|
+
:last_result,
|
12
|
+
:namespace,
|
13
|
+
:parent,
|
14
|
+
:retry_policy,
|
15
|
+
:run_id,
|
16
|
+
:run_timeout,
|
17
|
+
:start_time,
|
18
|
+
:task_queue,
|
19
|
+
:task_timeout,
|
20
|
+
:workflow_id,
|
21
|
+
:workflow_type,
|
22
|
+
keyword_init: true
|
23
|
+
)
|
24
|
+
|
25
|
+
# Information about the running workflow. This is immutable for the life of the workflow run.
|
26
|
+
#
|
27
|
+
# @!attribute attempt
|
28
|
+
# @return [Integer] Current workflow attempt.
|
29
|
+
# @!attribute continued_run_id
|
30
|
+
# @return [String, nil] Run ID if this was continued.
|
31
|
+
# @!attribute cron_schedule
|
32
|
+
# @return [String, nil] Cron schedule if applicable.
|
33
|
+
# @!attribute execution_timeout
|
34
|
+
# @return [Float, nil] Execution timeout for the workflow.
|
35
|
+
# @!attribute last_failure
|
36
|
+
# @return [Exception, nil] Failure if this workflow run is a continuation of a failure.
|
37
|
+
# @!attribute last_result
|
38
|
+
# @return [Object, nil] Successful result if this workflow is a continuation of a success.
|
39
|
+
# @!attribute namespace
|
40
|
+
# @return [String] Namespace for the workflow.
|
41
|
+
# @!attribute parent
|
42
|
+
# @return [ParentInfo, nil] Parent information for the workflow if this is a child.
|
43
|
+
# @!attribute retry_policy
|
44
|
+
# @return [RetryPolicy, nil] Retry policy for the workflow.
|
45
|
+
# @!attribute run_id
|
46
|
+
# @return [String] Run ID for the workflow.
|
47
|
+
# @!attribute run_timeout
|
48
|
+
# @return [Float, nil] Run timeout for the workflow.
|
49
|
+
# @!attribute start_time
|
50
|
+
# @return [Time] Time when the workflow started.
|
51
|
+
# @!attribute task_queue
|
52
|
+
# @return [String] Task queue for the workflow.
|
53
|
+
# @!attribute task_timeout
|
54
|
+
# @return [Float] Task timeout for the workflow.
|
55
|
+
# @!attribute workflow_id
|
56
|
+
# @return [String] ID for the workflow.
|
57
|
+
# @!attribute workflow_type
|
58
|
+
# @return [String] Workflow type name.
|
59
|
+
#
|
60
|
+
# @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate this
|
61
|
+
# class or it may break in incompatible ways.
|
62
|
+
class Info
|
63
|
+
# Information about a parent of a workflow.
|
64
|
+
#
|
65
|
+
# @!attribute namespace
|
66
|
+
# @return [String] Namespace for the parent.
|
67
|
+
# @!attribute run_id
|
68
|
+
# @return [String] Run ID for the parent.
|
69
|
+
# @!attribute workflow_id
|
70
|
+
# @return [String] Workflow ID for the parent.
|
71
|
+
#
|
72
|
+
# @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate
|
73
|
+
# this class or it may break in incompatible ways.
|
74
|
+
ParentInfo = Struct.new(
|
75
|
+
:namespace,
|
76
|
+
:run_id,
|
77
|
+
:workflow_id,
|
78
|
+
keyword_init: true
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'temporalio/internal/bridge/api'
|
4
|
+
|
5
|
+
module Temporalio
|
6
|
+
module Workflow
|
7
|
+
# How a child workflow should be handled when the parent closes.
|
8
|
+
module ParentClosePolicy
|
9
|
+
# Unset.
|
10
|
+
UNSPECIFIED = Internal::Bridge::Api::ChildWorkflow::ParentClosePolicy::PARENT_CLOSE_POLICY_UNSPECIFIED
|
11
|
+
# The child workflow will also terminate.
|
12
|
+
TERMINATE = Internal::Bridge::Api::ChildWorkflow::ParentClosePolicy::PARENT_CLOSE_POLICY_TERMINATE
|
13
|
+
# The child workflow will do nothing.
|
14
|
+
ABANDON = Internal::Bridge::Api::ChildWorkflow::ParentClosePolicy::PARENT_CLOSE_POLICY_ABANDON
|
15
|
+
# Cancellation will be requested of the child workflow.
|
16
|
+
REQUEST_CANCEL = Internal::Bridge::Api::ChildWorkflow::ParentClosePolicy::PARENT_CLOSE_POLICY_REQUEST_CANCEL
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Workflow
|
5
|
+
# Information about a workflow update
|
6
|
+
#
|
7
|
+
# @!attribute id
|
8
|
+
# @return [String] Update ID.
|
9
|
+
# @!attribute name
|
10
|
+
# @return [String] Update name.
|
11
|
+
#
|
12
|
+
# @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate this
|
13
|
+
# class or it may break in incompatible ways.
|
14
|
+
UpdateInfo = Struct.new(
|
15
|
+
:id,
|
16
|
+
:name,
|
17
|
+
keyword_init: true
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|