temporalio 0.0.1 → 0.0.2

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 (232) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -4
  3. data/bridge/Cargo.lock +44 -21
  4. data/bridge/Cargo.toml +1 -0
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +1 -4
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +12 -20
  9. data/bridge/sdk-core/client/src/raw.rs +9 -8
  10. data/bridge/sdk-core/client/src/retry.rs +100 -23
  11. data/bridge/sdk-core/core/Cargo.toml +7 -7
  12. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  13. data/bridge/sdk-core/core/src/abstractions.rs +22 -22
  14. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +146 -43
  15. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +419 -9
  16. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -89
  17. data/bridge/sdk-core/core/src/core_tests/workers.rs +2 -2
  18. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  19. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +47 -27
  20. data/bridge/sdk-core/core/src/lib.rs +139 -32
  21. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  22. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  23. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  24. data/bridge/sdk-core/core/src/telemetry/metrics.rs +184 -139
  25. data/bridge/sdk-core/core/src/telemetry/mod.rs +310 -315
  26. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
  27. data/bridge/sdk-core/core/src/test_help/mod.rs +23 -9
  28. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +12 -6
  29. data/bridge/sdk-core/core/src/worker/activities.rs +40 -23
  30. data/bridge/sdk-core/core/src/worker/client/mocks.rs +1 -1
  31. data/bridge/sdk-core/core/src/worker/client.rs +30 -4
  32. data/bridge/sdk-core/core/src/worker/mod.rs +23 -19
  33. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
  34. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
  35. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
  36. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
  37. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
  38. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +3 -5
  39. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
  40. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
  41. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +24 -22
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +233 -217
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
  53. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
  54. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
  55. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +86 -29
  56. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
  57. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
  58. data/bridge/sdk-core/core-api/Cargo.toml +4 -3
  59. data/bridge/sdk-core/core-api/src/lib.rs +1 -43
  60. data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
  61. data/bridge/sdk-core/core-api/src/worker.rs +13 -0
  62. data/bridge/sdk-core/etc/deps.svg +115 -140
  63. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  64. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  65. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  66. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  67. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  68. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  69. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  70. data/bridge/sdk-core/protos/api_upstream/{temporal/api/update/v1/message.proto → build/tools.go} +6 -23
  71. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  72. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  73. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +20 -19
  74. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
  75. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  76. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -4
  77. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  78. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +5 -3
  79. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +23 -2
  80. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/{cluster.proto → interaction_type.proto} +10 -11
  81. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  82. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  83. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  84. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  85. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  86. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +2 -13
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +26 -19
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -2
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +21 -61
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -16
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +17 -3
  104. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
  105. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
  106. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  107. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  108. data/bridge/sdk-core/sdk/Cargo.toml +2 -2
  109. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  110. data/bridge/sdk-core/sdk/src/lib.rs +7 -5
  111. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  112. data/bridge/sdk-core/sdk/src/workflow_future.rs +3 -7
  113. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +1 -1
  114. data/bridge/sdk-core/sdk-core-protos/build.rs +0 -1
  115. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +65 -18
  116. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
  117. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +104 -44
  118. data/bridge/sdk-core/test-utils/Cargo.toml +2 -1
  119. data/bridge/sdk-core/test-utils/src/lib.rs +81 -29
  120. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -2
  121. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
  122. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
  123. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +167 -13
  124. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
  125. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
  126. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
  127. data/bridge/sdk-core/tests/main.rs +6 -4
  128. data/bridge/src/connection.rs +81 -62
  129. data/bridge/src/lib.rs +92 -33
  130. data/bridge/src/runtime.rs +9 -2
  131. data/bridge/src/worker.rs +53 -2
  132. data/lib/bridge.so +0 -0
  133. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  134. data/lib/gen/temporal/api/command/v1/message_pb.rb +17 -9
  135. data/lib/gen/temporal/api/common/v1/message_pb.rb +1 -1
  136. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  137. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -1
  138. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  139. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +3 -2
  140. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +7 -1
  141. data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
  142. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  143. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  144. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  145. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  146. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  147. data/lib/gen/temporal/api/enums/v1/update_pb.rb +1 -6
  148. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  149. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  150. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  151. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  152. data/lib/gen/temporal/api/history/v1/message_pb.rb +19 -18
  153. data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
  154. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +1 -1
  155. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +11 -51
  156. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  157. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  158. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  159. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  160. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  161. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  162. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  163. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +27 -10
  164. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  165. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +1 -0
  166. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +5 -1
  167. data/lib/temporalio/activity/context.rb +97 -0
  168. data/lib/temporalio/activity/info.rb +67 -0
  169. data/lib/temporalio/activity.rb +85 -0
  170. data/lib/temporalio/bridge/error.rb +8 -0
  171. data/lib/temporalio/bridge.rb +14 -0
  172. data/lib/{temporal → temporalio}/client/implementation.rb +49 -48
  173. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  174. data/lib/{temporal → temporalio}/client.rb +19 -32
  175. data/lib/{temporal → temporalio}/connection.rb +238 -223
  176. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  177. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  178. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  179. data/lib/{temporal → temporalio}/errors.rb +19 -1
  180. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  181. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  182. data/lib/temporalio/failure_converter.rb +7 -0
  183. data/lib/{temporal → temporalio}/interceptor/chain.rb +2 -1
  184. data/lib/{temporal → temporalio}/interceptor/client.rb +22 -1
  185. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  186. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  187. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  188. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  189. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  190. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  191. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  192. data/lib/temporalio/payload_converter.rb +14 -0
  193. data/lib/{temporal → temporalio}/retry_policy.rb +4 -4
  194. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  195. data/lib/temporalio/runtime.rb +25 -0
  196. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  197. data/lib/temporalio/version.rb +3 -0
  198. data/lib/temporalio/worker/activity_runner.rb +92 -0
  199. data/lib/temporalio/worker/activity_worker.rb +138 -0
  200. data/lib/temporalio/worker/reactor.rb +46 -0
  201. data/lib/temporalio/worker/runner.rb +63 -0
  202. data/lib/temporalio/worker/sync_worker.rb +88 -0
  203. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  204. data/lib/temporalio/worker.rb +198 -0
  205. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  206. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  207. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  208. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  209. data/lib/temporalio.rb +12 -3
  210. data/temporalio.gemspec +7 -3
  211. metadata +79 -56
  212. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  213. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  214. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  215. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  216. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  217. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  218. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  219. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  220. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  221. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  222. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  223. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  224. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  225. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  226. data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -26
  227. data/lib/temporal/bridge.rb +0 -14
  228. data/lib/temporal/failure_converter.rb +0 -8
  229. data/lib/temporal/payload_converter.rb +0 -14
  230. data/lib/temporal/runtime.rb +0 -22
  231. data/lib/temporal/version.rb +0 -3
  232. data/lib/temporal.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c61a784d88682c42f1dae18ee88ce556f6f705914abccf793f7a37ae4877bb83
