temporalio 0.0.1

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 (317) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +20 -0
  4. data/README.md +130 -0
  5. data/bridge/Cargo.lock +2865 -0
  6. data/bridge/Cargo.toml +26 -0
  7. data/bridge/sdk-core/ARCHITECTURE.md +76 -0
  8. data/bridge/sdk-core/Cargo.lock +2606 -0
  9. data/bridge/sdk-core/Cargo.toml +2 -0
  10. data/bridge/sdk-core/LICENSE.txt +23 -0
  11. data/bridge/sdk-core/README.md +107 -0
  12. data/bridge/sdk-core/arch_docs/diagrams/README.md +10 -0
  13. data/bridge/sdk-core/arch_docs/diagrams/sticky_queues.puml +40 -0
  14. data/bridge/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
  15. data/bridge/sdk-core/arch_docs/sticky_queues.md +51 -0
  16. data/bridge/sdk-core/bridge-ffi/Cargo.toml +24 -0
  17. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +23 -0
  18. data/bridge/sdk-core/bridge-ffi/build.rs +25 -0
  19. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +249 -0
  20. data/bridge/sdk-core/bridge-ffi/src/lib.rs +825 -0
  21. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +211 -0
  22. data/bridge/sdk-core/client/Cargo.toml +40 -0
  23. data/bridge/sdk-core/client/LICENSE.txt +23 -0
  24. data/bridge/sdk-core/client/src/lib.rs +1294 -0
  25. data/bridge/sdk-core/client/src/metrics.rs +165 -0
  26. data/bridge/sdk-core/client/src/raw.rs +931 -0
  27. data/bridge/sdk-core/client/src/retry.rs +674 -0
  28. data/bridge/sdk-core/client/src/workflow_handle/mod.rs +185 -0
  29. data/bridge/sdk-core/core/Cargo.toml +116 -0
  30. data/bridge/sdk-core/core/LICENSE.txt +23 -0
  31. data/bridge/sdk-core/core/benches/workflow_replay.rs +73 -0
  32. data/bridge/sdk-core/core/src/abstractions.rs +166 -0
  33. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +911 -0
  34. data/bridge/sdk-core/core/src/core_tests/child_workflows.rs +221 -0
  35. data/bridge/sdk-core/core/src/core_tests/determinism.rs +107 -0
  36. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +515 -0
  37. data/bridge/sdk-core/core/src/core_tests/mod.rs +100 -0
  38. data/bridge/sdk-core/core/src/core_tests/queries.rs +736 -0
  39. data/bridge/sdk-core/core/src/core_tests/replay_flag.rs +65 -0
  40. data/bridge/sdk-core/core/src/core_tests/workers.rs +259 -0
  41. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +124 -0
  42. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +2070 -0
  43. data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +515 -0
  44. data/bridge/sdk-core/core/src/lib.rs +175 -0
  45. data/bridge/sdk-core/core/src/log_export.rs +62 -0
  46. data/bridge/sdk-core/core/src/pollers/mod.rs +54 -0
  47. data/bridge/sdk-core/core/src/pollers/poll_buffer.rs +297 -0
  48. data/bridge/sdk-core/core/src/protosext/mod.rs +428 -0
  49. data/bridge/sdk-core/core/src/replay/mod.rs +71 -0
  50. data/bridge/sdk-core/core/src/retry_logic.rs +202 -0
  51. data/bridge/sdk-core/core/src/telemetry/metrics.rs +383 -0
  52. data/bridge/sdk-core/core/src/telemetry/mod.rs +412 -0
  53. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +77 -0
  54. data/bridge/sdk-core/core/src/test_help/mod.rs +875 -0
  55. data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +580 -0
  56. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +1042 -0
  57. data/bridge/sdk-core/core/src/worker/activities.rs +464 -0
  58. data/bridge/sdk-core/core/src/worker/client/mocks.rs +87 -0
  59. data/bridge/sdk-core/core/src/worker/client.rs +347 -0
  60. data/bridge/sdk-core/core/src/worker/mod.rs +566 -0
  61. data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +37 -0
  62. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +110 -0
  63. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +458 -0
  64. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +911 -0
  65. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +298 -0
  66. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +171 -0
  67. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +860 -0
  68. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +140 -0
  69. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +161 -0
  70. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +133 -0
  71. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +1448 -0
  72. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +342 -0
  73. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +127 -0
  74. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +712 -0
  75. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +71 -0
  76. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +443 -0
  77. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +439 -0
  78. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +169 -0
  79. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +246 -0
  80. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +96 -0
  81. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +1184 -0
  82. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +277 -0
  83. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
  84. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +647 -0
  85. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +1143 -0
  86. data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +145 -0
  87. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
  88. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +940 -0
  89. data/bridge/sdk-core/core-api/Cargo.toml +31 -0
  90. data/bridge/sdk-core/core-api/LICENSE.txt +23 -0
  91. data/bridge/sdk-core/core-api/src/errors.rs +95 -0
  92. data/bridge/sdk-core/core-api/src/lib.rs +151 -0
  93. data/bridge/sdk-core/core-api/src/worker.rs +135 -0
  94. data/bridge/sdk-core/etc/deps.svg +187 -0
  95. data/bridge/sdk-core/etc/dynamic-config.yaml +2 -0
  96. data/bridge/sdk-core/etc/otel-collector-config.yaml +36 -0
  97. data/bridge/sdk-core/etc/prometheus.yaml +6 -0
  98. data/bridge/sdk-core/fsm/Cargo.toml +18 -0
  99. data/bridge/sdk-core/fsm/LICENSE.txt +23 -0
  100. data/bridge/sdk-core/fsm/README.md +3 -0
  101. data/bridge/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +27 -0
  102. data/bridge/sdk-core/fsm/rustfsm_procmacro/LICENSE.txt +23 -0
  103. data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +647 -0
  104. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/progress.rs +8 -0
  105. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.rs +18 -0
  106. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +12 -0
  107. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dynamic_dest_pass.rs +41 -0
  108. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.rs +14 -0
  109. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.stderr +11 -0
  110. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_arg_pass.rs +32 -0
  111. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_pass.rs +31 -0
  112. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/medium_complex_pass.rs +46 -0
  113. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.rs +29 -0
  114. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +12 -0
  115. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/simple_pass.rs +32 -0
  116. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.rs +18 -0
  117. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.stderr +5 -0
  118. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.rs +11 -0
  119. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.stderr +5 -0
  120. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.rs +11 -0
  121. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.stderr +5 -0
  122. data/bridge/sdk-core/fsm/rustfsm_trait/Cargo.toml +14 -0
  123. data/bridge/sdk-core/fsm/rustfsm_trait/LICENSE.txt +23 -0
  124. data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +249 -0
  125. data/bridge/sdk-core/fsm/src/lib.rs +2 -0
  126. data/bridge/sdk-core/histories/fail_wf_task.bin +0 -0
  127. data/bridge/sdk-core/histories/timer_workflow_history.bin +0 -0
  128. data/bridge/sdk-core/integ-with-otel.sh +7 -0
  129. data/bridge/sdk-core/protos/api_upstream/README.md +9 -0
  130. data/bridge/sdk-core/protos/api_upstream/api-linter.yaml +40 -0
  131. data/bridge/sdk-core/protos/api_upstream/buf.yaml +12 -0
  132. data/bridge/sdk-core/protos/api_upstream/dependencies/gogoproto/gogo.proto +141 -0
  133. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +86 -0
  134. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +83 -0
  135. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +259 -0
  136. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +112 -0
  137. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +46 -0
  138. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +40 -0
  139. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +57 -0
  140. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +55 -0
  141. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +168 -0
  142. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +97 -0
  143. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +51 -0
  144. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +50 -0
  145. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +41 -0
  146. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
  147. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +59 -0
  148. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +51 -0
  149. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +122 -0
  150. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +108 -0
  151. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +114 -0
  152. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +56 -0
  153. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +751 -0
  154. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +97 -0
  155. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +161 -0
  156. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +99 -0
  157. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +61 -0
  158. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +55 -0
  159. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +300 -0
  160. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +108 -0
  161. data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +46 -0
  162. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +59 -0
  163. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +145 -0
  164. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +1124 -0
  165. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +401 -0
  166. data/bridge/sdk-core/protos/grpc/health/v1/health.proto +63 -0
  167. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
  168. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +79 -0
  169. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +210 -0
  170. data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +77 -0
  171. data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +15 -0
  172. data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +30 -0
  173. data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
  174. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +261 -0
  175. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +297 -0
  176. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +29 -0
  177. data/bridge/sdk-core/protos/testsrv_upstream/api-linter.yaml +38 -0
  178. data/bridge/sdk-core/protos/testsrv_upstream/buf.yaml +13 -0
  179. data/bridge/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +141 -0
  180. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +63 -0
  181. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +90 -0
  182. data/bridge/sdk-core/rustfmt.toml +1 -0
  183. data/bridge/sdk-core/sdk/Cargo.toml +47 -0
  184. data/bridge/sdk-core/sdk/LICENSE.txt +23 -0
  185. data/bridge/sdk-core/sdk/src/activity_context.rs +230 -0
  186. data/bridge/sdk-core/sdk/src/app_data.rs +37 -0
  187. data/bridge/sdk-core/sdk/src/conversions.rs +8 -0
  188. data/bridge/sdk-core/sdk/src/interceptors.rs +17 -0
  189. data/bridge/sdk-core/sdk/src/lib.rs +792 -0
  190. data/bridge/sdk-core/sdk/src/payload_converter.rs +11 -0
  191. data/bridge/sdk-core/sdk/src/workflow_context/options.rs +295 -0
  192. data/bridge/sdk-core/sdk/src/workflow_context.rs +683 -0
  193. data/bridge/sdk-core/sdk/src/workflow_future.rs +503 -0
  194. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +30 -0
  195. data/bridge/sdk-core/sdk-core-protos/LICENSE.txt +23 -0
  196. data/bridge/sdk-core/sdk-core-protos/build.rs +108 -0
  197. data/bridge/sdk-core/sdk-core-protos/src/constants.rs +7 -0
  198. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +497 -0
  199. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +230 -0
  200. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +1910 -0
  201. data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
  202. data/bridge/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  203. data/bridge/sdk-core/test-utils/Cargo.toml +35 -0
  204. data/bridge/sdk-core/test-utils/src/canned_histories.rs +1579 -0
  205. data/bridge/sdk-core/test-utils/src/histfetch.rs +28 -0
  206. data/bridge/sdk-core/test-utils/src/lib.rs +598 -0
  207. data/bridge/sdk-core/tests/integ_tests/client_tests.rs +36 -0
  208. data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +128 -0
  209. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +218 -0
  210. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +146 -0
  211. data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +437 -0
  212. data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +93 -0
  213. data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +878 -0
  214. data/bridge/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
  215. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +59 -0
  216. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +58 -0
  217. data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +50 -0
  218. data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +60 -0
  219. data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +54 -0
  220. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +634 -0
  221. data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +113 -0
  222. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +137 -0
  223. data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +93 -0
  224. data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +167 -0
  225. data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +99 -0
  226. data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +131 -0
  227. data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +75 -0
  228. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +587 -0
  229. data/bridge/sdk-core/tests/load_tests.rs +191 -0
  230. data/bridge/sdk-core/tests/main.rs +111 -0
  231. data/bridge/sdk-core/tests/runner.rs +93 -0
  232. data/bridge/src/connection.rs +167 -0
  233. data/bridge/src/lib.rs +180 -0
  234. data/bridge/src/runtime.rs +47 -0
  235. data/bridge/src/worker.rs +73 -0
  236. data/ext/Rakefile +9 -0
  237. data/lib/bridge.so +0 -0
  238. data/lib/gen/dependencies/gogoproto/gogo_pb.rb +14 -0
  239. data/lib/gen/temporal/api/batch/v1/message_pb.rb +48 -0
  240. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +67 -0
  241. data/lib/gen/temporal/api/command/v1/message_pb.rb +166 -0
  242. data/lib/gen/temporal/api/common/v1/message_pb.rb +69 -0
  243. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +32 -0
  244. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +26 -0
  245. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +37 -0
  246. data/lib/gen/temporal/api/enums/v1/common_pb.rb +41 -0
  247. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +67 -0
  248. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +71 -0
  249. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +37 -0
  250. data/lib/gen/temporal/api/enums/v1/query_pb.rb +31 -0
  251. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +24 -0
  252. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +28 -0
  253. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +30 -0
  254. data/lib/gen/temporal/api/enums/v1/update_pb.rb +28 -0
  255. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +89 -0
  256. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +84 -0
  257. data/lib/gen/temporal/api/failure/v1/message_pb.rb +83 -0
  258. data/lib/gen/temporal/api/filter/v1/message_pb.rb +40 -0
  259. data/lib/gen/temporal/api/history/v1/message_pb.rb +489 -0
  260. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +63 -0
  261. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +125 -0
  262. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +20 -0
  263. data/lib/gen/temporal/api/query/v1/message_pb.rb +38 -0
  264. data/lib/gen/temporal/api/replication/v1/message_pb.rb +37 -0
  265. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +128 -0
  266. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +73 -0
  267. data/lib/gen/temporal/api/update/v1/message_pb.rb +26 -0
  268. data/lib/gen/temporal/api/version/v1/message_pb.rb +41 -0
  269. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +110 -0
  270. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +771 -0
  271. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +20 -0
  272. data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +58 -0
  273. data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +57 -0
  274. data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +222 -0
  275. data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +57 -0
  276. data/lib/gen/temporal/sdk/core/common/common_pb.rb +22 -0
  277. data/lib/gen/temporal/sdk/core/core_interface_pb.rb +34 -0
  278. data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +27 -0
  279. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +164 -0
  280. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +192 -0
  281. data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +34 -0
  282. data/lib/temporal/bridge.rb +14 -0
  283. data/lib/temporal/client/implementation.rb +339 -0
  284. data/lib/temporal/client/workflow_handle.rb +243 -0
  285. data/lib/temporal/client.rb +144 -0
  286. data/lib/temporal/connection.rb +736 -0
  287. data/lib/temporal/data_converter.rb +150 -0
  288. data/lib/temporal/error/failure.rb +194 -0
  289. data/lib/temporal/error/workflow_failure.rb +17 -0
  290. data/lib/temporal/errors.rb +22 -0
  291. data/lib/temporal/failure_converter/base.rb +26 -0
  292. data/lib/temporal/failure_converter/basic.rb +313 -0
  293. data/lib/temporal/failure_converter.rb +8 -0
  294. data/lib/temporal/interceptor/chain.rb +27 -0
  295. data/lib/temporal/interceptor/client.rb +102 -0
  296. data/lib/temporal/payload_codec/base.rb +32 -0
  297. data/lib/temporal/payload_converter/base.rb +24 -0
  298. data/lib/temporal/payload_converter/bytes.rb +26 -0
  299. data/lib/temporal/payload_converter/composite.rb +47 -0
  300. data/lib/temporal/payload_converter/encoding_base.rb +35 -0
  301. data/lib/temporal/payload_converter/json.rb +25 -0
  302. data/lib/temporal/payload_converter/nil.rb +25 -0
  303. data/lib/temporal/payload_converter.rb +14 -0
  304. data/lib/temporal/retry_policy.rb +82 -0
  305. data/lib/temporal/retry_state.rb +35 -0
  306. data/lib/temporal/runtime.rb +22 -0
  307. data/lib/temporal/timeout_type.rb +29 -0
  308. data/lib/temporal/version.rb +3 -0
  309. data/lib/temporal/workflow/execution_info.rb +54 -0
  310. data/lib/temporal/workflow/execution_status.rb +36 -0
  311. data/lib/temporal/workflow/id_reuse_policy.rb +36 -0
  312. data/lib/temporal/workflow/query_reject_condition.rb +33 -0
  313. data/lib/temporal.rb +8 -0
  314. data/lib/temporalio.rb +3 -0
  315. data/lib/thermite_patch.rb +23 -0
  316. data/temporalio.gemspec +41 -0
  317. metadata +583 -0
