amit-temporalio 0.3.1-x86_64-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 (177) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +2 -0
  3. data/Gemfile +23 -0
  4. data/Rakefile +101 -0
  5. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  6. data/lib/temporalio/activity/context.rb +116 -0
  7. data/lib/temporalio/activity/definition.rb +189 -0
  8. data/lib/temporalio/activity/info.rb +64 -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 +31 -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 +47 -0
  27. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  28. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  29. data/lib/temporalio/api/enums/v1/common.rb +26 -0
  30. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  31. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  32. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  33. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  34. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  35. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  36. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  37. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  38. data/lib/temporalio/api/enums/v1/workflow.rb +30 -0
  39. data/lib/temporalio/api/errordetails/v1/message.rb +42 -0
  40. data/lib/temporalio/api/export/v1/message.rb +24 -0
  41. data/lib/temporalio/api/failure/v1/message.rb +35 -0
  42. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  43. data/lib/temporalio/api/history/v1/message.rb +90 -0
  44. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  45. data/lib/temporalio/api/nexus/v1/message.rb +40 -0
  46. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  47. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  48. data/lib/temporalio/api/operatorservice.rb +3 -0
  49. data/lib/temporalio/api/payload_visitor.rb +1513 -0
  50. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  51. data/lib/temporalio/api/query/v1/message.rb +27 -0
  52. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  53. data/lib/temporalio/api/schedule/v1/message.rb +43 -0
  54. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  55. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  56. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  57. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  58. data/lib/temporalio/api/taskqueue/v1/message.rb +45 -0
  59. data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
  60. data/lib/temporalio/api/testservice/v1/service.rb +23 -0
  61. data/lib/temporalio/api/update/v1/message.rb +33 -0
  62. data/lib/temporalio/api/version/v1/message.rb +26 -0
  63. data/lib/temporalio/api/workflow/v1/message.rb +43 -0
  64. data/lib/temporalio/api/workflowservice/v1/request_response.rb +204 -0
  65. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  66. data/lib/temporalio/api/workflowservice.rb +3 -0
  67. data/lib/temporalio/api.rb +14 -0
  68. data/lib/temporalio/cancellation.rb +170 -0
  69. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  70. data/lib/temporalio/client/async_activity_handle.rb +85 -0
  71. data/lib/temporalio/client/connection/cloud_service.rb +726 -0
  72. data/lib/temporalio/client/connection/operator_service.rb +201 -0
  73. data/lib/temporalio/client/connection/service.rb +42 -0
  74. data/lib/temporalio/client/connection/test_service.rb +111 -0
  75. data/lib/temporalio/client/connection/workflow_service.rb +1041 -0
  76. data/lib/temporalio/client/connection.rb +316 -0
  77. data/lib/temporalio/client/interceptor.rb +416 -0
  78. data/lib/temporalio/client/schedule.rb +967 -0
  79. data/lib/temporalio/client/schedule_handle.rb +126 -0
  80. data/lib/temporalio/client/workflow_execution.rb +100 -0
  81. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  82. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  83. data/lib/temporalio/client/workflow_handle.rb +389 -0
  84. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  85. data/lib/temporalio/client/workflow_update_handle.rb +65 -0
  86. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  87. data/lib/temporalio/client.rb +484 -0
  88. data/lib/temporalio/common_enums.rb +41 -0
  89. data/lib/temporalio/converters/data_converter.rb +99 -0
  90. data/lib/temporalio/converters/failure_converter.rb +202 -0
  91. data/lib/temporalio/converters/payload_codec.rb +26 -0
  92. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  93. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  94. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  95. data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
  96. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  97. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  98. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  99. data/lib/temporalio/converters/payload_converter.rb +71 -0
  100. data/lib/temporalio/converters/raw_value.rb +20 -0
  101. data/lib/temporalio/converters.rb +9 -0
  102. data/lib/temporalio/error/failure.rb +219 -0
  103. data/lib/temporalio/error.rb +155 -0
  104. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.so +0 -0
  105. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.so +0 -0
  106. data/lib/temporalio/internal/bridge/3.4/temporalio_bridge.so +0 -0
  107. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  108. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
  109. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  110. data/lib/temporalio/internal/bridge/api/common/common.rb +26 -0
  111. data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
  112. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  113. data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +33 -0
  114. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
  115. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +57 -0
  116. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +30 -0
  117. data/lib/temporalio/internal/bridge/api.rb +3 -0
  118. data/lib/temporalio/internal/bridge/client.rb +95 -0
  119. data/lib/temporalio/internal/bridge/runtime.rb +53 -0
  120. data/lib/temporalio/internal/bridge/testing.rb +66 -0
  121. data/lib/temporalio/internal/bridge/worker.rb +85 -0
  122. data/lib/temporalio/internal/bridge.rb +36 -0
  123. data/lib/temporalio/internal/client/implementation.rb +700 -0
  124. data/lib/temporalio/internal/metric.rb +122 -0
  125. data/lib/temporalio/internal/proto_utils.rb +133 -0
  126. data/lib/temporalio/internal/worker/activity_worker.rb +376 -0
  127. data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
  128. data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
  129. data/lib/temporalio/internal/worker/workflow_instance/context.rb +333 -0
  130. data/lib/temporalio/internal/worker/workflow_instance/details.rb +44 -0
  131. data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
  132. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
  133. data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
  134. data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
  135. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
  136. data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
  137. data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +415 -0
  138. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
  139. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
  140. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +163 -0
  141. data/lib/temporalio/internal/worker/workflow_instance.rb +730 -0
  142. data/lib/temporalio/internal/worker/workflow_worker.rb +236 -0
  143. data/lib/temporalio/internal.rb +7 -0
  144. data/lib/temporalio/metric.rb +109 -0
  145. data/lib/temporalio/retry_policy.rb +74 -0
  146. data/lib/temporalio/runtime.rb +314 -0
  147. data/lib/temporalio/scoped_logger.rb +96 -0
  148. data/lib/temporalio/search_attributes.rb +343 -0
  149. data/lib/temporalio/testing/activity_environment.rb +136 -0
  150. data/lib/temporalio/testing/workflow_environment.rb +383 -0
  151. data/lib/temporalio/testing.rb +10 -0
  152. data/lib/temporalio/version.rb +5 -0
  153. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  154. data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
  155. data/lib/temporalio/worker/activity_executor.rb +55 -0
  156. data/lib/temporalio/worker/interceptor.rb +362 -0
  157. data/lib/temporalio/worker/thread_pool.rb +237 -0
  158. data/lib/temporalio/worker/tuner.rb +189 -0
  159. data/lib/temporalio/worker/workflow_executor/thread_pool.rb +230 -0
  160. data/lib/temporalio/worker/workflow_executor.rb +26 -0
  161. data/lib/temporalio/worker/workflow_replayer.rb +343 -0
  162. data/lib/temporalio/worker.rb +569 -0
  163. data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
  164. data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
  165. data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
  166. data/lib/temporalio/workflow/definition.rb +566 -0
  167. data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
  168. data/lib/temporalio/workflow/future.rb +151 -0
  169. data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
  170. data/lib/temporalio/workflow/info.rb +82 -0
  171. data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
  172. data/lib/temporalio/workflow/update_info.rb +20 -0
  173. data/lib/temporalio/workflow.rb +529 -0
  174. data/lib/temporalio/workflow_history.rb +47 -0
  175. data/lib/temporalio.rb +11 -0
  176. data/temporalio.gemspec +28 -0
  177. metadata +238 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: de3dd4fa1f72313c1dc8d573a1b2432efbb7cfc6f2a06dfa7dcfa1e38bde940b
