clara-temporalio 0.4.3-arm64-darwin

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 (190) 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/cancellation_details.rb +58 -0
  6. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  7. data/lib/temporalio/activity/context.rb +131 -0
  8. data/lib/temporalio/activity/definition.rb +197 -0
  9. data/lib/temporalio/activity/info.rb +70 -0
  10. data/lib/temporalio/activity.rb +14 -0
  11. data/lib/temporalio/api/activity/v1/message.rb +25 -0
  12. data/lib/temporalio/api/batch/v1/message.rb +38 -0
  13. data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
  14. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +135 -0
  15. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
  16. data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
  17. data/lib/temporalio/api/cloud/identity/v1/message.rb +46 -0
  18. data/lib/temporalio/api/cloud/namespace/v1/message.rb +46 -0
  19. data/lib/temporalio/api/cloud/nexus/v1/message.rb +32 -0
  20. data/lib/temporalio/api/cloud/operation/v1/message.rb +28 -0
  21. data/lib/temporalio/api/cloud/region/v1/message.rb +24 -0
  22. data/lib/temporalio/api/cloud/resource/v1/message.rb +23 -0
  23. data/lib/temporalio/api/cloud/sink/v1/message.rb +24 -0
  24. data/lib/temporalio/api/cloud/usage/v1/message.rb +31 -0
  25. data/lib/temporalio/api/command/v1/message.rb +46 -0
  26. data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
  27. data/lib/temporalio/api/common/v1/message.rb +49 -0
  28. data/lib/temporalio/api/deployment/v1/message.rb +39 -0
  29. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  30. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  31. data/lib/temporalio/api/enums/v1/common.rb +28 -0
  32. data/lib/temporalio/api/enums/v1/deployment.rb +23 -0
  33. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  34. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  35. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  36. data/lib/temporalio/api/enums/v1/nexus.rb +21 -0
  37. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  38. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  39. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  40. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  41. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  42. data/lib/temporalio/api/enums/v1/workflow.rb +31 -0
  43. data/lib/temporalio/api/errordetails/v1/message.rb +44 -0
  44. data/lib/temporalio/api/export/v1/message.rb +24 -0
  45. data/lib/temporalio/api/failure/v1/message.rb +38 -0
  46. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  47. data/lib/temporalio/api/history/v1/message.rb +94 -0
  48. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  49. data/lib/temporalio/api/nexus/v1/message.rb +41 -0
  50. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  51. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  52. data/lib/temporalio/api/operatorservice.rb +3 -0
  53. data/lib/temporalio/api/payload_visitor.rb +1668 -0
  54. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  55. data/lib/temporalio/api/query/v1/message.rb +28 -0
  56. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  57. data/lib/temporalio/api/rules/v1/message.rb +27 -0
  58. data/lib/temporalio/api/schedule/v1/message.rb +43 -0
  59. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  60. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  61. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  62. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  63. data/lib/temporalio/api/taskqueue/v1/message.rb +48 -0
  64. data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
  65. data/lib/temporalio/api/testservice/v1/service.rb +23 -0
  66. data/lib/temporalio/api/update/v1/message.rb +33 -0
  67. data/lib/temporalio/api/version/v1/message.rb +26 -0
  68. data/lib/temporalio/api/workflow/v1/message.rb +63 -0
  69. data/lib/temporalio/api/workflowservice/v1/request_response.rb +244 -0
  70. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  71. data/lib/temporalio/api/workflowservice.rb +3 -0
  72. data/lib/temporalio/api.rb +15 -0
  73. data/lib/temporalio/cancellation.rb +170 -0
  74. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  75. data/lib/temporalio/client/async_activity_handle.rb +85 -0
  76. data/lib/temporalio/client/connection/cloud_service.rb +786 -0
  77. data/lib/temporalio/client/connection/operator_service.rb +201 -0
  78. data/lib/temporalio/client/connection/service.rb +42 -0
  79. data/lib/temporalio/client/connection/test_service.rb +111 -0
  80. data/lib/temporalio/client/connection/workflow_service.rb +1326 -0
  81. data/lib/temporalio/client/connection.rb +316 -0
  82. data/lib/temporalio/client/interceptor.rb +457 -0
  83. data/lib/temporalio/client/schedule.rb +991 -0
  84. data/lib/temporalio/client/schedule_handle.rb +126 -0
  85. data/lib/temporalio/client/with_start_workflow_operation.rb +115 -0
  86. data/lib/temporalio/client/workflow_execution.rb +119 -0
  87. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  88. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  89. data/lib/temporalio/client/workflow_handle.rb +389 -0
  90. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  91. data/lib/temporalio/client/workflow_update_handle.rb +65 -0
  92. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  93. data/lib/temporalio/client.rb +625 -0
  94. data/lib/temporalio/common_enums.rb +55 -0
  95. data/lib/temporalio/contrib/open_telemetry.rb +469 -0
  96. data/lib/temporalio/converters/data_converter.rb +99 -0
  97. data/lib/temporalio/converters/failure_converter.rb +205 -0
  98. data/lib/temporalio/converters/payload_codec.rb +26 -0
  99. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  100. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  101. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  102. data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
  103. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  104. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  105. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  106. data/lib/temporalio/converters/payload_converter.rb +71 -0
  107. data/lib/temporalio/converters/raw_value.rb +20 -0
  108. data/lib/temporalio/converters.rb +9 -0
  109. data/lib/temporalio/error/failure.rb +237 -0
  110. data/lib/temporalio/error.rb +156 -0
  111. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.bundle +0 -0
  112. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.bundle +0 -0
  113. data/lib/temporalio/internal/bridge/3.4/temporalio_bridge.bundle +0 -0
  114. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  115. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +32 -0
  116. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  117. data/lib/temporalio/internal/bridge/api/common/common.rb +27 -0
  118. data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
  119. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  120. data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +34 -0
  121. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
  122. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +58 -0
  123. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +31 -0
  124. data/lib/temporalio/internal/bridge/api.rb +3 -0
  125. data/lib/temporalio/internal/bridge/client.rb +95 -0
  126. data/lib/temporalio/internal/bridge/runtime.rb +56 -0
  127. data/lib/temporalio/internal/bridge/testing.rb +69 -0
  128. data/lib/temporalio/internal/bridge/worker.rb +109 -0
  129. data/lib/temporalio/internal/bridge.rb +36 -0
  130. data/lib/temporalio/internal/client/implementation.rb +926 -0
  131. data/lib/temporalio/internal/metric.rb +122 -0
  132. data/lib/temporalio/internal/proto_utils.rb +165 -0
  133. data/lib/temporalio/internal/worker/activity_worker.rb +448 -0
  134. data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
  135. data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
  136. data/lib/temporalio/internal/worker/workflow_instance/context.rb +391 -0
  137. data/lib/temporalio/internal/worker/workflow_instance/details.rb +49 -0
  138. data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
  139. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
  140. data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
  141. data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
  142. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
  143. data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
  144. data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +404 -0
  145. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
  146. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
  147. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +183 -0
  148. data/lib/temporalio/internal/worker/workflow_instance.rb +800 -0
  149. data/lib/temporalio/internal/worker/workflow_worker.rb +249 -0
  150. data/lib/temporalio/internal.rb +7 -0
  151. data/lib/temporalio/metric.rb +109 -0
  152. data/lib/temporalio/priority.rb +59 -0
  153. data/lib/temporalio/retry_policy.rb +74 -0
  154. data/lib/temporalio/runtime/metric_buffer.rb +94 -0
  155. data/lib/temporalio/runtime.rb +352 -0
  156. data/lib/temporalio/scoped_logger.rb +96 -0
  157. data/lib/temporalio/search_attributes.rb +356 -0
  158. data/lib/temporalio/testing/activity_environment.rb +175 -0
  159. data/lib/temporalio/testing/workflow_environment.rb +406 -0
  160. data/lib/temporalio/testing.rb +10 -0
  161. data/lib/temporalio/version.rb +5 -0
  162. data/lib/temporalio/versioning_override.rb +55 -0
  163. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  164. data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
  165. data/lib/temporalio/worker/activity_executor.rb +55 -0
  166. data/lib/temporalio/worker/deployment_options.rb +45 -0
  167. data/lib/temporalio/worker/interceptor.rb +367 -0
  168. data/lib/temporalio/worker/poller_behavior.rb +61 -0
  169. data/lib/temporalio/worker/thread_pool.rb +237 -0
  170. data/lib/temporalio/worker/tuner.rb +189 -0
  171. data/lib/temporalio/worker/workflow_executor/thread_pool.rb +236 -0
  172. data/lib/temporalio/worker/workflow_executor.rb +26 -0
  173. data/lib/temporalio/worker/workflow_replayer.rb +349 -0
  174. data/lib/temporalio/worker.rb +633 -0
  175. data/lib/temporalio/worker_deployment_version.rb +67 -0
  176. data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
  177. data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
  178. data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
  179. data/lib/temporalio/workflow/definition.rb +680 -0
  180. data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
  181. data/lib/temporalio/workflow/future.rb +151 -0
  182. data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
  183. data/lib/temporalio/workflow/info.rb +107 -0
  184. data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
  185. data/lib/temporalio/workflow/update_info.rb +20 -0
  186. data/lib/temporalio/workflow.rb +594 -0
  187. data/lib/temporalio/workflow_history.rb +47 -0
  188. data/lib/temporalio.rb +12 -0
  189. data/temporalio.gemspec +31 -0
  190. metadata +267 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60dc1e6bea61fc8dd219f9e320668b7cb194148e0fd4dbeb50a3fe4d18d52272