@@ -0,0 +1,313 @@
1
+ require 'temporal/api/common/v1/message_pb'
2
+ require 'temporal/api/failure/v1/message_pb'
3
+ require 'temporal/error/failure'
4
+ require 'temporal/failure_converter/base'
5
+ require 'temporal/retry_state'
6
+ require 'temporal/timeout_type'
7
+
8
+ module Temporal
9
+ module FailureConverter
10
+ class Basic < Base
11
+ def initialize(encode_common_attributes: false)
12
+ super()
13
+
14
+ @encode_common_attributes = encode_common_attributes
15
+ end
16
+
17
+ def to_failure(error, payload_converter)
18
+ return error.raw if error.is_a?(Temporal::Error::Failure) && error.raw
19
+
20
+ failure =
21
+ case error
22
+ when Temporal::Error::ApplicationError
23
+ to_application_failure(error, payload_converter)
24
+ when Temporal::Error::TimeoutError
25
+ to_timeout_failure(error, payload_converter)
26
+ when Temporal::Error::CancelledError
27
+ to_cancelled_failure(error, payload_converter)
28
+ when Temporal::Error::TerminatedError
29
+ to_terminated_failure(error, payload_converter)
30
+ when Temporal::Error::ServerError
31
+ to_server_failure(error, payload_converter)
32
+ when Temporal::Error::ResetWorkflowError
33
+ to_reset_workflow_failure(error, payload_converter)
34
+ when Temporal::Error::ActivityError
35
+ to_activity_failure(error, payload_converter)
36
+ when Temporal::Error::ChildWorkflowError
37
+ to_child_workflow_execution_failure(error, payload_converter)
38
+ else
39
+ to_generic_failure(error, payload_converter)
40
+ end
41
+
42
+ failure.message = error.message
43
+ failure.stack_trace = error.backtrace&.join("\n") || ''
44
+ failure.cause = to_failure(error.cause, payload_converter) if error.cause
45
+
46
+ if encode_common_attributes?
47
+ failure.encoded_attributes = payload_converter.to_payload(
48
+ 'message' => failure.message,
49
+ 'stack_trace' => failure.stack_trace,
50
+ )
51
+ failure.message = 'Encoded failure'
52
+ failure.stack_trace = ''
53
+ end
54
+
55
+ failure
56
+ end
57
+
58
+ def from_failure(failure, payload_converter)
59
+ failure = apply_from_encoded_attributes(failure, payload_converter)
60
+ cause = failure.cause ? from_failure(failure.cause, payload_converter) : nil
61
+
62
+ error =
63
+ if failure.application_failure_info
64
+ from_application_failure(failure, failure.application_failure_info, cause, payload_converter)
65
+ elsif failure.timeout_failure_info
66
+ from_timeout_failure(failure, failure.timeout_failure_info, cause, payload_converter)
67
+ elsif failure.canceled_failure_info
68
+ from_cancelled_failure(failure, failure.canceled_failure_info, cause, payload_converter)
69
+ elsif failure.terminated_failure_info
70
+ from_terminated_failure(failure, failure.terminated_failure_info, cause, payload_converter)
71
+ elsif failure.server_failure_info
72
+ from_server_failure(failure, failure.server_failure_info, cause, payload_converter)
73
+ elsif failure.reset_workflow_failure_info
74
+ from_reset_workflow_failure(failure, failure.reset_workflow_failure_info, cause, payload_converter)
75
+ elsif failure.activity_failure_info
76
+ from_activity_failure(failure, failure.activity_failure_info, cause, payload_converter)
77
+ elsif failure.child_workflow_execution_failure_info
78
+ from_child_workflow_execution_failure(
79
+ failure,
80
+ failure.child_workflow_execution_failure_info,
81
+ cause,
82
+ payload_converter,
83
+ )
84
+ else
85
+ from_generic_failure(failure, cause, payload_converter)
86
+ end
87
+
88
+ unless failure.stack_trace.empty?
89
+ error.set_backtrace(failure.stack_trace.split("\n"))
90
+ end
91
+
92
+ error
93
+ end
94
+
95
+ private
96
+
97
+ def encode_common_attributes?
98
+ @encode_common_attributes
99
+ end
100
+
101
+ def to_payloads(data, payload_converter)
102
+ return if data.nil? || Array(data).empty?
103
+
104
+ payloads = Array(data).map { |value| payload_converter.to_payload(value) }
105
+ Temporal::Api::Common::V1::Payloads.new(payloads: payloads)
106
+ end
107
+
108
+ def from_payloads(payloads, payload_converter)
109
+ return [] unless payloads
110
+
111
+ payloads.payloads.map { |payload| payload_converter.from_payload(payload) }
112
+ end
113
+
114
+ def apply_from_encoded_attributes(failure, payload_converter)
115
+ return failure unless failure.encoded_attributes
116
+
117
+ attributes = payload_converter.from_payload(failure.encoded_attributes)
118
+ return failure unless attributes.is_a?(Hash)
119
+
120
+ failure = failure.dup
121
+ if attributes['message'].is_a?(String)
122
+ failure.message = attributes['message']
123
+ end
124
+
125
+ if attributes['stack_trace'].is_a?(String)
126
+ failure.stack_trace = attributes['stack_trace']
127
+ end
128
+
129
+ failure
130
+ end
131
+
132
+ def to_application_failure(error, payload_converter)
133
+ Temporal::Api::Failure::V1::Failure.new(
134
+ application_failure_info: Temporal::Api::Failure::V1::ApplicationFailureInfo.new(
135
+ type: error.type,
136
+ non_retryable: error.non_retryable,
137
+ details: to_payloads(error.details, payload_converter),
138
+ ),
139
+ )
140
+ end
141
+
142
+ def to_timeout_failure(error, payload_converter)
143
+ Temporal::Api::Failure::V1::Failure.new(
144
+ timeout_failure_info: Temporal::Api::Failure::V1::TimeoutFailureInfo.new(
145
+ timeout_type: Temporal::TimeoutType.to_raw(error.type),
146
+ last_heartbeat_details: to_payloads(error.last_heartbeat_details, payload_converter),
147
+ ),
148
+ )
149
+ end
150
+
151
+ def to_cancelled_failure(error, payload_converter)
152
+ Temporal::Api::Failure::V1::Failure.new(
153
+ canceled_failure_info: Temporal::Api::Failure::V1::CanceledFailureInfo.new(
154
+ details: to_payloads(error.details, payload_converter),
155
+ ),
156
+ )
157
+ end
158
+
159
+ def to_terminated_failure(_error, _payload_converter)
160
+ Temporal::Api::Failure::V1::Failure.new(
161
+ terminated_failure_info: Temporal::Api::Failure::V1::TerminatedFailureInfo.new,
162
+ )
163
+ end
164
+
165
+ def to_server_failure(error, _payload_converter)
166
+ Temporal::Api::Failure::V1::Failure.new(
167
+ server_failure_info: Temporal::Api::Failure::V1::ServerFailureInfo.new(
168
+ non_retryable: error.non_retryable,
169
+ ),
170
+ )
171
+ end
172
+
173
+ def to_reset_workflow_failure(error, payload_converter)
174
+ Temporal::Api::Failure::V1::Failure.new(
175
+ reset_workflow_failure_info: Temporal::Api::Failure::V1::ResetWorkflowFailureInfo.new(
176
+ last_heartbeat_details: to_payloads(error.last_heartbeat_details, payload_converter),
177
+ ),
178
+ )
179
+ end
180
+
181
+ def to_activity_failure(error, _payload_converter)
182
+ Temporal::Api::Failure::V1::Failure.new(
183
+ activity_failure_info: Temporal::Api::Failure::V1::ActivityFailureInfo.new(
184
+ scheduled_event_id: error.scheduled_event_id,
185
+ started_event_id: error.started_event_id,
186
+ identity: error.identity,
187
+ activity_type: Temporal::Api::Common::V1::ActivityType.new(name: error.activity_name || ''),
188
+ activity_id: error.activity_id,
189
+ retry_state: Temporal::RetryState.to_raw(error.retry_state),
190
+ ),
191
+ )
192
+ end
193
+
194
+ def to_child_workflow_execution_failure(error, _payload_converter)
195
+ Temporal::Api::Failure::V1::Failure.new(
196
+ child_workflow_execution_failure_info:
197
+ Temporal::Api::Failure::V1::ChildWorkflowExecutionFailureInfo.new(
198
+ namespace: error.namespace,
199
+ workflow_execution: Temporal::Api::Common::V1::WorkflowExecution.new(
200
+ workflow_id: error.workflow_id || '',
201
+ run_id: error.run_id || '',
202
+ ),
203
+ workflow_type: Temporal::Api::Common::V1::WorkflowType.new(name: error.workflow_name || ''),
204
+ initiated_event_id: error.initiated_event_id,
205
+ started_event_id: error.started_event_id,
206
+ retry_state: Temporal::RetryState.to_raw(error.retry_state),
207
+ ),
208
+ )
209
+ end
210
+
211
+ def to_generic_failure(error, _payload_converter)
212
+ Temporal::Api::Failure::V1::Failure.new(
213
+ application_failure_info: Temporal::Api::Failure::V1::ApplicationFailureInfo.new(
214
+ type: error.class.name,
215
+ ),
216
+ )
217
+ end
218
+
219
+ def from_application_failure(failure, failure_info, cause, payload_converter)
220
+ Temporal::Error::ApplicationError.new(
221
+ failure.message || 'Application error',
222
+ type: failure_info.type,
223
+ details: from_payloads(failure_info.details, payload_converter),
224
+ non_retryable: failure_info.non_retryable,
225
+ raw: failure,
226
+ cause: cause,
227
+ )
228
+ end
229
+
230
+ def from_timeout_failure(failure, failure_info, cause, payload_converter)
231
+ Temporal::Error::TimeoutError.new(
232
+ failure.message || 'Timeout',
233
+ type: Temporal::TimeoutType.from_raw(failure_info.timeout_type),
234
+ last_heartbeat_details: from_payloads(failure_info.last_heartbeat_details, payload_converter),
235
+ raw: failure,
236
+ cause: cause,
237
+ )
238
+ end
239
+
240
+ def from_cancelled_failure(failure, failure_info, cause, payload_converter)
241
+ Temporal::Error::CancelledError.new(
242
+ failure.message || 'Cancelled',
243
+ details: from_payloads(failure_info.details, payload_converter),
244
+ raw: failure,
245
+ cause: cause,
246
+ )
247
+ end
248
+
249
+ def from_terminated_failure(failure, _failure_info, cause, _payload_converter)
250
+ Temporal::Error::TerminatedError.new(
251
+ failure.message || 'Terminated',
252
+ raw: failure,
253
+ cause: cause,
254
+ )
255
+ end
256
+
257
+ def from_server_failure(failure, failure_info, cause, _payload_converter)
258
+ Temporal::Error::ServerError.new(
259
+ failure.message || 'Server error',
260
+ non_retryable: failure_info.non_retryable,
261
+ raw: failure,
262
+ cause: cause,
263
+ )
264
+ end
265
+
266
+ def from_reset_workflow_failure(failure, failure_info, cause, payload_converter)
267
+ Temporal::Error::ResetWorkflowError.new(
268
+ failure.message || 'Reset workflow error',
269
+ last_heartbeat_details: from_payloads(failure_info.last_heartbeat_details, payload_converter),
270
+ raw: failure,
271
+ cause: cause,
272
+ )
273
+ end
274
+
275
+ def from_activity_failure(failure, failure_info, cause, _payload_converter)
276
+ Temporal::Error::ActivityError.new(
277
+ failure.message || 'Activity error',
278
+ scheduled_event_id: failure_info.scheduled_event_id,
279
+ started_event_id: failure_info.started_event_id,
280
+ identity: failure_info.identity,
281
+ activity_name: failure_info.activity_type&.name,
282
+ activity_id: failure_info.activity_id,
283
+ retry_state: Temporal::RetryState.from_raw(failure_info.retry_state),
284
+ raw: failure,
285
+ cause: cause,
286
+ )
287
+ end
288
+
289
+ def from_child_workflow_execution_failure(failure, failure_info, cause, _payload_converter)
290
+ Temporal::Error::ChildWorkflowError.new(
291
+ failure.message || 'Child workflow error',
292
+ namespace: failure_info.namespace,
293
+ workflow_id: failure_info.workflow_execution&.workflow_id,
294
+ run_id: failure_info.workflow_execution&.run_id,
295
+ workflow_name: failure_info.workflow_type&.name,
296
+ initiated_event_id: failure_info.initiated_event_id,
297
+ started_event_id: failure_info.started_event_id,
298
+ retry_state: Temporal::RetryState.from_raw(failure_info.retry_state),
299
+ raw: failure,
300
+ cause: cause,
301
+ )
302
+ end
303
+
304
+ def from_generic_failure(failure, cause, _payload_converter)
305
+ Temporal::Error::Failure.new(
306
+ failure.message || 'Failure error',
307
+ raw: failure,
308
+ cause: cause,
309
+ )
310
+ end
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,8 @@
1
+ require 'temporal/failure_converter/basic'
2
+ require 'temporal/payload_converter'
3
+
4
+ module Temporal
5
+ module FailureConverter
6
+ DEFAULT = Temporal::FailureConverter::Basic.new
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ module Temporal
2
+ module Interceptor
3
+ class Chain
4
+ def initialize(interceptors = [])
5
+ @interceptors = interceptors
6
+ end
7
+
8
+ def invoke(method, input)
9
+ chain = interceptors.dup
10
+
11
+ traverse_chain = lambda do |i|
12
+ if chain.empty?
13
+ yield(i)
14
+ else
15
+ chain.shift.public_send(method, i, &traverse_chain)
16
+ end
17
+ end
18
+
19
+ traverse_chain.call(input)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :interceptors
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,102 @@
1
+ module Temporal
2
+ module Interceptor
3
+ class Client
4
+ class StartWorkflowInput < Struct.new(
5
+ :workflow,
6
+ :args,
7
+ :id,
8
+ :task_queue,
9
+ :execution_timeout,
10
+ :run_timeout,
11
+ :task_timeout,
12
+ :id_reuse_policy,
13
+ :retry_policy,
14
+ :cron_schedule,
15
+ :memo,
16
+ :search_attributes,
17
+ :headers,
18
+ :start_signal,
19
+ :start_signal_args,
20
+ :rpc_metadata,
21
+ :rpc_timeout,
22
+ keyword_init: true,
23
+ ); end
24
+
25
+ class DescribeWorkflowInput < Struct.new(
26
+ :id,
27
+ :run_id,
28
+ :rpc_metadata,
29
+ :rpc_timeout,
30
+ keyword_init: true,
31
+ ); end
32
+
33
+ class QueryWorkflowInput < Struct.new(
34
+ :id,
35
+ :run_id,
36
+ :query,
37
+ :args,
38
+ :reject_condition,
39
+ :headers,
40
+ :rpc_metadata,
41
+ :rpc_timeout,
42
+ keyword_init: true,
43
+ ); end
44
+
45
+ class SignalWorkflowInput < Struct.new(
46
+ :id,
47
+ :run_id,
48
+ :signal,
49
+ :args,
50
+ :headers,
51
+ :rpc_metadata,
52
+ :rpc_timeout,
53
+ keyword_init: true,
54
+ ); end
55
+
56
+ class CancelWorkflowInput < Struct.new(
57
+ :id,
58
+ :run_id,
59
+ :first_execution_run_id,
60
+ :reason,
61
+ :rpc_metadata,
62
+ :rpc_timeout,
63
+ keyword_init: true,
64
+ ); end
65
+
66
+ class TerminateWorkflowInput < Struct.new(
67
+ :id,
68
+ :run_id,
69
+ :first_execution_run_id,
70
+ :reason,
71
+ :args,
72
+ :rpc_metadata,
73
+ :rpc_timeout,
74
+ keyword_init: true,
75
+ ); end
76
+
77
+ def start_workflow(input)
78
+ yield(input)
79
+ end
80
+
81
+ def describe_workflow(input)
82
+ yield(input)
83
+ end
84
+
85
+ def query_workflow(input)
86
+ yield(input)
87
+ end
88
+
89
+ def signal_workflow(input)
90
+ yield(input)
91
+ end
92
+
93
+ def cancel_workflow(input)
94
+ yield(input)
95
+ end
96
+
97
+ def terminate_workflow(input)
98
+ yield(input)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,32 @@
1
+ module Temporal
2
+ module PayloadCodec
3
+ # @abstract Use this Interface for implementing your payload codecs.
4
+ #
5
+ # Codec for encoding/decoding to/from bytes. Commonly used for compression or encryption.
6
+ class Base
7
+ # Encode the given payloads.
8
+ #
9
+ # @param _payloads [Array<Temporal::Api::Common::V1::Payload>] Payloads to encode.
10
+ # This value should not be mutated.
11
+ #
12
+ # @return [Array<Temporal::Api::Common::V1::Payload>] Encoded payloads. Note, this does not
13
+ # have to be the same number as payloads given, but must be at least one and cannot be more
14
+ # than was given.
15
+ def encode(_payloads)
16
+ raise NoMethodError, 'must implement #encode'
17
+ end
18
+
19
+ # Decode the given payloads.
20
+ #
21
+ # @param _payloads [Array<Temporal::Api::Common::V1::Payload>] Payloads to decode. This value
22
+ # should not be mutated.
23
+ #
24
+ # @return [Array<Temporal::Api::Common::V1::Payload>] Decoded payloads. Note, this does not
25
+ # have to be the same number as payloads given, but must be at least one and cannot be more
26
+ # than was given.
27
+ def decode(_payloads)
28
+ raise NoMethodError, 'must implement #decode'
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ module Temporal
2
+ module PayloadConverter
3
+ # @abstract Use this Interface for implementing your payload converter.
4
+ class Base
5
+ # Convert a Ruby value to a proto Payload.
6
+ #
7
+ # @param _data [any] Ruby value to be converted.
8
+ #
9
+ # @return [Temporal::Api::Common::V1::Payload]
10
+ def to_payload(_data)
11
+ raise NoMethodError, 'must implement #to_payload'
12
+ end
13
+
14
+ # Convert a proto Payload to a Ruby value.
15
+ #
16
+ # @param _payload [Temporal::Api::Common::V1::Payload] Proto Payload to be converted.
17
+ #
18
+ # @return [any]
19
+ def from_payload(_payload)
20
+ raise NoMethodError, 'must implement #from_payload'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'temporal/payload_converter/encoding_base'
2
+
3
+ module Temporal
4
+ module PayloadConverter
5
+ class Bytes < EncodingBase
6
+ ENCODING = 'binary/plain'.freeze
7
+
8
+ def encoding
9
+ ENCODING
10
+ end
11
+
12
+ def from_payload(payload)
13
+ payload.data
14
+ end
15
+
16
+ def to_payload(data)
17
+ return nil unless data.is_a?(String) && data.encoding == Encoding::ASCII_8BIT
18
+
19
+ Temporal::Api::Common::V1::Payload.new(
20
+ metadata: { 'encoding' => ENCODING },
21
+ data: data,
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
1
+ require 'temporal/payload_converter/base'
2
+ require 'temporal/errors'
3
+
4
+ module Temporal
5
+ module PayloadConverter
6
+ class Composite < Base
7
+ class ConverterNotFound < Temporal::Error; end
8
+ class EncodingNotSet < Temporal::Error; end
9
+
10
+ def initialize(*converters)
11
+ super()
12
+
13
+ @converters = converters.each_with_object({}) do |converter, result|
14
+ result[converter.encoding] = converter
15
+ result
16
+ end
17
+ end
18
+
19
+ def to_payload(data)
20
+ converters.each_value do |converter|
21
+ payload = converter.to_payload(data)
22
+ return payload unless payload.nil?
23
+ end
24
+
25
+ available = converters.values.map(&:class).join(', ')
26
+ raise ConverterNotFound, "Available converters (#{available}) could not convert data"
27
+ end
28
+
29
+ def from_payload(payload)
30
+ encoding = payload.metadata['encoding']
31
+ raise EncodingNotSet, 'Missing payload encoding' unless encoding
32
+
33
+ converter = converters[encoding]
34
+ unless converter
35
+ available = converters.keys.join(', ')
36
+ raise ConverterNotFound, "Missing converter for encoding '#{encoding}' (available: #{available})"
37
+ end
38
+
39
+ converter.from_payload(payload)
40
+ end
41
+
42
+ private
43
+
44
+ attr_reader :converters
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ require 'temporal/api/common/v1/message_pb'
2
+
3
+ module Temporal
4
+ module PayloadConverter
5
+ # @abstract Use this Interface for implementing an encoding payload converter.
6
+ # This is used as a converter for the {Temporal::PayloadConverter::Composite}.
7
+ class EncodingBase
8
+ # A mime-type for the converter's encoding.
9
+ #
10
+ # @return [String]
11
+ def encoding
12
+ raise NoMethodError, 'must implement #encoding'
13
+ end
14
+
15
+ # Convert a Ruby value to a proto Payload.
16
+ #
17
+ # @param _data [any] Ruby value to be converted.
18
+ #
19
+ # @return [Temporal::Api::Common::V1::Payload, nil] Return `nil` if the received value is not
20
+ # supported by this converter.
21
+ def to_payload(_data)
22
+ raise NoMethodError, 'must implement #to_payload'
23
+ end
24
+
25
+ # Convert a proto Payload to a Ruby value.
26
+ #
27
+ # @param _payload [Temporal::Api::Common::V1::Payload] Proto Payload to be converted.
28
+ #
29
+ # @return [any]
30
+ def from_payload(_payload)
31
+ raise NoMethodError, 'must implement #from_payload'
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'json/ext'
2
+ require 'temporal/payload_converter/encoding_base'
3
+
4
+ module Temporal
5
+ module PayloadConverter
6
+ class JSON < EncodingBase
7
+ ENCODING = 'json/plain'.freeze
8
+
9
+ def encoding
10
+ ENCODING
11
+ end
12
+
13
+ def from_payload(payload)
14
+ ::JSON.parse(payload.data, create_additions: true)
15
+ end
16
+
17
+ def to_payload(data)
18
+ Temporal::Api::Common::V1::Payload.new(
19
+ metadata: { 'encoding' => ENCODING },
20
+ data: ::JSON.generate(data).b,
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'temporal/payload_converter/encoding_base'
2
+
3
+ module Temporal
4
+ module PayloadConverter
5
+ class Nil < EncodingBase
6
+ ENCODING = 'binary/null'.freeze
7
+
8
+ def encoding
9
+ ENCODING
10
+ end
11
+
12
+ def from_payload(_payload)
13
+ nil
14
+ end
15
+
16
+ def to_payload(data)
17
+ return nil unless data.nil?
18
+
19
+ Temporal::Api::Common::V1::Payload.new(
20
+ metadata: { 'encoding' => ENCODING },
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'temporal/payload_converter/bytes'
2
+ require 'temporal/payload_converter/composite'
3
+ require 'temporal/payload_converter/json'
4
+ require 'temporal/payload_converter/nil'
5
+
6
+ module Temporal
7
+ module PayloadConverter
8
+ DEFAULT = Temporal::PayloadConverter::Composite.new(
9
+ Temporal::PayloadConverter::Nil.new,
10
+ Temporal::PayloadConverter::Bytes.new,
11
+ Temporal::PayloadConverter::JSON.new,
12
+ )
13
+ end
14
+ end