temporalio 0.4.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.
Files changed (183) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +2 -0
  3. data/Gemfile +27 -0
  4. data/Rakefile +101 -0
  5. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  6. data/lib/temporalio/activity/context.rb +123 -0
  7. data/lib/temporalio/activity/definition.rb +192 -0
  8. data/lib/temporalio/activity/info.rb +67 -0
  9. data/lib/temporalio/activity.rb +12 -0
  10. data/lib/temporalio/api/activity/v1/message.rb +25 -0
  11. data/lib/temporalio/api/batch/v1/message.rb +36 -0
  12. data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
  13. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +126 -0
  14. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
  15. data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
  16. data/lib/temporalio/api/cloud/identity/v1/message.rb +41 -0
  17. data/lib/temporalio/api/cloud/namespace/v1/message.rb +42 -0
  18. data/lib/temporalio/api/cloud/nexus/v1/message.rb +31 -0
  19. data/lib/temporalio/api/cloud/operation/v1/message.rb +28 -0
  20. data/lib/temporalio/api/cloud/region/v1/message.rb +24 -0
  21. data/lib/temporalio/api/cloud/resource/v1/message.rb +23 -0
  22. data/lib/temporalio/api/cloud/sink/v1/message.rb +24 -0
  23. data/lib/temporalio/api/cloud/usage/v1/message.rb +31 -0
  24. data/lib/temporalio/api/command/v1/message.rb +46 -0
  25. data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
  26. data/lib/temporalio/api/common/v1/message.rb +48 -0
  27. data/lib/temporalio/api/deployment/v1/message.rb +38 -0
  28. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  29. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  30. data/lib/temporalio/api/enums/v1/common.rb +26 -0
  31. data/lib/temporalio/api/enums/v1/deployment.rb +23 -0
  32. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  33. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  34. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  35. data/lib/temporalio/api/enums/v1/nexus.rb +21 -0
  36. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  37. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  38. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  39. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  40. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  41. data/lib/temporalio/api/enums/v1/workflow.rb +31 -0
  42. data/lib/temporalio/api/errordetails/v1/message.rb +44 -0
  43. data/lib/temporalio/api/export/v1/message.rb +24 -0
  44. data/lib/temporalio/api/failure/v1/message.rb +37 -0
  45. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  46. data/lib/temporalio/api/history/v1/message.rb +92 -0
  47. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  48. data/lib/temporalio/api/nexus/v1/message.rb +41 -0
  49. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  50. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  51. data/lib/temporalio/api/operatorservice.rb +3 -0
  52. data/lib/temporalio/api/payload_visitor.rb +1581 -0
  53. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  54. data/lib/temporalio/api/query/v1/message.rb +28 -0
  55. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  56. data/lib/temporalio/api/schedule/v1/message.rb +43 -0
  57. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  58. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  59. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  60. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  61. data/lib/temporalio/api/taskqueue/v1/message.rb +48 -0
  62. data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
  63. data/lib/temporalio/api/testservice/v1/service.rb +23 -0
  64. data/lib/temporalio/api/update/v1/message.rb +33 -0
  65. data/lib/temporalio/api/version/v1/message.rb +26 -0
  66. data/lib/temporalio/api/workflow/v1/message.rb +51 -0
  67. data/lib/temporalio/api/workflowservice/v1/request_response.rb +233 -0
  68. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  69. data/lib/temporalio/api/workflowservice.rb +3 -0
  70. data/lib/temporalio/api.rb +15 -0
  71. data/lib/temporalio/cancellation.rb +170 -0
  72. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  73. data/lib/temporalio/client/async_activity_handle.rb +85 -0
  74. data/lib/temporalio/client/connection/cloud_service.rb +726 -0
  75. data/lib/temporalio/client/connection/operator_service.rb +201 -0
  76. data/lib/temporalio/client/connection/service.rb +42 -0
  77. data/lib/temporalio/client/connection/test_service.rb +111 -0
  78. data/lib/temporalio/client/connection/workflow_service.rb +1251 -0
  79. data/lib/temporalio/client/connection.rb +316 -0
  80. data/lib/temporalio/client/interceptor.rb +455 -0
  81. data/lib/temporalio/client/schedule.rb +991 -0
  82. data/lib/temporalio/client/schedule_handle.rb +126 -0
  83. data/lib/temporalio/client/with_start_workflow_operation.rb +115 -0
  84. data/lib/temporalio/client/workflow_execution.rb +119 -0
  85. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  86. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  87. data/lib/temporalio/client/workflow_handle.rb +389 -0
  88. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  89. data/lib/temporalio/client/workflow_update_handle.rb +65 -0
  90. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  91. data/lib/temporalio/client.rb +607 -0
  92. data/lib/temporalio/common_enums.rb +41 -0
  93. data/lib/temporalio/contrib/open_telemetry.rb +470 -0
  94. data/lib/temporalio/converters/data_converter.rb +99 -0
  95. data/lib/temporalio/converters/failure_converter.rb +202 -0
  96. data/lib/temporalio/converters/payload_codec.rb +26 -0
  97. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  98. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  99. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  100. data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
  101. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  102. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  103. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  104. data/lib/temporalio/converters/payload_converter.rb +71 -0
  105. data/lib/temporalio/converters/raw_value.rb +20 -0
  106. data/lib/temporalio/converters.rb +9 -0
  107. data/lib/temporalio/error/failure.rb +219 -0
  108. data/lib/temporalio/error.rb +156 -0
  109. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.so +0 -0
  110. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.so +0 -0
  111. data/lib/temporalio/internal/bridge/3.4/temporalio_bridge.so +0 -0
  112. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  113. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
  114. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  115. data/lib/temporalio/internal/bridge/api/common/common.rb +27 -0
  116. data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
  117. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  118. data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +33 -0
  119. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
  120. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +57 -0
  121. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +31 -0
  122. data/lib/temporalio/internal/bridge/api.rb +3 -0
  123. data/lib/temporalio/internal/bridge/client.rb +95 -0
  124. data/lib/temporalio/internal/bridge/runtime.rb +56 -0
  125. data/lib/temporalio/internal/bridge/testing.rb +69 -0
  126. data/lib/temporalio/internal/bridge/worker.rb +85 -0
  127. data/lib/temporalio/internal/bridge.rb +36 -0
  128. data/lib/temporalio/internal/client/implementation.rb +922 -0
  129. data/lib/temporalio/internal/metric.rb +122 -0
  130. data/lib/temporalio/internal/proto_utils.rb +165 -0
  131. data/lib/temporalio/internal/worker/activity_worker.rb +385 -0
  132. data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
  133. data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
  134. data/lib/temporalio/internal/worker/workflow_instance/context.rb +383 -0
  135. data/lib/temporalio/internal/worker/workflow_instance/details.rb +46 -0
  136. data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
  137. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
  138. data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
  139. data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
  140. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
  141. data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
  142. data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +400 -0
  143. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
  144. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
  145. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +183 -0
  146. data/lib/temporalio/internal/worker/workflow_instance.rb +774 -0
  147. data/lib/temporalio/internal/worker/workflow_worker.rb +239 -0
  148. data/lib/temporalio/internal.rb +7 -0
  149. data/lib/temporalio/metric.rb +109 -0
  150. data/lib/temporalio/retry_policy.rb +74 -0
  151. data/lib/temporalio/runtime/metric_buffer.rb +94 -0
  152. data/lib/temporalio/runtime.rb +352 -0
  153. data/lib/temporalio/scoped_logger.rb +96 -0
  154. data/lib/temporalio/search_attributes.rb +356 -0
  155. data/lib/temporalio/testing/activity_environment.rb +160 -0
  156. data/lib/temporalio/testing/workflow_environment.rb +406 -0
  157. data/lib/temporalio/testing.rb +10 -0
  158. data/lib/temporalio/version.rb +5 -0
  159. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  160. data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
  161. data/lib/temporalio/worker/activity_executor.rb +55 -0
  162. data/lib/temporalio/worker/interceptor.rb +365 -0
  163. data/lib/temporalio/worker/thread_pool.rb +237 -0
  164. data/lib/temporalio/worker/tuner.rb +189 -0
  165. data/lib/temporalio/worker/workflow_executor/thread_pool.rb +235 -0
  166. data/lib/temporalio/worker/workflow_executor.rb +26 -0
  167. data/lib/temporalio/worker/workflow_replayer.rb +350 -0
  168. data/lib/temporalio/worker.rb +603 -0
  169. data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
  170. data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
  171. data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
  172. data/lib/temporalio/workflow/definition.rb +598 -0
  173. data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
  174. data/lib/temporalio/workflow/future.rb +151 -0
  175. data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
  176. data/lib/temporalio/workflow/info.rb +104 -0
  177. data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
  178. data/lib/temporalio/workflow/update_info.rb +20 -0
  179. data/lib/temporalio/workflow.rb +575 -0
  180. data/lib/temporalio/workflow_history.rb +47 -0
  181. data/lib/temporalio.rb +11 -0
  182. data/temporalio.gemspec +29 -0
  183. metadata +258 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 753472a9409fb7ba257a3a46608d59ade1bb4f992c2bcb59a9dbb0fd1a2b0c8f