4
+ data.tar.gz: 6a7dfe99455fc5cb139f120ec1bb13cd8f4803d6b9d0441b7aa4672b8e8e70a6
5
+ SHA512:
6
+ metadata.gz: 5bfcaecf338dcd5a9f4e5104f5229c3a059f0c1aa0e2d6afd2715d9aab4e8f9dd4f1fcc51214d2e7d85a6b64d47882c93d8ba3d027d9353ea8bb00d756957212
7
+ data.tar.gz: f8dd70ef206b7233ad5f587aeee0ead2d19075f8a8b37732f0359e82081329fd2c7643a95321c9b64fd7541aa7baecdfe40f0401536b7e76b9221c64df89da18
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --readme README.md
2
+ --protected
data/Gemfile ADDED
@@ -0,0 +1,23 @@
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
+ gem 'rake'
16
+ gem 'rake-compiler'
17
+ gem 'rbs', '~> 3.5.3'
18
+ gem 'rb_sys', '~> 0.9.63'
19
+ gem 'rubocop'
20
+ gem 'sqlite3'
21
+ gem 'steep', '~> 1.7.1'
22
+ gem 'yard'
23
+ 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', '--', '-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,116 @@
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
+ def metric_meter
112
+ raise NotImplementedError
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Temporalio
4
+ module Activity
5
+ # Base class for all activities.
6
+ #
7
+ # Activities can be given to a worker as instances of this class, which will call execute on the same instance for
8
+ # each execution, or given to the worker as the class itself which instantiates the activity for each execution.
9
+ #
10
+ # All activities must implement {execute}. Inside execute, {Activity::Context.current} can be used to access the
11
+ # current context to get information, issue heartbeats, etc.
12
+ #
13
+ # By default, the activity is named as its unqualified class name. This can be customized with {activity_name}.
14
+ #
15
+ # By default, the activity uses the `:default` executor which is usually the thread-pool based executor. This can be
16
+ # customized with {activity_executor}.
17
+ #
18
+ # By default, upon cancellation {::Thread.raise} or {::Fiber.raise} is called with a {Error::CanceledError}. This
19
+ # can be disabled by passing `false` to {activity_cancel_raise}.
20
+ #
21
+ # See documentation for more detail on activities.
22
+ class Definition
23
+ class << self
24
+ protected
25
+
26
+ # Override the activity name which is defaulted to the unqualified class name.
27
+ #
28
+ # @param name [String, Symbol] Name to use.
29
+ def activity_name(name)
30
+ if !name.is_a?(Symbol) && !name.is_a?(String)
31
+ raise ArgumentError,
32
+ 'Activity name must be a symbol or string'
33
+ end
34
+
35
+ @activity_name = name.to_s
36
+ end
37
+
38
+ # Override the activity executor which is defaulted to `:default`.
39
+ #
40
+ # @param executor_name [Symbol] Executor to use.
41
+ def activity_executor(executor_name)
42
+ raise ArgumentError, 'Executor name must be a symbol' unless executor_name.is_a?(Symbol)
43
+
44
+ @activity_executor = executor_name
45
+ end
46
+
47
+ # Override whether the activity uses Thread/Fiber raise for cancellation which is defaulted to true.
48
+ #
49
+ # @param cancel_raise [Boolean] Whether to raise.
50
+ def activity_cancel_raise(cancel_raise)
51
+ unless cancel_raise.is_a?(TrueClass) || cancel_raise.is_a?(FalseClass)
52
+ raise ArgumentError, 'Must be a boolean'
53
+ end
54
+
55
+ @activity_cancel_raise = cancel_raise
56
+ end
57
+
58
+ # Set an activity as dynamic. Dynamic activities do not have names and handle any activity that is not otherwise
59
+ # registered. A worker can only have one dynamic activity. It is often useful to use {activity_raw_args} with
60
+ # this.
61
+ #
62
+ # @param value [Boolean] Whether the activity is dynamic.
63
+ def activity_dynamic(value = true) # rubocop:disable Style/OptionalBooleanParameter
64
+ raise ArgumentError, 'Must be a boolean' unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
65
+
66
+ @activity_dynamic = value
67
+ end
68
+
69
+ # Have activity arguments delivered to `execute` as {Converters::RawValue}s. These are wrappers for the raw
70
+ # payloads that have not been converted to types (but they have been decoded by the codec if present). They can
71
+ # be converted with {Context#payload_converter}.
72
+ #
73
+ # @param value [Boolean] Whether the activity accepts raw arguments.
74
+ def activity_raw_args(value = true) # rubocop:disable Style/OptionalBooleanParameter
75
+ raise ArgumentError, 'Must be a boolean' unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
76
+
77
+ @activity_raw_args = value
78
+ end
79
+ end
80
+
81
+ # @!visibility private
82
+ def self._activity_definition_details
83
+ activity_name = @activity_name
84
+ raise 'Cannot have activity name specified for dynamic activity' if activity_name && @activity_dynamic
85
+
86
+ # Default to unqualified class name if not dynamic
87
+ activity_name ||= name.to_s.split('::').last unless @activity_dynamic
88
+ {
89
+ activity_name:,
90
+ activity_executor: @activity_executor || :default,
91
+ activity_cancel_raise: @activity_cancel_raise.nil? ? true : @activity_cancel_raise,
92
+ activity_raw_args: @activity_raw_args.nil? ? false : @activity_raw_args
93
+ }
94
+ end
95
+
96
+ # Implementation of the activity. The arguments should be positional and this should return the value on success
97
+ # or raise an error on failure.
98
+ def execute(*args)
99
+ raise NotImplementedError, 'Activity did not implement "execute"'
100
+ end
101
+
102
+ # Definition info of an activity. Activities are usually classes/instances that extend {Definition}, but
103
+ # definitions can also be manually created with a block via {initialize} here.
104
+ class Info
105
+ # @return [String, Symbol, nil] Name of the activity, or nil if the activity is dynamic.
106
+ attr_reader :name
107
+
108
+ # @return [Object, Proc, nil] The pre-created instance or the proc to create/return it.
109
+ attr_reader :instance
110
+
111
+ # @return [Proc] Proc for the activity. Should use {Context#instance} to access the instance.
112
+ attr_reader :proc
113
+
114
+ # @return [Symbol] Name of the executor. Default is `:default`.
115
+ attr_reader :executor
116
+
117
+ # @return [Boolean] Whether to raise in thread/fiber on cancellation. Default is `true`.
118
+ attr_reader :cancel_raise
119
+
120
+ # @return [Boolean] Whether to use {Converters::RawValue}s as arguments.
121
+ attr_reader :raw_args
122
+
123
+ # Obtain definition info representing the given activity, which can be a class, instance, or definition info.
124
+ #
125
+ # @param activity [Definition, Class<Definition>, Info] Activity to get info for.
126
+ # @return Info Obtained definition info.
127
+ def self.from_activity(activity)
128
+ # Class means create each time, instance means just call, definition
129
+ # does nothing special
130
+ case activity
131
+ when Class
132
+ unless activity < Definition
133
+ raise ArgumentError,
134
+ "Class '#{activity}' does not extend Temporalio::Activity::Definition"
135
+ end
136
+
137
+ details = activity._activity_definition_details
138
+ new(
139
+ name: details[:activity_name],
140
+ instance: proc { activity.new },
141
+ executor: details[:activity_executor],
142
+ cancel_raise: details[:activity_cancel_raise],
143
+ raw_args: details[:activity_raw_args]
144
+ ) { |*args| Context.current.instance&.execute(*args) }
145
+ when Definition
146
+ details = activity.class._activity_definition_details
147
+ new(
148
+ name: details[:activity_name],
149
+ instance: activity,
150
+ executor: details[:activity_executor],
151
+ cancel_raise: details[:activity_cancel_raise],
152
+ raw_args: details[:activity_raw_args]
153
+ ) { |*args| Context.current.instance&.execute(*args) }
154
+ when Info
155
+ activity
156
+ else
157
+ raise ArgumentError, "#{activity} is not an activity class, instance, or definition info"
158
+ end
159
+ end
160
+
161
+ # Manually create activity definition info. Most users will use an instance/class of {Definition}.
162
+ #
163
+ # @param name [String, Symbol, nil] Name of the activity or nil for dynamic activity.
164
+ # @param instance [Object, Proc, nil] The pre-created instance or the proc to create/return it.
165
+ # @param executor [Symbol] Name of the executor.
166
+ # @param cancel_raise [Boolean] Whether to raise in thread/fiber on cancellation.
167
+ # @param raw_args [Boolean] Whether to use {Converters::RawValue}s as arguments.
168
+ # @yield Use this block as the activity.
169
+ def initialize(
170
+ name:,
171
+ instance: nil,
172
+ executor: :default,
173
+ cancel_raise: true,
174
+ raw_args: false,
175
+ &block
176
+ )
177
+ @name = name
178
+ @instance = instance
179
+ raise ArgumentError, 'Must give block' unless block_given?
180
+
181
+ @proc = block
182
+ @executor = executor
183
+ @cancel_raise = cancel_raise
184
+ @raw_args = raw_args
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,64 @@
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
+ class Info; end # rubocop:disable Lint/EmptyClass
63
+ end
64
+ 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,31 @@
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/timestamp_pb'
8
+ require 'temporalio/api/common/v1/message'
9
+ require 'temporalio/api/enums/v1/batch_operation'
10
+ require 'temporalio/api/enums/v1/reset'
11
+
12
+
13
+ descriptor_data = "\n#temporal/api/batch/v1/message.proto\x12\x15temporal.api.batch.v1\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\"\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.ResetReapplyTypeB\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"
14
+
15
+ pool = Google::Protobuf::DescriptorPool.generated_pool
16
+ pool.add_serialized_file(descriptor_data)
17
+
18
+ module Temporalio
19
+ module Api
20
+ module Batch
21
+ module V1
22
+ BatchOperationInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationInfo").msgclass
23
+ BatchOperationTermination = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationTermination").msgclass
24
+ BatchOperationSignal = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationSignal").msgclass
25
+ BatchOperationCancellation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationCancellation").msgclass
26
+ BatchOperationDeletion = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationDeletion").msgclass
27
+ BatchOperationReset = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("temporal.api.batch.v1.BatchOperationReset").msgclass
28
+ end
29
+ end
30
+ end
31
+ 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