4
+ data.tar.gz: 9b4b5a8556f132ac9826b5b4d2c11331a7e685076fd25fc1da698b7b82dcb597
5
+ SHA512:
6
+ metadata.gz: e3c28ba08fb0925ca7a120d37345dbc779da6aa5fea5ad0fa1ca76e6b285e39ca72dd70522901aae139470d3f5b58f2347c1e9cb42281043573007b24a233588
7
+ data.tar.gz: 9bdaa8f7a23248d1f9b54de29352748f79e94cda45be00b711723596ae37af7465bbff9cf23ffa5e083ef9c3fca0e521715dd4a1758691a4b2fbe64d09081d7d
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,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/error'
4
+
5
+ module Temporalio
6
+ module Activity
7
+ # Details that are set when an activity is cancelled. This is only valid at the time the cancel was received, the
8
+ # state may change on the server after it is received.
9
+ class CancellationDetails
10
+ def initialize(
11
+ gone_from_server: false,
12
+ cancel_requested: true,
13
+ timed_out: false,
14
+ worker_shutdown: false,
15
+ paused: false,
16
+ reset: false
17
+ )
18
+ @gone_from_server = gone_from_server
19
+ @cancel_requested = cancel_requested
20
+ @timed_out = timed_out
21
+ @worker_shutdown = worker_shutdown
22
+ @paused = paused
23
+ @reset = reset
24
+ end
25
+
26
+ # @return [Boolean] Whether the activity no longer exists on the server (may already be completed or its workflow
27
+ # may be completed).
28
+ def gone_from_server?
29
+ @gone_from_server
30
+ end
31
+
32
+ # @return [Boolean] Whether the activity was explicitly cancelled.
33
+ def cancel_requested?
34
+ @cancel_requested
35
+ end
36
+
37
+ # @return [Boolean] Whether the activity timeout caused activity to be marked cancelled.
38
+ def timed_out?
39
+ @timed_out
40
+ end
41
+
42
+ # @return [Boolean] Whether the worker the activity is running on is shutting down.
43
+ def worker_shutdown?
44
+ @worker_shutdown
45
+ end
46
+
47
+ # @return [Boolean] Whether the activity was explicitly paused.
48
+ def paused?
49
+ @paused
50
+ end
51
+
52
+ # @return [Boolean] Whether the activity was explicitly reset.
53
+ def reset?
54
+ @reset
55
+ end
56
+ end
57
+ end
58
+ end
@@ -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,131 @@
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 [CancellationDetails, nil] Cancellation details if canceled. These are set just before cancellation is
74
+ # actually canceled. These details only represent when the cancel was first performed. Once set, this object is
75
+ # never mutated. Therefore, the situation on the server may have changed (e.g. unpause), but this still
76
+ # represents the values when cancellation first occurred for this attempt.
77
+ def cancellation_details
78
+ raise NotImplementedError
79
+ end
80
+
81
+ # @return [Cancellation] Cancellation that is canceled when the worker is shutting down. On worker shutdown, this
82
+ # is canceled, then the `graceful_shutdown_period` is waited (default 0s), then the activity is canceled.
83
+ def worker_shutdown_cancellation
84
+ raise NotImplementedError
85
+ end
86
+
87
+ # @return [Converters::PayloadConverter] Payload converter associated with this activity.
88
+ def payload_converter
89
+ raise NotImplementedError
90
+ end
91
+
92
+ # @return [ScopedLogger] Logger for this activity. Note, this is a shared logger not created each activity
93
+ # invocation. It just has logic to extract current activity details and so is only able to do so on log calls
94
+ # made with a current context available.
95
+ def logger
96
+ raise NotImplementedError
97
+ end
98
+
99
+ # @!visibility private
100
+ def _scoped_logger_info
101
+ return @scoped_logger_info unless @scoped_logger_info.nil?
102
+
103
+ curr_info = info
104
+ @scoped_logger_info = {
105
+ temporal_activity: {
106
+ activity_id: curr_info.activity_id,
107
+ activity_type: curr_info.activity_type,
108
+ attempt: curr_info.attempt,
109
+ task_queue: curr_info.task_queue,
110
+ workflow_id: curr_info.workflow_id,
111
+ workflow_namespace: curr_info.workflow_namespace,
112
+ workflow_run_id: curr_info.workflow_run_id,
113
+ workflow_type: curr_info.workflow_type
114
+ }
115
+ }.freeze
116
+ end
117
+
118
+ # @return [Metric::Meter] Metric meter to create metrics on, with some activity-specific attributes already set.
119
+ # @raise [RuntimeError] Called within a {Testing::ActivityEnvironment} and it was not set.
120
+ def metric_meter
121
+ raise NotImplementedError
122
+ end
123
+
124
+ # @return [Client] Temporal client this activity worker is running in.
125
+ # @raise [RuntimeError] Called within a {Testing::ActivityEnvironment} and it was not set.
126
+ def client
127
+ raise NotImplementedError
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,197 @@
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
+ # Disallow kwargs in execute parameters
89
+ if instance_method(:execute).parameters.any? { |t, _| t == :key || t == :keyreq }
90
+ raise 'Activity execute cannot have keyword arguments'
91
+ end
92
+
93
+ # Default to unqualified class name if not dynamic
94
+ activity_name ||= name.to_s.split('::').last unless @activity_dynamic
95
+ {
96
+ activity_name:,
97
+ activity_executor: @activity_executor || :default,
98
+ activity_cancel_raise: @activity_cancel_raise.nil? || @activity_cancel_raise,
99
+ activity_raw_args: @activity_raw_args.nil? ? false : @activity_raw_args
100
+ }
101
+ end
102
+
103
+ # Implementation of the activity. The arguments should be positional and this should return the value on success
104
+ # or raise an error on failure.
105
+ def execute(*args)
106
+ raise NotImplementedError, 'Activity did not implement "execute"'
107
+ end
108
+
109
+ # Definition info of an activity. Activities are usually classes/instances that extend {Definition}, but
110
+ # definitions can also be manually created with a block via {initialize} here.
111
+ class Info
112
+ # @return [String, Symbol, nil] Name of the activity, or nil if the activity is dynamic.
113
+ attr_reader :name
114
+
115
+ # @return [Object, Proc, nil] The pre-created instance or the proc to create/return it.
116
+ attr_reader :instance
117
+
118
+ # @return [Proc] Proc for the activity. Should use {Context#instance} to access the instance.
119
+ attr_reader :proc
120
+
121
+ # @return [Symbol] Name of the executor. Default is `:default`.
122
+ attr_reader :executor
123
+
124
+ # @return [Boolean] Whether to raise in thread/fiber on cancellation. Default is `true`.
125
+ attr_reader :cancel_raise
126
+
127
+ # @return [Boolean] Whether to use {Converters::RawValue}s as arguments.
128
+ attr_reader :raw_args
129
+
130
+ # Obtain definition info representing the given activity, which can be a class, instance, or definition info.
131
+ #
132
+ # @param activity [Definition, Class<Definition>, Info] Activity to get info for.
133
+ # @return Info Obtained definition info.
134
+ def self.from_activity(activity)
135
+ # Class means create each time, instance means just call, definition
136
+ # does nothing special
137
+ case activity
138
+ when Class
139
+ unless activity < Definition
140
+ raise ArgumentError,
141
+ "Class '#{activity}' does not extend Temporalio::Activity::Definition"
142
+ end
143
+
144
+ details = activity._activity_definition_details
145
+ new(
146
+ name: details[:activity_name],
147
+ instance: proc { activity.new },
148
+ executor: details[:activity_executor],
149
+ cancel_raise: details[:activity_cancel_raise],
150
+ raw_args: details[:activity_raw_args]
151
+ ) { |*args| Context.current.instance&.execute(*args) }
152
+ when Definition
153
+ details = activity.class._activity_definition_details
154
+ new(
155
+ name: details[:activity_name],
156
+ instance: activity,
157
+ executor: details[:activity_executor],
158
+ cancel_raise: details[:activity_cancel_raise],
159
+ raw_args: details[:activity_raw_args]
160
+ ) { |*args| Context.current.instance&.execute(*args) }
161
+ when Info
162
+ activity
163
+ else
164
+ raise ArgumentError, "#{activity} is not an activity class, instance, or definition info"
165
+ end
166
+ end
167
+
168
+ # Manually create activity definition info. Most users will use an instance/class of {Definition}.
169
+ #
170
+ # @param name [String, Symbol, nil] Name of the activity or nil for dynamic activity.
171
+ # @param instance [Object, Proc, nil] The pre-created instance or the proc to create/return it.
172
+ # @param executor [Symbol] Name of the executor.
173
+ # @param cancel_raise [Boolean] Whether to raise in thread/fiber on cancellation.
174
+ # @param raw_args [Boolean] Whether to use {Converters::RawValue}s as arguments.
175
+ # @yield Use this block as the activity.
176
+ def initialize(
177
+ name:,
178
+ instance: nil,
179
+ executor: :default,
180
+ cancel_raise: true,
181
+ raw_args: false,
182
+ &block
183
+ )
184
+ @name = name
185
+ @instance = instance
186
+ raise ArgumentError, 'Must give block' unless block_given?
187
+
188
+ @proc = block
189
+ @executor = executor
190
+ @cancel_raise = cancel_raise
191
+ @raw_args = raw_args
192
+ Internal::ProtoUtils.assert_non_reserved_name(name)
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,70 @@
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
+ :priority,
14
+ :schedule_to_close_timeout,
15
+ :scheduled_time,
16
+ :start_to_close_timeout,
17
+ :started_time,
18
+ :task_queue,
19
+ :task_token,
20
+ :workflow_id,
21
+ :workflow_namespace,
22
+ :workflow_run_id,
23
+ :workflow_type
24
+ )
25
+
26
+ # Information about an activity.
27
+ #
28
+ # @!attribute activity_id
29
+ # @return [String] ID for the activity.
30
+ # @!attribute activity_type
31
+ # @return [String] Type name for the activity.
32
+ # @!attribute attempt
33
+ # @return [Integer] Attempt the activity is on.
34
+ # @!attribute current_attempt_scheduled_time
35
+ # @return [Time] When the current attempt was scheduled.
36
+ # @!attribute heartbeat_details
37
+ # @return [Array<Object>] Details from the last heartbeat of the last attempt.
38
+ # @!attribute heartbeat_timeout
39
+ # @return [Float, nil] Heartbeat timeout set by the caller.
40
+ # @!attribute local?
41
+ # @return [Boolean] Whether the activity is a local activity or not.
42
+ # @!attribute priority
43
+ # @return [Priority] The priority of this activity.
44
+ # @!attribute schedule_to_close_timeout
45
+ # @return [Float, nil] Schedule to close timeout set by the caller.
46
+ # @!attribute scheduled_time
47
+ # @return [Time] When the activity was scheduled.
48
+ # @!attribute start_to_close_timeout
49
+ # @return [Float, nil] Start to close timeout set by the caller.
50
+ # @!attribute started_time
51
+ # @return [Time] When the activity started.
52
+ # @!attribute task_queue
53
+ # @return [String] Task queue this activity is on.
54
+ # @!attribute task_token
55
+ # @return [String] Task token uniquely identifying this activity. Note, this is a `ASCII-8BIT` encoded string, not
56
+ # a `UTF-8` encoded string nor a valid UTF-8 string.
57
+ # @!attribute workflow_id
58
+ # @return [String] Workflow ID that started this activity.
59
+ # @!attribute workflow_namespace
60
+ # @return [String] Namespace this activity is on.
61
+ # @!attribute workflow_run_id
62
+ # @return [String] Workflow run ID that started this activity.
63
+ # @!attribute workflow_type
64
+ # @return [String] Workflow type name that started this activity.
65
+ #
66
+ # @note WARNING: This class may have required parameters added to its constructor. Users should not instantiate this
67
+ # class or it may break in incompatible ways.
68
+ class Info; end # rubocop:disable Lint/EmptyClass
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/activity/cancellation_details'
4
+ require 'temporalio/activity/complete_async_error'
5
+ require 'temporalio/activity/context'
6
+ require 'temporalio/activity/definition'
7
+ require 'temporalio/activity/info'
8
+ require 'temporalio/priority'
9
+
10
+ module Temporalio
11
+ # All activity related classes.
12
+ module Activity
13
+ end
14
+ 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