4
- data.tar.gz: 72a8f479f63d3acad8944eee20f4eb53f2db84e6304c930d29d2180e4181100f
3
+ metadata.gz: 657f0a3bde04af32d78ce4f6b58103ba1eb5e16b6b023aea02fdd8889fe7594c
4
+ data.tar.gz: 7b51a09196eb6dde92b54e31b1abad8cf7ce3a41f2c719de73d8341e83d5d95e
5
5
  SHA512:
6
- metadata.gz: c6d6e559f5f71e48d823acef13e32576fc61d589882f35c6ba5b2bbd5addd83bfbab0cf76480de6895e9afa005c2fa9a8fa2dd973048443fd152d5057ea9724f
7
- data.tar.gz: 1cab9eb98faaa44e715f046870bcc83a64a979720da6ef28c1ff5dd0a600041cd7f32a4bdc44afcc9b4576171d07b36fe80c7eb7815c5a5c83f52c51f96cb16e
6
+ metadata.gz: 768d7983132b8a4bc3bd359be90a621463f9abd0e3a6de51dbd13256c86e9f60f916142b3301d22082e7ffacba156b5a97666b4f189299e976bc890c224fe2bb
7
+ data.tar.gz: 7602428c63547f9de4da9dcbd4180d58617eae04fb5478a58fbfc16c2d7f27fda8894134ab1a7d37dfe3c79f0c67d97eabf5f2f7f50e0112f19dbcc12f32d1d3
data/README.md CHANGED
@@ -23,12 +23,17 @@ At this point the SDK only supports the **Temporal Client** capabilities:
23
23
  - gRPC access to Temporal Server