4
+ data.tar.gz: 20ec63570954961c622d3b8b721284779780199dbcced948d00ba9e38749b6c6
5
+ SHA512:
6
+ metadata.gz: 318d57305e3bf385c9e98d9885c400783bbecff8d0ce96863855b4131e781bbef0a9baec0433061095f4102b5616ff62ff1b643ee52b1edf3c7ede2afd0b8efb
7
+ data.tar.gz: 683d023873fa9a16b994f4a234e45123f5ecdcd39a3b3a94870f1d664e59f496318079573e1accc2fb74aac0b56a8ff347a69ecc4b639c27cdd5b464c5258ade
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --readme README.md
2
+ --protected
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'activemodel'
9
+ gem 'activerecord'
10
+ gem 'async'
11
+ gem 'base64'
12
+ gem 'grpc', '~> 1.69'
13
+ gem 'grpc-tools', '~> 1.69'
14
+ gem 'minitest'
15
+ # We are intentionally not pinning OTel versions here so that CI tests the latest. This also means that the OTel
16
+ # contrib library also does not require specific versions, we are relying on the compatibility rigor of OTel.
17
+ gem 'opentelemetry-api'
18
+ gem 'opentelemetry-sdk'
19
+ gem 'rake'
20
+ gem 'rake-compiler'
21
+ gem 'rbs', '~> 3.5.3'
22
+ gem 'rb_sys', '~> 0.9.63'
23
+ gem 'rubocop'
24
+ gem 'sqlite3'
25
+ gem 'steep', '~> 1.7.1'
26
+ gem 'yard'
27
+ end
data/Rakefile ADDED
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Lint/MissingCopEnableDirective, Style/DocumentationMethod
4
+
5
+ require 'bundler/gem_tasks'
6
+ require 'rb_sys/cargo/metadata'
7
+ require 'rb_sys/extensiontask'
8
+
9
+ task build: :compile
10
+
11
+ GEMSPEC = Gem::Specification.load('temporalio.gemspec')
12
+
13
+ begin
14
+ RbSys::ExtensionTask.new('temporalio_bridge', GEMSPEC) do |ext|
15
+ ext.lib_dir = 'lib/temporalio/internal/bridge'
16
+ end
17
+ rescue RbSys::CargoMetadataError
18
+ raise 'Source gem cannot be installed directly, must be a supported platform'
19
+ end
20
+
21
+ require 'rake/testtask'
22
+
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.warning = false
25
+ t.libs << 'test'
26
+ t.libs << 'lib'
27
+ t.test_files = FileList['test/**/*_test.rb']
28
+ end
29
+
30
+ def add_protoc_to_path
31
+ tools_spec = Gem::Specification.find_by_name('grpc-tools')
32
+ cpu = RbConfig::CONFIG['host_cpu']
33
+ cpu = 'x86_64' if cpu == 'x64'
34
+ os = RbConfig::CONFIG['host_os']
35
+ os = 'windows' if os.start_with?('mingw')
36
+ protoc_path = "#{tools_spec.gem_dir}/bin/#{cpu}-#{os}"
37
+ separator = os == 'windows' ? ';' : ':'
38
+ ENV['PATH'] = "#{ENV.fetch('PATH', nil)}#{separator}#{protoc_path}"
39
+ end
40
+
41
+ add_protoc_to_path
42
+
43
+ require 'rubocop/rake_task'
44
+
45
+ RuboCop::RakeTask.new
46
+
47
+ require 'steep/rake_task'
48
+
49
+ Steep::RakeTask.new
50
+
51
+ require 'yard'
52
+
53
+ module CustomizeYardWarnings # rubocop:disable Style/Documentation
54
+ def process
55
+ super
56
+ rescue YARD::Parser::UndocumentableError
57
+ # We ignore if it's an API warning
58
+ last_file = statement.last.file
59
+ raise unless (last_file.start_with?('lib/temporalio/api/') && last_file.count('/') > 3) ||
60
+ last_file.start_with?('lib/temporalio/internal/bridge/api/')
61
+ end
62
+ end
63
+
64
+ YARD::Handlers::Ruby::ConstantHandler.prepend(CustomizeYardWarnings)
65
+
66
+ YARD::Rake::YardocTask.new { |t| t.options = ['--fail-on-warning'] }
67
+
68
+ Rake::Task[:yard].enhance([:copy_parent_files]) do
69
+ rm ['LICENSE', 'README.md']
70
+ end
71
+
72
+ namespace :proto do
73
+ desc 'Generate API and Core protobufs'
74
+ task :generate do
75
+ require_relative 'extra/proto_gen'
76
+ ProtoGen.new.run
77
+ end
78
+ end
79
+
80
+ namespace :rbs do
81
+ desc 'RBS tasks'
82
+ task :install_collection do
83
+ sh 'rbs collection install'
84
+ end
85
+ end
86
+
87
+ # We have to copy some parent files to this dir for gem
88
+ task :copy_parent_files do
89
+ cp '../LICENSE', 'LICENSE'
90
+ cp '../README.md', 'README.md'
91
+ end
92
+ Rake::Task[:build].enhance([:copy_parent_files]) do
93
+ rm ['LICENSE', 'README.md']
94
+ end
95
+
96
+ task :rust_lint do
97
+ sh 'cargo', 'clippy', '-p', 'temporalio_bridge', '--no-deps', '--', '-Dwarnings'
98
+ sh 'cargo', 'fmt', '--check'
99
+ end
100
+
101
+ task default: ['rubocop', 'yard', 'rbs:install_collection', 'steep', 'rust_lint', 'compile', 'test']
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/error'
4
+
5
+ module Temporalio
6
+ module Activity
7
+ # Error raised inside an activity to mark that the activity will be completed asynchronously.
8
+ class CompleteAsyncError < Error
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/error'
4
+
5
+ module Temporalio
6
+ module Activity
7
+ # Context accessible only within an activity. Use {current} to get the current context. Contexts are fiber or thread
8
+ # local so may not be available in a newly started thread from an activity and may have to be propagated manually.
9
+ class Context
10
+ # @return [Context] The current context, or raises an error if not in activity fiber/thread.
11
+ def self.current
12
+ context = current_or_nil
13
+ raise Error, 'Not in activity context' if context.nil?
14
+
15
+ context
16
+ end
17
+
18
+ # @return [Context, nil] The current context or nil if not in activity fiber/thread.
19
+ def self.current_or_nil
20
+ _current_executor&.activity_context
21
+ end
22
+
23
+ # @return [Boolean] Whether there is a current context available.
24
+ def self.exist?
25
+ !current_or_nil.nil?
26
+ end
27
+
28
+ # @!visibility private
29
+ def self._current_executor
30
+ if Fiber.current_scheduler
31
+ Fiber[:temporal_activity_executor]
32
+ else
33
+ Thread.current[:temporal_activity_executor]
34
+ end
35
+ end
36
+
37
+ # @!visibility private
38
+ def self._current_executor=(executor)
39
+ if Fiber.current_scheduler
40
+ Fiber[:temporal_activity_executor] = executor
41
+ else
42
+ Thread.current[:temporal_activity_executor] = executor
43
+ end
44
+ end
45
+
46
+ # @return [Info] Activity info for this activity.
47
+ def info
48
+ raise NotImplementedError
49
+ end
50
+
51
+ # @return [Object, nil] Activity class instance. This should always be present except for advanced cases where the
52
+ # definition was manually created without any instance getter/creator.
53
+ def instance
54
+ raise NotImplementedError
55
+ end
56
+
57
+ # Record a heartbeat on the activity.
58
+ #
59
+ # Heartbeats should be used for all non-immediately-returning, non-local activities and they are required to
60
+ # receive cancellation. Heartbeat calls are throttled internally based on the heartbeat timeout of the activity.
61
+ # Users do not have to be concerned with burdening the server by calling this too frequently.
62
+ #
63
+ # @param details [Array<Object>] Details to record with the heartbeat.
64
+ def heartbeat(*details)
65
+ raise NotImplementedError
66
+ end
67
+
68
+ # @return [Cancellation] Cancellation that is canceled when the activity is canceled.
69
+ def cancellation
70
+ raise NotImplementedError
71
+ end
72
+
73
+ # @return [Cancellation] Cancellation that is canceled when the worker is shutting down. On worker shutdown, this
74
+ # is canceled, then the `graceful_shutdown_period` is waited (default 0s), then the activity is canceled.
75
+ def worker_shutdown_cancellation
76
+ raise NotImplementedError
77
+ end
78
+
79
+ # @return [Converters::PayloadConverter] Payload converter associated with this activity.
80
+ def payload_converter
81
+ raise NotImplementedError
82
+ end
83
+
84
+ # @return [ScopedLogger] Logger for this activity. Note, this is a shared logger not created each activity
85
+ # invocation. It just has logic to extract current activity details and so is only able to do so on log calls
86
+ # made with a current context available.
87
+ def logger
88
+ raise NotImplementedError
89
+ end
90
+
91
+ # @!visibility private
92
+ def _scoped_logger_info
93
+ return @scoped_logger_info unless @scoped_logger_info.nil?
94
+
95
+ curr_info = info
96
+ @scoped_logger_info = {
97
+ temporal_activity: {
98
+ activity_id: curr_info.activity_id,
99
+ activity_type: curr_info.activity_type,
100
+ attempt: curr_info.attempt,
101
+ task_queue: curr_info.task_queue,
102
+ workflow_id: curr_info.workflow_id,
103
+ workflow_namespace: curr_info.workflow_namespace,
104
+ workflow_run_id: curr_info.workflow_run_id,
105
+ workflow_type: curr_info.workflow_type
106
+ }
107
+ }.freeze
108
+ end
109
+
110
+ # @return [Metric::Meter] Metric meter to create metrics on, with some activity-specific attributes already set.
111
+ # @raise [RuntimeError] Called within a {Testing::ActivityEnvironment} and it was not set.
112
+ def metric_meter
113
+ raise NotImplementedError
114
+ end
115
+
116
+ # @return [Client] Temporal client this activity worker is running in.
117
+ # @raise [RuntimeError] Called within a {Testing::ActivityEnvironment} and it was not set.
118
+ def client
119
+ raise NotImplementedError
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/internal/proto_utils'
4
+
5
+ module Temporalio
6
+ module Activity
7
+ # Base class for all activities.
8
+ #
9
+ # Activities can be given to a worker as instances of this class, which will call execute on the same instance for
10
+ # each execution, or given to the worker as the class itself which instantiates the activity for each execution.
11
+ #
12
+ # All activities must implement {execute}. Inside execute, {Activity::Context.current} can be used to access the
13
+ # current context to get information, issue heartbeats, etc.
14
+ #
15
+ # By default, the activity is named as its unqualified class name. This can be customized with {activity_name}.
16
+ #
17
+ # By default, the activity uses the `:default` executor which is usually the thread-pool based executor. This can be
18
+ # customized with {activity_executor}.
19
+ #
20
+ # By default, upon cancellation {::Thread.raise} or {::Fiber.raise} is called with a {Error::CanceledError}. This
21
+ # can be disabled by passing `false` to {activity_cancel_raise}.
22
+ #
23
+ # See documentation for more detail on activities.
24
+ class Definition
25
+ class << self
26
+ protected
27
+
28
+ # Override the activity name which is defaulted to the unqualified class name.
29
+ #
30
+ # @param name [String, Symbol] Name to use.
31
+ def activity_name(name)
32
+ if !name.is_a?(Symbol) && !name.is_a?(String)
33
+ raise ArgumentError,
34
+ 'Activity name must be a symbol or string'
35
+ end
36
+
37
+ @activity_name = name.to_s
38
+ end
39
+
40
+ # Override the activity executor which is defaulted to `:default`.
41
+ #
42
+ # @param executor_name [Symbol] Executor to use.
43
+ def activity_executor(executor_name)
44
+ raise ArgumentError, 'Executor name must be a symbol' unless executor_name.is_a?(Symbol)
45
+
46
+ @activity_executor = executor_name
47
+ end
48
+
49
+ # Override whether the activity uses Thread/Fiber raise for cancellation which is defaulted to true.
50
+ #
51
+ # @param cancel_raise [Boolean] Whether to raise.
52
+ def activity_cancel_raise(cancel_raise)
53
+ unless cancel_raise.is_a?(TrueClass) || cancel_raise.is_a?(FalseClass)
54
+ raise ArgumentError, 'Must be a boolean'
55
+ end
56
+
57
+ @activity_cancel_raise = cancel_raise
58
+ end
59
+
60
+ # Set an activity as dynamic. Dynamic activities do not have names and handle any activity that is not otherwise
61
+ # registered. A worker can only have one dynamic activity. It is often useful to use {activity_raw_args} with
62
+ # this.
63
+ #
64
+ # @param value [Boolean] Whether the activity is dynamic.
65
+ def activity_dynamic(value = true) # rubocop:disable Style/OptionalBooleanParameter
66
+ raise ArgumentError, 'Must be a boolean' unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
67
+
68
+ @activity_dynamic = value
69
+ end
70
+
71
+ # Have activity arguments delivered to `execute` as {Converters::RawValue}s. These are wrappers for the raw
72
+ # payloads that have not been converted to types (but they have been decoded by the codec if present). They can
73
+ # be converted with {Context#payload_converter}.
74
+ #
75
+ # @param value [Boolean] Whether the activity accepts raw arguments.
76
+ def activity_raw_args(value = true) # rubocop:disable Style/OptionalBooleanParameter
77
+ raise ArgumentError, 'Must be a boolean' unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
78
+
79
+ @activity_raw_args = value
80
+ end
81
+ end
82
+
83
+ # @!visibility private
84
+ def self._activity_definition_details
85
+ activity_name = @activity_name
86
+ raise 'Cannot have activity name specified for dynamic activity' if activity_name && @activity_dynamic
87
+
88
+ # Default to unqualified class name if not dynamic
89
+ activity_name ||= name.to_s.split('::').last unless @activity_dynamic
90
+ {
91
+ activity_name:,
92
+ activity_executor: @activity_executor || :default,
93
+ activity_cancel_raise: @activity_cancel_raise.nil? || @activity_cancel_raise,
94
+ activity_raw_args: @activity_raw_args.nil? ? false : @activity_raw_args
95
+ }
96
+ end
97
+
98
+ # Implementation of the activity. The arguments should be positional and this should return the value on success
99
+ # or raise an error on failure.
100
+ def execute(*args)
101
+ raise NotImplementedError, 'Activity did not implement "execute"'
102
+ end
103
+
104
+ # Definition info of an activity. Activities are usually classes/instances that extend {Definition}, but
105
+ # definitions can also be manually created with a block via {initialize} here.
106
+ class Info
107
+ # @return [String, Symbol, nil] Name of the activity, or nil if the activity is dynamic.
108
+ attr_reader :name
109
+
110
+ # @return [Object, Proc, nil] The pre-created instance or the proc to create/return it.
111
+ attr_reader :instance
112
+
113
+ # @return [Proc] Proc for the activity. Should use {Context#instance} to access the instance.
114
+ attr_reader :proc
115
+
116
+ # @return [Symbol] Name of the executor. Default is `:default`.
117
+ attr_reader :executor
118
+
119
+ # @return [Boolean] Whether to raise in thread/fiber on cancellation. Default is `true`.
120
+ attr_reader :cancel_raise
121
+
122
+ # @return [Boolean] Whether to use {Converters::RawValue}s as arguments.
123
+ attr_reader :raw_args
124
+
125
+ # Obtain definition info representing the given activity, which can be a class, instance, or definition info.
126
+ #
127
+ # @param activity [Definition, Class<Definition>, Info] Activity to get info for.
128
+ # @return Info Obtained definition info.
129
+ def self.from_activity(activity)
130
+ # Class means create each time, instance means just call, definition
131
+ # does nothing special
132
+ case activity
133
+ when Class
134
+ unless activity < Definition
135
+ raise ArgumentError,
136
+ "Class '#{activity}' does not extend Temporalio::Activity::Definition"
137
+ end
138
+
139
+ details = activity._activity_definition_details
140
+ new(
141
+ name: details[:activity_name],
142
+ instance: proc { activity.new },
143
+ executor: details[:activity_executor],
144
+ cancel_raise: details[:activity_cancel_raise],
145
+ raw_args: details[:activity_raw_args]
146
+ ) { |*args| Context.current.instance&.execute(*args) }
147
+ when Definition
148
+ details = activity.class._activity_definition_details
149
+ new(
150
+ name: details[:activity_name],
151
+ instance: activity,
152
+ executor: details[:activity_executor],
153
+ cancel_raise: details[:activity_cancel_raise],
154
+ raw_args: details[:activity_raw_args]
155
+ ) { |*args| Context.current.instance&.execute(*args) }
156
+ when Info
157
+ activity
158
+ else
159
+ raise ArgumentError, "#{activity} is not an activity class, instance, or definition info"
160
+ end
161
+ end
162
+
163
+ # Manually create activity definition info. Most users will use an instance/class of {Definition}.
164
+ #
165
+ # @param name [String, Symbol, nil] Name of the activity or nil for dynamic activity.
166
+ # @param instance [Object, Proc, nil] The pre-created instance or the proc to create/return it.
167
+ # @param executor [Symbol] Name of the executor.
168
+ # @param cancel_raise [Boolean] Whether to raise in thread/fiber on cancellation.
169
+ # @param raw_args [Boolean] Whether to use {Converters::RawValue}s as arguments.
170
+ # @yield Use this block as the activity.
171
+ def initialize(
172
+ name:,
173
+ instance: nil,
174
+ executor: :default,
175
+ cancel_raise: true,
176
+ raw_args: false,
177
+ &block
178
+ )
179
+ @name = name
180
+ @instance = instance
181
+ raise ArgumentError, 'Must give block' unless block_given?
182
+
183
+ @proc = block
184
+ @executor = executor
185
+ @cancel_raise = cancel_raise
186
+ @raw_args = raw_args
187
+ Internal::ProtoUtils.assert_non_reserved_name(name)
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Temporalio
4
+ module Activity
5
+ Info = Data.define(
6
+ :activity_id,
7
+ :activity_type,
8
+ :attempt,
9
+ :current_attempt_scheduled_time,
10
+ :heartbeat_details,
11
+ :heartbeat_timeout,
12
+ :local?,
13
+ :schedule_to_close_timeout,
14
+ :scheduled_time,
15
+ :start_to_close_timeout,
16
+ :started_time,
17
+ :task_queue,
18
+ :task_token,
19
+ :workflow_id,
20
+ :workflow_namespace,
21
+ :workflow_run_id,
22
+ :workflow_type
23
+ )
24
+
25
+ # Information about an activity.
26
+ #
27
+ # @!attribute activity_id
28
+ # @return [String] ID for the activity.
29
+ # @!attribute activity_type
30
+ # @return [String] Type name for the activity.
31
+ # @!attribute attempt
32
+ # @return [Integer] Attempt the activity is on.
33
+ # @!attribute current_attempt_scheduled_time
34
+ # @return [Time] When the current attempt was scheduled.
35
+ # @!attribute heartbeat_details
36
+ # @return [Array<Object>] Details from the last heartbeat of the last attempt.
37
+ # @!attribute heartbeat_timeout
38
+ # @return [Float, nil] Heartbeat timeout set by the caller.
39
+ # @!attribute local?
40
+ # @return [Boolean] Whether the activity is a local activity or not.
41
+ # @!attribute schedule_to_close_timeout
42
+ # @return [Float, nil] Schedule to close timeout set by the caller.
43
+ # @!attribute scheduled_time
44
+ # @return [Time] When the activity was scheduled.
45
+ # @!attribute start_to_close_timeout
46
+ # @return [Float, nil] Start to close timeout set by the caller.
47
+ # @!attribute started_time
48
+ # @return [Time] When the activity started.
49
+ # @!attribute task_queue
50
+ # @return [String] Task queue this activity is on.
51
+ # @!attribute task_token
52
+ # @return [String] Task token uniquely identifying this activity. Note, this is a `ASCII-8BIT` encoded string, not
53
+ # a `UTF-8` encoded string nor a valid UTF-8 string.
54
+ # @!attribute workflow_id
55
+ # @return [String] Workflow ID that started this activity.
56
+ # @!attribute workflow_namespace
57
+ # @return [String] Namespace this activity is on.
58
+ # @!attribute workflow_run_id
59
+ # @return [String] Workflow run ID that started this activity.
60
+ # @!attribute workflow_type
61
+ # @return [String] Workflow type name that started this activity.
62
+ #
63
+ # @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate this
64
+ # class or it may break in incompatible ways.
65
+ class Info; end # rubocop:disable Lint/EmptyClass
66
+ end
67
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/activity/complete_async_error'
4
+ require 'temporalio/activity/context'
5
+ require 'temporalio/activity/definition'
6
+ require 'temporalio/activity/info'
7
+
8
+ module Temporalio
9
+ # All activity related classes.
10
+ module Activity
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: temporal/api/activity/v1/message.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'temporalio/api/common/v1/message'
8
+ require 'temporalio/api/taskqueue/v1/message'
9
+ require 'google/protobuf/duration_pb'
10
+
11
+
12
+ descriptor_data = "\n&temporal/api/activity/v1/message.proto\x12\x18temporal.api.activity.v1\x1a$temporal/api/common/v1/message.proto\x1a\'temporal/api/taskqueue/v1/message.proto\x1a\x1egoogle/protobuf/duration.proto\"\xf3\x02\n\x0f\x41\x63tivityOptions\x12\x38\n\ntask_queue\x18\x01 \x01(\x0b\x32$.temporal.api.taskqueue.v1.TaskQueue\x12<\n\x19schedule_to_close_timeout\x18\x02 \x01(\x0b\x32\x19.google.protobuf.Duration\x12<\n\x19schedule_to_start_timeout\x18\x03 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x39\n\x16start_to_close_timeout\x18\x04 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x34\n\x11heartbeat_timeout\x18\x05 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x39\n\x0cretry_policy\x18\x06 \x01(\x0b\x32#.temporal.api.common.v1.RetryPolicyB\x93\x01\n\x1bio.temporal.api.activity.v1B\x0cMessageProtoP\x01Z\'go.temporal.io/api/activity/v1;activity\xaa\x02\x1aTemporalio.Api.Activity.V1\xea\x02\x1dTemporalio::Api::Activity::V1b\x06proto3"
13
+
14
+ pool = Google::Protobuf::DescriptorPool.generated_pool
15
+ pool.add_serialized_file(descriptor_data)
16
+
17
+ module Temporalio
18
+ module Api
19
+ module Activity
20
+ module V1
21
+ ActivityOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.activity.v1.ActivityOptions").msgclass
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: temporal/api/batch/v1/message.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'google/protobuf/duration_pb'
8
+ require 'google/protobuf/field_mask_pb'
9
+ require 'google/protobuf/timestamp_pb'
10
+ require 'temporalio/api/common/v1/message'
11
+ require 'temporalio/api/enums/v1/batch_operation'
12
+ require 'temporalio/api/enums/v1/reset'
13
+ require 'temporalio/api/workflow/v1/message'
14
+
15
+
16
+ descriptor_data = "\n#temporal/api/batch/v1/message.proto\x12\x15temporal.api.batch.v1\x1a\x1egoogle/protobuf/duration.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a$temporal/api/common/v1/message.proto\x1a+temporal/api/enums/v1/batch_operation.proto\x1a!temporal/api/enums/v1/reset.proto\x1a&temporal/api/workflow/v1/message.proto\"\xbf\x01\n\x12\x42\x61tchOperationInfo\x12\x0e\n\x06job_id\x18\x01 \x01(\t\x12\x39\n\x05state\x18\x02 \x01(\x0e\x32*.temporal.api.enums.v1.BatchOperationState\x12.\n\nstart_time\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12.\n\nclose_time\x18\x04 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"`\n\x19\x42\x61tchOperationTermination\x12\x31\n\x07\x64\x65tails\x18\x01 \x01(\x0b\x32 .temporal.api.common.v1.Payloads\x12\x10\n\x08identity\x18\x02 \x01(\t\"\x99\x01\n\x14\x42\x61tchOperationSignal\x12\x0e\n\x06signal\x18\x01 \x01(\t\x12/\n\x05input\x18\x02 \x01(\x0b\x32 .temporal.api.common.v1.Payloads\x12.\n\x06header\x18\x03 \x01(\x0b\x32\x1e.temporal.api.common.v1.Header\x12\x10\n\x08identity\x18\x04 \x01(\t\".\n\x1a\x42\x61tchOperationCancellation\x12\x10\n\x08identity\x18\x01 \x01(\t\"*\n\x16\x42\x61tchOperationDeletion\x12\x10\n\x08identity\x18\x01 \x01(\t\"\xd9\x01\n\x13\x42\x61tchOperationReset\x12\x10\n\x08identity\x18\x03 \x01(\t\x12\x35\n\x07options\x18\x04 \x01(\x0b\x32$.temporal.api.common.v1.ResetOptions\x12\x34\n\nreset_type\x18\x01 \x01(\x0e\x32 .temporal.api.enums.v1.ResetType\x12\x43\n\x12reset_reapply_type\x18\x02 \x01(\x0e\x32\'.temporal.api.enums.v1.ResetReapplyType\"\xc9\x01\n,BatchOperationUpdateWorkflowExecutionOptions\x12\x10\n\x08identity\x18\x01 \x01(\t\x12V\n\x1aworkflow_execution_options\x18\x02 \x01(\x0b\x32\x32.temporal.api.workflow.v1.WorkflowExecutionOptions\x12/\n\x0bupdate_mask\x18\x03 \x01(\x0b\x32\x1a.google.protobuf.FieldMask\"\xc0\x01\n\x1f\x42\x61tchOperationUnpauseActivities\x12\x10\n\x08identity\x18\x01 \x01(\t\x12\x0e\n\x04type\x18\x02 \x01(\tH\x00\x12\x13\n\tmatch_all\x18\x03 \x01(\x08H\x00\x12\x16\n\x0ereset_attempts\x18\x04 \x01(\x08\x12\x17\n\x0freset_heartbeat\x18\x05 \x01(\x08\x12)\n\x06jitter\x18\x06 \x01(\x0b\x32\x19.google.protobuf.DurationB\n\n\x08\x61\x63tivityB\x84\x01\n\x18io.temporal.api.batch.v1B\x0cMessageProtoP\x01Z!go.temporal.io/api/batch/v1;batch\xaa\x02\x17Temporalio.Api.Batch.V1\xea\x02\x1aTemporalio::Api::Batch::V1b\x06proto3"
17
+
18
+ pool = Google::Protobuf::DescriptorPool.generated_pool
19
+ pool.add_serialized_file(descriptor_data)
20
+
21
+ module Temporalio
22
+ module Api
23
+ module Batch
24
+ module V1
25
+ BatchOperationInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationInfo").msgclass
26
+ BatchOperationTermination = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationTermination").msgclass
27
+ BatchOperationSignal = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationSignal").msgclass
28
+ BatchOperationCancellation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationCancellation").msgclass
29
+ BatchOperationDeletion = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationDeletion").msgclass
30
+ BatchOperationReset = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationReset").msgclass
31
+ BatchOperationUpdateWorkflowExecutionOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationUpdateWorkflowExecutionOptions").msgclass
32
+ BatchOperationUnpauseActivities = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationUnpauseActivities").msgclass
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
3
+ # source: temporal/api/cloud/account/v1/message.proto
4
+
5
+ require 'google/protobuf'
6
+
7
+ require 'temporalio/api/cloud/resource/v1/message'
8
+
9
+
10
+ descriptor_data = "\n+temporal/api/cloud/account/v1/message.proto\x12\x1dtemporal.api.cloud.account.v1\x1a,temporal/api/cloud/resource/v1/message.proto\")\n\x0bMetricsSpec\x12\x1a\n\x12\x61\x63\x63\x65pted_client_ca\x18\x02 \x01(\x0c\"J\n\x0b\x41\x63\x63ountSpec\x12;\n\x07metrics\x18\x01 \x01(\x0b\x32*.temporal.api.cloud.account.v1.MetricsSpec\"\x16\n\x07Metrics\x12\x0b\n\x03uri\x18\x01 \x01(\t\"\xfc\x01\n\x07\x41\x63\x63ount\x12\n\n\x02id\x18\x01 \x01(\t\x12\x38\n\x04spec\x18\x02 \x01(\x0b\x32*.temporal.api.cloud.account.v1.AccountSpec\x12\x18\n\x10resource_version\x18\x03 \x01(\t\x12<\n\x05state\x18\x04 \x01(\x0e\x32-.temporal.api.cloud.resource.v1.ResourceState\x12\x1a\n\x12\x61sync_operation_id\x18\x05 \x01(\t\x12\x37\n\x07metrics\x18\x06 \x01(\x0b\x32&.temporal.api.cloud.account.v1.MetricsB\xa7\x01\n io.temporal.api.cloud.account.v1B\x0cMessageProtoP\x01Z+go.temporal.io/api/cloud/account/v1;account\xaa\x02\x1fTemporalio.Api.Cloud.Account.V1\xea\x02#Temporalio::Api::Cloud::Account::V1b\x06proto3"
11
+
12
+ pool = Google::Protobuf::DescriptorPool.generated_pool
13
+ pool.add_serialized_file(descriptor_data)
14
+
15
+ module Temporalio
16
+ module Api
17
+ module Cloud
18
+ module Account
19
+ module V1
20
+ MetricsSpec = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.cloud.account.v1.MetricsSpec").msgclass
21
+ AccountSpec = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.cloud.account.v1.AccountSpec").msgclass
22
+ Metrics = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.cloud.account.v1.Metrics").msgclass
23
+ Account = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.cloud.account.v1.Account").msgclass
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end