24
24
  - Temporal Cloud is not yet supported due to the lack of TLS support, but it's coming soon
25
25
 
26
+ As well as **Activity Worker** capabilities:
27
+
28
+ - Definiting activities
29
+ - Activity heartbeats/cancellations
30
+ - Running activity workers
26
31
 
27
32
  ## Quick Start
28
33
 
29
34
  ### Installation
30
35
 
31
- Add the [`temporalio` gem](https://rubygems.org/gems/temporalio) to your Gemfile:
36
+ Add the [temporalio gem](https://rubygems.org/gems/temporalio) to your Gemfile:
32
37
 
33
38
  ```ruby
34
39
  gem 'temporalio'
@@ -47,10 +52,10 @@ A client can be created and used to start a workflow like so:
47
52
 
48
53
  ```ruby
49
54
  # Establish a gRPC connection to the server
50
- connection = Temporal::Connection.new('localhost:7233')
55
+ connection = Temporalio::Connection.new('localhost:7233')
51
56
 
52
57
  # Initialize a Client with a namespace
53
- client = Temporal::Client.new(connection, 'my-namespace')
58
+ client = Temporalio::Client.new(connection, 'my-namespace')
54
59
 
55
60
  # Start a workflow
56
61
  handle = client.start_workflow('MyWorkflow', 'some input', id: 'my-id', task_queue: 'my-task-queue')
@@ -82,12 +87,178 @@ The default data converter supports converting multiple types including:
82
87
 
83
88
  - `nil`
84
89
  - bytes (`String` with `Encoding::ASCII_8BIT`)
85
- - Anything that [`JSON.generate`](https://ruby-doc.org/stdlib-3.0.0/libdoc/json/rdoc/JSON.html#method-i-generate)
90
+ - Anything that [JSON.generate](https://ruby-doc.org/stdlib-3.0.0/libdoc/json/rdoc/JSON.html#method-i-generate)
86
91
  supports
87
92
 
88
93
  This notably doesn't include any `Date`, `Time`, or `DateTime` objects as they may not work across
89
94
  different SDKs. A custom payload converter can be implemented to support these.
90
95
 
96
+ ### Workers
97
+
98
+ Workers host workflows (coming soon) and/or activities. Here's how to run a worker:
99
+
100
+ ```ruby
101
+ require 'temporal'
102
+
103
+ # Establish a gRPC connection to the server
104
+ connection = Temporal::Connection.new('localhost:7233')
105
+
106
+ # Initialize a new worker with your activities
107
+ worker = Temporal::Worker.new(connection, 'my-namespace', 'my-task-queue', activities: [MyActivity])
108
+
109
+ # Occupy the thread by running the worker
110
+ worker.run
111
+ ```
112
+
113
+ Some things to note about the above code:
114
+
115
+ - This creates/uses the same connection that is used for initializing a client
116
+ - Workers can have many more options not shown here (e.g. data converters and interceptors)
117
+
118
+ In order to have more control over running of a worker you can provide a block of code by the end of
119
+ which the worker will shut itself down:
120
+
121
+ ```ruby
122
+ # Initialize worker_1, worker_2 and worker_3 as in the example above
123
+
124
+ # Run the worker for 5 seconds, then shut down
125
+ worker_1.run { sleep 5 }
126
+
127
+ # Or shut the worker down when a workflow completes (very useful for running specs):
128
+ client = Temporal::Client.new(connection, 'my-namespace')
129
+ handle = client.start_workflow('MyWorkflow', 'some input', id: 'my-id', task_queue: 'my-task-queue')
130
+ worker_2.run { handle.result }
131
+
132
+ # Or wait for some external signal to stop the worker
133
+ stop_queue = Queue.new
134
+ Signal.trap('USR1') { stop_queue.close }
135
+ worker_3.run { stop_queue.pop }
136
+ ```
137
+
138
+ You can also shut down a running worker by calling `Temporal::Worker#shutdown` from a separate
139
+ thread at any time.
140
+
141
+ #### Running multiple workers
142
+
143
+ In order to run multiple workers in the same thread you can use the `Temporal::Worker.run` method:
144
+
145
+ ```ruby
146
+ # Initialize workers
147
+ worker_1 = Temporal::Worker.new(connection, 'my-namespace-1', 'my-task-queue-1', activities: [MyActivity1, MyActivity2])
148
+ worker_2 = Temporal::Worker.new(connection, 'my-namespace-2', 'my-task-queue-1', activities: [MyActivity3])
149
+ worker_3 = Temporal::Worker.new(connection, 'my-namespace-1', 'my-task-queue-2', activities: [MyActivity4])
150
+
151
+ Temporal::Worker.run(worker_1, worker_2, worker_3)
152
+ ```
153
+
154
+ Please note that similar to `Temporal::Worker#run`, `Temporal::Worker.run` accepts a block that
155
+ behaves the same way — the workers will be shut down when the block finishes.
156
+
157
+ You can also configure your worker to listen on process signals to initiate a shutdown:
158
+
159
+ ```ruby
160
+ Temporal::Worker.run(worker_1, worker_2, worker_3, shutdown_signals: %w[INT TERM])
161
+ ```
162
+
163
+ #### Worker Shutdown
164
+
165
+ The `Temporal::Worker#run` (as well as `Temporal::Worker#shutdown`) invocation will wait on all
166
+ activities to complete, so if a long-running activity does not at least respect cancellation, the
167
+ shutdown may never complete.
168
+
169
+ If a worker was initialized with a `graceful_shutdown_timeout` option then a cancellation will be
170
+ issued for every running activity after the set timeout. The bahaviour is mostly identical to a
171
+ server requested cancellation and should be handled accordingly. More on this in [Heartbeating and
172
+ Cancellation](#heartbeating-and-cancellation).
173
+
174
+ ### Activities
175
+
176
+ #### Definition
177
+
178
+ Activities are defined by subclassing `Temporal::Activity` class:
179
+
180
+ ```ruby
181
+ class SayHelloActivity < Temporal::Activity
182
+ # Optionally specify a custom activity name:
183
+ # (The class name `SayHelloActivity` will be used by default)
184
+ activity_name 'say-hello'
185
+
186
+ def execute(name)
187
+ return "Hello, #{name}!"
188
+ end
189
+ end
190
+ ```
191
+
192
+ Some things to note about activity definitions:
193
+
194
+ - Long running activities should regularly heartbeat and handle cancellation
195
+ - Activities can only have positional arguments. Best practice is to only take a single argument
196
+ that is an object/dataclass of fields that can be added to as needed.
197
+
198
+ #### Activity Context
199
+
200
+ Activity classes have access to `Temporal::Activity::Context` via the `activity` method. Which
201
+ itself provides access to useful methods, specifically:
202
+
203
+ - `info` - Returns the immutable info of the currently running activity
204
+ - `heartbeat(*details)` - Record a heartbeat
205
+ - `cancelled?` - Whether a cancellation has been requested on this activity
206
+ - `shield` - Prevent cancel exception from being thrown during the provided block of code
207
+
208
+ ##### Heartbeating and Cancellation
209
+
210
+ In order for a non-local activity to be notified of cancellation requests, it must call
211
+ `activity.heartbeat`. It is strongly recommended that all but the fastest executing activities call
212
+ this method regularly.
213
+
214
+ In addition to obtaining cancellation information, heartbeats also support detail data that is
215
+ persisted on the server for retrieval during activity retry. If an activity calls
216
+ `activity.heartbeat(123, 456)` and then fails and is retried, `activity.info.heartbeat_details` will
217
+ return an array containing `123` and `456` on the next run.
218
+
219
+ A cancellation is implemented using the `Thread#raise` method, which will raise a
220
+ `Temporal::Error::ActivityCancelled` during the execution of an activity. This means that your code
221
+ might get interrupted at any point and never complete. In order to protect critical parts of your
222
+ activities wrap them in `activity.shield`:
223
+
224
+ ```ruby
225
+ class ActivityWithCriticalLogic < Temporal::Activity
226
+ def execute
227
+ activity.shield do
228
+ run_business_critical_logic_1
229
+ end
230
+
231
+ run_non_critical_logic
232
+
233
+ activity.shield do
234
+ run_business_critical_logic_2
235
+ end
236
+ end
237
+ end
238
+ ```
239
+
240
+ This will ensure that a cancellation request received while inside the `activity.shield` block will
241
+ not raise an exception until that block finishes.
242
+
243
+ In case the entire activity is considered critical, you can mark it as `shielded!` and ignore
244
+ cancellation requests altogether:
245
+
246
+ ```ruby
247
+ class CriticalActivity < Temporal::Activity
248
+ shielded!
249
+
250
+ def execute
251
+ ...
252
+ end
253
+ end
254
+ ```
255
+
256
+ For any long-running activity using this approach it is recommended to periodically check
257
+ `activity.cancelled?` flag and respond accordingly.
258
+
259
+ Please note that your activities can also get cancelled during a worker shutdown process ([if
260
+ configured accordingly](#worker-shutdown)).
261
+
91
262
 
92
263
  ## Dev Setup
93
264
 
data/bridge/Cargo.lock CHANGED
@@ -163,6 +163,12 @@ version = "0.13.1"
163
163
  source = "registry+https://github.com/rust-lang/crates.io-index"
164
164
  checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
165
165
 
166
+ [[package]]
167
+ name = "base64"
168
+ version = "0.20.0"
169
+ source = "registry+https://github.com/rust-lang/crates.io-index"
170
+ checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
171
+
166
172
  [[package]]
167
173
  name = "base64ct"
168
174
  version = "1.5.3"
@@ -197,6 +203,7 @@ dependencies = [
197
203
  "temporal-sdk-core-protos",
198
204
  "thiserror",
199
205
  "tokio",
206
+ "tokio-util",
200
207
  "tonic",
201
208
  "url",
202
209
  ]
@@ -369,7 +376,7 @@ dependencies = [
369
376
  "autocfg",
370
377
  "cfg-if",
371
378
  "crossbeam-utils",
372
- "memoffset",
379
+ "memoffset 0.6.5",
373
380
  "scopeguard",
374
381
  ]
375
382
 
@@ -452,18 +459,18 @@ dependencies = [
452
459
 
453
460
  [[package]]
454
461
  name = "derive_builder"
455
- version = "0.11.2"
462
+ version = "0.12.0"
456
463
  source = "registry+https://github.com/rust-lang/crates.io-index"
457
- checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3"
464
+ checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
458
465
  dependencies = [
459
466
  "derive_builder_macro",
460
467
  ]
461
468
 
462
469
  [[package]]
463
470
  name = "derive_builder_core"
464
- version = "0.11.2"
471
+ version = "0.12.0"
465
472
  source = "registry+https://github.com/rust-lang/crates.io-index"
466
- checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4"
473
+ checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
467
474
  dependencies = [
468
475
  "darling",
469
476
  "proc-macro2",
@@ -473,9 +480,9 @@ dependencies = [
473
480
 
474
481
  [[package]]
475
482
  name = "derive_builder_macro"
476
- version = "0.11.2"
483
+ version = "0.12.0"
477
484
  source = "registry+https://github.com/rust-lang/crates.io-index"
478
- checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68"
485
+ checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
479
486
  dependencies = [
480
487
  "derive_builder_core",
481
488
  "syn",
@@ -1056,6 +1063,15 @@ dependencies = [
1056
1063
  "autocfg",
1057
1064
  ]
1058
1065
 
1066
+ [[package]]
1067
+ name = "memoffset"
1068
+ version = "0.7.1"
1069
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1070
+ checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
1071
+ dependencies = [
1072
+ "autocfg",
1073
+ ]
1074
+
1059
1075
  [[package]]
1060
1076
  name = "mime"
1061
1077
  version = "0.3.16"
@@ -1118,16 +1134,16 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
1118
1134
 
1119
1135
  [[package]]
1120
1136
  name = "nix"
1121
- version = "0.25.0"
1137
+ version = "0.26.1"
1122
1138
  source = "registry+https://github.com/rust-lang/crates.io-index"
1123
- checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
1139
+ checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694"
1124
1140
  dependencies = [
1125
- "autocfg",
1126
1141
  "bitflags",
1127
1142
  "cfg-if",
1128
1143
  "libc",
1129
- "memoffset",
1144
+ "memoffset 0.7.1",
1130
1145
  "pin-utils",
1146
+ "static_assertions",
1131
1147
  ]
1132
1148
 
1133
1149
  [[package]]
@@ -1637,7 +1653,7 @@ version = "0.11.12"
1637
1653
  source = "registry+https://github.com/rust-lang/crates.io-index"
1638
1654
  checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc"
1639
1655
  dependencies = [
1640
- "base64",
1656
+ "base64 0.13.1",
1641
1657
  "bytes",
1642
1658
  "encoding_rs",
1643
1659
  "futures-core",
@@ -1688,11 +1704,11 @@ dependencies = [
1688
1704
 
1689
1705
  [[package]]
1690
1706
  name = "ringbuf"
1691
- version = "0.2.8"
1707
+ version = "0.3.1"
1692
1708
  source = "registry+https://github.com/rust-lang/crates.io-index"
1693
- checksum = "f65af18d50f789e74aaf23bbb3f65dcd22a3cb6e029b5bced149f6bd57c5c2a2"
1709
+ checksum = "89e68dd9c1d8f7bb0c664e1556b1521809bc6fa62d92bb3b813adf8611caa0eb"
1694
1710
  dependencies = [
1695
- "cache-padded",
1711
+ "crossbeam-utils",
1696
1712
  ]
1697
1713
 
1698
1714
  [[package]]
@@ -1757,7 +1773,7 @@ version = "1.0.1"
1757
1773
  source = "registry+https://github.com/rust-lang/crates.io-index"
1758
1774
  checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
1759
1775
  dependencies = [
1760
- "base64",
1776
+ "base64 0.13.1",
1761
1777
  ]
1762
1778
 
1763
1779
  [[package]]
@@ -1960,6 +1976,12 @@ version = "0.5.2"
1960
1976
  source = "registry+https://github.com/rust-lang/crates.io-index"
1961
1977
  checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
1962
1978
 
1979
+ [[package]]
1980
+ name = "static_assertions"
1981
+ version = "1.1.0"
1982
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1983
+ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
1984
+
1963
1985
  [[package]]
1964
1986
  name = "strsim"
1965
1987
  version = "0.10.0"
@@ -2048,7 +2070,7 @@ dependencies = [
2048
2070
  "arc-swap",
2049
2071
  "async-channel",
2050
2072
  "async-trait",
2051
- "base64",
2073
+ "base64 0.20.0",
2052
2074
  "crossbeam",
2053
2075
  "dashmap",
2054
2076
  "derive_builder",
@@ -2105,16 +2127,17 @@ dependencies = [
2105
2127
  name = "temporal-sdk-core-api"
2106
2128
  version = "0.1.0"
2107
2129
  dependencies = [
2108
- "anyhow",
2109
2130
  "async-trait",
2110
2131
  "derive_builder",
2111
- "log",
2112
2132
  "opentelemetry",
2113
2133
  "prost-types",
2134
+ "serde_json",
2114
2135
  "temporal-client",
2115
2136
  "temporal-sdk-core-protos",
2116
2137
  "thiserror",
2117
2138
  "tonic",
2139
+ "tracing-core",
2140
+ "url",
2118
2141
  ]
2119
2142
 
2120
2143
  [[package]]
@@ -2122,7 +2145,7 @@ name = "temporal-sdk-core-protos"
2122
2145
  version = "0.1.0"
2123
2146
  dependencies = [
2124
2147
  "anyhow",
2125
- "base64",
2148
+ "base64 0.20.0",
2126
2149
  "derive_more",
2127
2150
  "prost",
2128
2151
  "prost-types",
@@ -2298,7 +2321,7 @@ dependencies = [
2298
2321
  "async-stream",
2299
2322
  "async-trait",
2300
2323
  "axum",
2301
- "base64",
2324
+ "base64 0.13.1",
2302
2325
  "bytes",
2303
2326
  "futures-core",
2304
2327
  "futures-util",
data/bridge/Cargo.toml CHANGED
@@ -15,6 +15,7 @@ temporal-sdk-core-api = { version = "0.1.0", path = "./sdk-core/core-api" }
15
15
  temporal-sdk-core-protos = { version = "0.1.0", path = "./sdk-core/sdk-core-protos" }
16
16
  thiserror = "1.0.31"
17
17
  tokio = "1.15"
18
+ tokio-util = "0.7.4"
18
19
  tonic = "0.8"
19
20
  url = "2.2"
20
21
 
@@ -1,2 +1,2 @@
1
1
  [workspace]
2
- members = ["bridge-ffi", "core", "client", "core-api", "fsm", "test-utils", "sdk-core-protos", "sdk"]
2
+ members = ["core", "client", "core-api", "fsm", "test-utils", "sdk-core-protos", "sdk"]
@@ -17,7 +17,6 @@ This repo is composed of multiple crates:
17
17
  * temporal-sdk-core-api `./core-api` - Defines the API surface exposed by Core
18
18
  * temporal-sdk-core `./core` - The Core implementation
19
19
  * temporal-sdk `./sdk` - A (currently prototype) Rust SDK built on top of Core. Used for testing.
20
- * temporal-sdk-core-bridge-ffi `./bridge-ffi` - C API wrapper for Core
21
20
  * rustfsm `./fsm` - Implements a procedural macro used by core for defining state machines
22
21
  (contains subcrates). It is temporal agnostic.
23
22
 
@@ -52,9 +51,7 @@ it for a test, insert the below snippet at the start of the test. By default, tr
52
51
  to stdout in a (reasonably) pretty manner.
53
52
 
54
53
  ```rust
55
- crate::telemetry::telemetry_init(Default::default());
56
- let s = info_span!("Test start");
57
- let _enter = s.enter();
54
+ crate::telemetry::test_telem_console();
58
55
  ```
59
56
 
60
57
  The passed in options to initialization can be customized to export to an OTel collector, etc.
@@ -14,7 +14,7 @@ categories = ["development-tools"]
14
14
  anyhow = "1.0"
15
15
  async-trait = "0.1"
16
16
  backoff = "0.4"
17
- derive_builder = "0.11"
17
+ derive_builder = "0.12"
18
18
  derive_more = "0.99"
19
19
  futures = "0.3"
20
20
  futures-retry = "0.6.0"
@@ -46,13 +46,12 @@ use temporal_sdk_core_protos::{
46
46
  coresdk::{workflow_commands::QueryResult, IntoPayloadsExt},
47
47
  grpc::health::v1::health_client::HealthClient,
48
48
  temporal::api::{
49
- command::v1::Command,
50
49
  common::v1::{Header, Payload, Payloads, WorkflowExecution, WorkflowType},
51
50
  enums::v1::{TaskQueueKind, WorkflowIdReusePolicy, WorkflowTaskFailedCause},
52
51
  failure::v1::Failure,
53
52
  operatorservice::v1::operator_service_client::OperatorServiceClient,
54
53
  query::v1::WorkflowQuery,
55
- taskqueue::v1::{StickyExecutionAttributes, TaskQueue},
54
+ taskqueue::v1::TaskQueue,
56
55
  testservice::v1::test_service_client::TestServiceClient,
57
56
  workflowservice::v1::{workflow_service_client::WorkflowServiceClient, *},
58
57
  },
@@ -181,6 +180,17 @@ impl RetryConfig {
181
180
  }
182
181
  }
183
182
 
183
+ pub(crate) const fn throttle_retry_policy() -> Self {
184
+ Self {
185
+ initial_interval: Duration::from_secs(1),
186
+ randomization_factor: 0.2,
187
+ multiplier: 2.0,
188
+ max_interval: Duration::from_secs(10),
189
+ max_elapsed_time: None,
190
+ max_retries: 0,
191
+ }
192
+ }
193
+
184
194
  pub(crate) fn into_exp_backoff<C>(self, clock: C) -> exponential::ExponentialBackoff<C> {
185
195
  exponential::ExponentialBackoff {
186
196
  current_interval: self.initial_interval,
@@ -362,24 +372,6 @@ impl ClientOptions {
362
372
  }
363
373
  }
364
374
 
365
- /// A version of [RespondWorkflowTaskCompletedRequest] that will finish being filled out by the
366
- /// server client
367
- #[derive(Debug, Clone, PartialEq)]
368
- pub struct WorkflowTaskCompletion {
369
- /// The task token that would've been received from polling for a workflow activation
370
- pub task_token: TaskToken,
371
- /// A list of new commands to send to the server, such as starting a timer.
372
- pub commands: Vec<Command>,
373
- /// If set, indicate that next task should be queued on sticky queue with given attributes.
374
- pub sticky_attributes: Option<StickyExecutionAttributes>,
375
- /// Responses to queries in the `queries` field of the workflow task.
376
- pub query_responses: Vec<QueryResult>,
377
- /// Indicate that the task completion should return a new WFT if one is available
378
- pub return_new_workflow_task: bool,
379
- /// Force a new WFT to be created after this completion
380
- pub force_create_new_workflow_task: bool,
381
- }
382
-
383
375
  /// Interceptor which attaches common metadata (like "client-name") to every outgoing call
384
376
  #[derive(Clone)]
385
377
  pub struct ServiceCallInterceptor {
@@ -542,6 +542,15 @@ proxier! {
542
542
  r.extensions_mut().insert(labels);
543
543
  }
544
544
  );
545
+ (
546
+ delete_workflow_execution,
547
+ DeleteWorkflowExecutionRequest,
548
+ DeleteWorkflowExecutionResponse,
549
+ |r| {
550
+ let labels = AttachMetricLabels::namespace(r.get_ref().namespace.clone());
551
+ r.extensions_mut().insert(labels);
552
+ }
553
+ );
545
554
  (
546
555
  list_open_workflow_executions,
547
556
  ListOpenWorkflowExecutionsRequest,
@@ -808,17 +817,9 @@ proxier! {
808
817
  r.extensions_mut().insert(labels);
809
818
  }
810
819
  );
811
- (delete_workflow_execution, DeleteWorkflowExecutionRequest, DeleteWorkflowExecutionResponse,
812
- |r| {
813
- let labels = AttachMetricLabels::namespace(r.get_ref().namespace.clone());
814
- r.extensions_mut().insert(labels);
815
- }
816
- );
817
820
  (add_or_update_remote_cluster, AddOrUpdateRemoteClusterRequest, AddOrUpdateRemoteClusterResponse);
818
821
  (remove_remote_cluster, RemoveRemoteClusterRequest, RemoveRemoteClusterResponse);
819
- (describe_cluster, DescribeClusterRequest, DescribeClusterResponse);
820
822
  (list_clusters, ListClustersRequest, ListClustersResponse);
821
- (list_cluster_members, ListClusterMembersRequest, ListClusterMembersResponse);
822
823
  }
823
824
 
824
825
  proxier! {