temporalio 0.0.0 → 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 (327) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +301 -0
  3. data/bridge/Cargo.lock +2888 -0
  4. data/bridge/Cargo.toml +27 -0
  5. data/bridge/sdk-core/ARCHITECTURE.md +76 -0
  6. data/bridge/sdk-core/Cargo.lock +2606 -0
  7. data/bridge/sdk-core/Cargo.toml +2 -0
  8. data/bridge/sdk-core/LICENSE.txt +23 -0
  9. data/bridge/sdk-core/README.md +104 -0
  10. data/bridge/sdk-core/arch_docs/diagrams/README.md +10 -0
  11. data/bridge/sdk-core/arch_docs/diagrams/sticky_queues.puml +40 -0
  12. data/bridge/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
  13. data/bridge/sdk-core/arch_docs/sticky_queues.md +51 -0
  14. data/bridge/sdk-core/client/Cargo.toml +40 -0
  15. data/bridge/sdk-core/client/LICENSE.txt +23 -0
  16. data/bridge/sdk-core/client/src/lib.rs +1286 -0
  17. data/bridge/sdk-core/client/src/metrics.rs +165 -0
  18. data/bridge/sdk-core/client/src/raw.rs +932 -0
  19. data/bridge/sdk-core/client/src/retry.rs +751 -0
  20. data/bridge/sdk-core/client/src/workflow_handle/mod.rs +185 -0
  21. data/bridge/sdk-core/core/Cargo.toml +116 -0
  22. data/bridge/sdk-core/core/LICENSE.txt +23 -0
  23. data/bridge/sdk-core/core/benches/workflow_replay.rs +76 -0
  24. data/bridge/sdk-core/core/src/abstractions.rs +166 -0
  25. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +1014 -0
  26. data/bridge/sdk-core/core/src/core_tests/child_workflows.rs +221 -0
  27. data/bridge/sdk-core/core/src/core_tests/determinism.rs +107 -0
  28. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +925 -0
  29. data/bridge/sdk-core/core/src/core_tests/mod.rs +100 -0
  30. data/bridge/sdk-core/core/src/core_tests/queries.rs +894 -0
  31. data/bridge/sdk-core/core/src/core_tests/replay_flag.rs +65 -0
  32. data/bridge/sdk-core/core/src/core_tests/workers.rs +259 -0
  33. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +124 -0
  34. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +2090 -0
  35. data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +515 -0
  36. data/bridge/sdk-core/core/src/lib.rs +282 -0
  37. data/bridge/sdk-core/core/src/pollers/mod.rs +54 -0
  38. data/bridge/sdk-core/core/src/pollers/poll_buffer.rs +297 -0
  39. data/bridge/sdk-core/core/src/protosext/mod.rs +428 -0
  40. data/bridge/sdk-core/core/src/replay/mod.rs +215 -0
  41. data/bridge/sdk-core/core/src/retry_logic.rs +202 -0
  42. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  43. data/bridge/sdk-core/core/src/telemetry/metrics.rs +428 -0
  44. data/bridge/sdk-core/core/src/telemetry/mod.rs +407 -0
  45. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +78 -0
  46. data/bridge/sdk-core/core/src/test_help/mod.rs +889 -0
  47. data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +580 -0
  48. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +1048 -0
  49. data/bridge/sdk-core/core/src/worker/activities.rs +481 -0
  50. data/bridge/sdk-core/core/src/worker/client/mocks.rs +87 -0
  51. data/bridge/sdk-core/core/src/worker/client.rs +373 -0
  52. data/bridge/sdk-core/core/src/worker/mod.rs +570 -0
  53. data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +37 -0
  54. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +101 -0
  55. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +532 -0
  56. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +907 -0
  57. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +294 -0
  58. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +167 -0
  59. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +858 -0
  60. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +136 -0
  61. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +157 -0
  62. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +129 -0
  63. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +1450 -0
  64. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +316 -0
  65. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
  66. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +708 -0
  67. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +439 -0
  68. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +435 -0
  69. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +175 -0
  70. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +242 -0
  71. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +96 -0
  72. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +1200 -0
  73. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +272 -0
  74. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
  75. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +655 -0
  76. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +1200 -0
  77. data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +145 -0
  78. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
  79. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +985 -0
  80. data/bridge/sdk-core/core-api/Cargo.toml +32 -0
  81. data/bridge/sdk-core/core-api/LICENSE.txt +23 -0
  82. data/bridge/sdk-core/core-api/src/errors.rs +95 -0
  83. data/bridge/sdk-core/core-api/src/lib.rs +109 -0
  84. data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
  85. data/bridge/sdk-core/core-api/src/worker.rs +148 -0
  86. data/bridge/sdk-core/etc/deps.svg +162 -0
  87. data/bridge/sdk-core/etc/dynamic-config.yaml +2 -0
  88. data/bridge/sdk-core/etc/otel-collector-config.yaml +36 -0
  89. data/bridge/sdk-core/etc/prometheus.yaml +6 -0
  90. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  91. data/bridge/sdk-core/fsm/Cargo.toml +18 -0
  92. data/bridge/sdk-core/fsm/LICENSE.txt +23 -0
  93. data/bridge/sdk-core/fsm/README.md +3 -0
  94. data/bridge/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +27 -0
  95. data/bridge/sdk-core/fsm/rustfsm_procmacro/LICENSE.txt +23 -0
  96. data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +647 -0
  97. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/progress.rs +8 -0
  98. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.rs +18 -0
  99. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +12 -0
  100. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dynamic_dest_pass.rs +41 -0
  101. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.rs +14 -0
  102. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.stderr +11 -0
  103. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_arg_pass.rs +32 -0
  104. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_pass.rs +31 -0
  105. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/medium_complex_pass.rs +46 -0
  106. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.rs +29 -0
  107. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +12 -0
  108. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/simple_pass.rs +32 -0
  109. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.rs +18 -0
  110. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.stderr +5 -0
  111. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.rs +11 -0
  112. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.stderr +5 -0
  113. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.rs +11 -0
  114. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.stderr +5 -0
  115. data/bridge/sdk-core/fsm/rustfsm_trait/Cargo.toml +14 -0
  116. data/bridge/sdk-core/fsm/rustfsm_trait/LICENSE.txt +23 -0
  117. data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +249 -0
  118. data/bridge/sdk-core/fsm/src/lib.rs +2 -0
  119. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  120. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  121. data/bridge/sdk-core/histories/fail_wf_task.bin +0 -0
  122. data/bridge/sdk-core/histories/timer_workflow_history.bin +0 -0
  123. data/bridge/sdk-core/integ-with-otel.sh +7 -0
  124. data/bridge/sdk-core/protos/api_upstream/README.md +9 -0
  125. data/bridge/sdk-core/protos/api_upstream/api-linter.yaml +40 -0
  126. data/bridge/sdk-core/protos/api_upstream/buf.yaml +9 -0
  127. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  128. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  129. data/bridge/sdk-core/protos/api_upstream/build/tools.go +29 -0
  130. data/bridge/sdk-core/protos/api_upstream/dependencies/gogoproto/gogo.proto +141 -0
  131. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  132. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +89 -0
  133. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +260 -0
  134. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +112 -0
  135. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +47 -0
  136. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +57 -0
  137. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +56 -0
  138. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +170 -0
  139. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +118 -0
  140. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/interaction_type.proto +39 -0
  141. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +51 -0
  142. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +50 -0
  143. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +41 -0
  144. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
  145. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +59 -0
  146. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +40 -0
  147. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +122 -0
  148. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +108 -0
  149. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +114 -0
  150. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +56 -0
  151. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +758 -0
  152. data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
  153. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +97 -0
  154. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +121 -0
  155. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +80 -0
  156. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +61 -0
  157. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +55 -0
  158. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +379 -0
  159. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +108 -0
  160. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +59 -0
  161. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +146 -0
  162. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +1168 -0
  163. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +415 -0
  164. data/bridge/sdk-core/protos/grpc/health/v1/health.proto +63 -0
  165. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
  166. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +79 -0
  167. data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +77 -0
  168. data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +15 -0
  169. data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +30 -0
  170. data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
  171. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +263 -0
  172. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +304 -0
  173. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +29 -0
  174. data/bridge/sdk-core/protos/testsrv_upstream/api-linter.yaml +38 -0
  175. data/bridge/sdk-core/protos/testsrv_upstream/buf.yaml +13 -0
  176. data/bridge/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +141 -0
  177. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +63 -0
  178. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +90 -0
  179. data/bridge/sdk-core/rustfmt.toml +1 -0
  180. data/bridge/sdk-core/sdk/Cargo.toml +47 -0
  181. data/bridge/sdk-core/sdk/LICENSE.txt +23 -0
  182. data/bridge/sdk-core/sdk/src/activity_context.rs +230 -0
  183. data/bridge/sdk-core/sdk/src/app_data.rs +37 -0
  184. data/bridge/sdk-core/sdk/src/interceptors.rs +50 -0
  185. data/bridge/sdk-core/sdk/src/lib.rs +794 -0
  186. data/bridge/sdk-core/sdk/src/payload_converter.rs +11 -0
  187. data/bridge/sdk-core/sdk/src/workflow_context/options.rs +295 -0
  188. data/bridge/sdk-core/sdk/src/workflow_context.rs +694 -0
  189. data/bridge/sdk-core/sdk/src/workflow_future.rs +499 -0
  190. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +30 -0
  191. data/bridge/sdk-core/sdk-core-protos/LICENSE.txt +23 -0
  192. data/bridge/sdk-core/sdk-core-protos/build.rs +107 -0
  193. data/bridge/sdk-core/sdk-core-protos/src/constants.rs +7 -0
  194. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +544 -0
  195. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +230 -0
  196. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +1970 -0
  197. data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
  198. data/bridge/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  199. data/bridge/sdk-core/test-utils/Cargo.toml +36 -0
  200. data/bridge/sdk-core/test-utils/src/canned_histories.rs +1579 -0
  201. data/bridge/sdk-core/test-utils/src/histfetch.rs +28 -0
  202. data/bridge/sdk-core/test-utils/src/lib.rs +650 -0
  203. data/bridge/sdk-core/tests/integ_tests/client_tests.rs +36 -0
  204. data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +128 -0
  205. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +221 -0
  206. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
  207. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +133 -0
  208. data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +437 -0
  209. data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +93 -0
  210. data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +878 -0
  211. data/bridge/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
  212. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +59 -0
  213. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +58 -0
  214. data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +50 -0
  215. data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +60 -0
  216. data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +54 -0
  217. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +788 -0
  218. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
  219. data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +113 -0
  220. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +223 -0
  221. data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +93 -0
  222. data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +167 -0
  223. data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +99 -0
  224. data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +131 -0
  225. data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +75 -0
  226. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +597 -0
  227. data/bridge/sdk-core/tests/load_tests.rs +191 -0
  228. data/bridge/sdk-core/tests/main.rs +113 -0
  229. data/bridge/sdk-core/tests/runner.rs +93 -0
  230. data/bridge/src/connection.rs +186 -0
  231. data/bridge/src/lib.rs +239 -0
  232. data/bridge/src/runtime.rs +54 -0
  233. data/bridge/src/worker.rs +124 -0
  234. data/ext/Rakefile +9 -0
  235. data/lib/bridge.so +0 -0
  236. data/lib/gen/dependencies/gogoproto/gogo_pb.rb +14 -0
  237. data/lib/gen/temporal/api/batch/v1/message_pb.rb +50 -0
  238. data/lib/gen/temporal/api/command/v1/message_pb.rb +174 -0
  239. data/lib/gen/temporal/api/common/v1/message_pb.rb +69 -0
  240. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +33 -0
  241. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +39 -0
  242. data/lib/gen/temporal/api/enums/v1/common_pb.rb +42 -0
  243. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +68 -0
  244. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +77 -0
  245. data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
  246. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +37 -0
  247. data/lib/gen/temporal/api/enums/v1/query_pb.rb +31 -0
  248. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +24 -0
  249. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +28 -0
  250. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +30 -0
  251. data/lib/gen/temporal/api/enums/v1/update_pb.rb +23 -0
  252. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +89 -0
  253. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +84 -0
  254. data/lib/gen/temporal/api/failure/v1/message_pb.rb +83 -0
  255. data/lib/gen/temporal/api/filter/v1/message_pb.rb +40 -0
  256. data/lib/gen/temporal/api/history/v1/message_pb.rb +490 -0
  257. data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
  258. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +63 -0
  259. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +85 -0
  260. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +20 -0
  261. data/lib/gen/temporal/api/query/v1/message_pb.rb +38 -0
  262. data/lib/gen/temporal/api/replication/v1/message_pb.rb +37 -0
  263. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +149 -0
  264. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +73 -0
  265. data/lib/gen/temporal/api/version/v1/message_pb.rb +41 -0
  266. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +111 -0
  267. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +788 -0
  268. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +20 -0
  269. data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +58 -0
  270. data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +57 -0
  271. data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +222 -0
  272. data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +57 -0
  273. data/lib/gen/temporal/sdk/core/common/common_pb.rb +22 -0
  274. data/lib/gen/temporal/sdk/core/core_interface_pb.rb +34 -0
  275. data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +27 -0
  276. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +165 -0
  277. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +196 -0
  278. data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +34 -0
  279. data/lib/temporalio/activity/context.rb +97 -0
  280. data/lib/temporalio/activity/info.rb +67 -0
  281. data/lib/temporalio/activity.rb +85 -0
  282. data/lib/temporalio/bridge/error.rb +8 -0
  283. data/lib/temporalio/bridge.rb +14 -0
  284. data/lib/temporalio/client/implementation.rb +340 -0
  285. data/lib/temporalio/client/workflow_handle.rb +243 -0
  286. data/lib/temporalio/client.rb +131 -0
  287. data/lib/temporalio/connection.rb +751 -0
  288. data/lib/temporalio/data_converter.rb +191 -0
  289. data/lib/temporalio/error/failure.rb +194 -0
  290. data/lib/temporalio/error/workflow_failure.rb +19 -0
  291. data/lib/temporalio/errors.rb +40 -0
  292. data/lib/temporalio/failure_converter/base.rb +26 -0
  293. data/lib/temporalio/failure_converter/basic.rb +319 -0
  294. data/lib/temporalio/failure_converter.rb +7 -0
  295. data/lib/temporalio/interceptor/chain.rb +28 -0
  296. data/lib/temporalio/interceptor/client.rb +123 -0
  297. data/lib/temporalio/payload_codec/base.rb +32 -0
  298. data/lib/temporalio/payload_converter/base.rb +24 -0
  299. data/lib/temporalio/payload_converter/bytes.rb +27 -0
  300. data/lib/temporalio/payload_converter/composite.rb +49 -0
  301. data/lib/temporalio/payload_converter/encoding_base.rb +35 -0
  302. data/lib/temporalio/payload_converter/json.rb +26 -0
  303. data/lib/temporalio/payload_converter/nil.rb +26 -0
  304. data/lib/temporalio/payload_converter.rb +14 -0
  305. data/lib/temporalio/retry_policy.rb +82 -0
  306. data/lib/temporalio/retry_state.rb +35 -0
  307. data/lib/temporalio/runtime.rb +25 -0
  308. data/lib/temporalio/timeout_type.rb +29 -0
  309. data/lib/temporalio/version.rb +3 -0
  310. data/lib/temporalio/worker/activity_runner.rb +92 -0
  311. data/lib/temporalio/worker/activity_worker.rb +138 -0
  312. data/lib/temporalio/worker/reactor.rb +46 -0
  313. data/lib/temporalio/worker/runner.rb +63 -0
  314. data/lib/temporalio/worker/sync_worker.rb +88 -0
  315. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  316. data/lib/temporalio/worker.rb +198 -0
  317. data/lib/temporalio/workflow/execution_info.rb +54 -0
  318. data/lib/temporalio/workflow/execution_status.rb +36 -0
  319. data/lib/temporalio/workflow/id_reuse_policy.rb +36 -0
  320. data/lib/temporalio/workflow/query_reject_condition.rb +33 -0
  321. data/lib/temporalio.rb +12 -1
  322. data/lib/thermite_patch.rb +23 -0
  323. data/temporalio.gemspec +45 -0
  324. metadata +566 -9
  325. data/lib/temporal/version.rb +0 -3
  326. data/lib/temporal.rb +0 -4
  327. data/temporal.gemspec +0 -20
@@ -0,0 +1,32 @@
1
+ [package]
2
+ name = "temporal-sdk-core-api"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Spencer Judge <spencer@temporal.io>"]
6
+ license-file = "LICENSE.txt"
7
+ description = "Interface definitions for the Temporal Core SDK"
8
+ homepage = "https://temporal.io/"
9
+ repository = "https://github.com/temporalio/sdk-core"
10
+ keywords = ["temporal", "workflow"]
11
+ categories = ["development-tools"]
12
+
13
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14
+
15
+ [dependencies]
16
+ async-trait = "0.1"
17
+ derive_builder = "0.12"
18
+ opentelemetry = "0.18"
19
+ prost-types = "0.11"
20
+ serde_json = "1.0"
21
+ thiserror = "1.0"
22
+ tonic = "0.8"
23
+ tracing-core = "0.1"
24
+ url = "2.3"
25
+
26
+ [dependencies.temporal-sdk-core-protos]
27
+ path = "../sdk-core-protos"
28
+ version = "0.1"
29
+
30
+ [dependencies.temporal-client]
31
+ path = "../client"
32
+ version = "0.1"
@@ -0,0 +1,23 @@
1
+ Temporal Core SDK
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2021 Temporal Technologies, Inc. All Rights Reserved
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ //! Error types exposed by public APIs
2
+
3
+ use prost_types::TimestampError;
4
+ use temporal_sdk_core_protos::coresdk::{
5
+ activity_result::ActivityExecutionResult,
6
+ workflow_activation::remove_from_cache::EvictionReason,
7
+ };
8
+
9
+ /// Errors thrown by [crate::Worker::poll_workflow_activation]
10
+ #[derive(thiserror::Error, Debug)]
11
+ pub enum PollWfError {
12
+ /// [crate::Worker::shutdown] was called, and there are no more replay tasks to be handled. Lang
13
+ /// must call [crate::Worker::complete_workflow_activation] for any remaining tasks, and then may
14
+ /// exit.
15
+ #[error("Core is shut down and there are no more workflow replay tasks")]
16
+ ShutDown,
17
+ /// Unhandled error when calling the temporal server. Core will attempt to retry any non-fatal
18
+ /// errors, so lang should consider this fatal.
19
+ #[error("Unhandled grpc error when workflow polling: {0:?}")]
20
+ TonicError(#[from] tonic::Status),
21
+ /// Unhandled error when completing a workflow during a poll -- this can happen when there is no
22
+ /// work for lang to perform, but the server sent us a workflow task (EX: An activity completed
23
+ /// even though we already cancelled it)
24
+ #[error("Unhandled error when auto-completing workflow task: {0:?}")]
25
+ AutocompleteError(#[from] CompleteWfError),
26
+ }
27
+
28
+ /// Errors thrown by [crate::Worker::poll_activity_task]
29
+ #[derive(thiserror::Error, Debug)]
30
+ pub enum PollActivityError {
31
+ /// [crate::Worker::shutdown] was called, we will no longer fetch new activity tasks. Lang must
32
+ /// ensure it is finished with any workflow replay, see [PollWfError::ShutDown]
33
+ #[error("Core is shut down")]
34
+ ShutDown,
35
+ /// Unhandled error when calling the temporal server. Core will attempt to retry any non-fatal
36
+ /// errors, so lang should consider this fatal.
37
+ #[error("Unhandled grpc error when activity polling: {0:?}")]
38
+ TonicError(#[from] tonic::Status),
39
+ }
40
+
41
+ /// Errors thrown by [crate::Worker::complete_workflow_activation]
42
+ #[derive(thiserror::Error, Debug)]
43
+ #[allow(clippy::large_enum_variant)]
44
+ pub enum CompleteWfError {
45
+ /// Lang SDK sent us a malformed workflow completion. This likely means a bug in the lang sdk.
46
+ #[error("Lang SDK sent us a malformed workflow completion for run ({run_id}): {reason}")]
47
+ MalformedWorkflowCompletion {
48
+ /// Reason the completion was malformed
49
+ reason: String,
50
+ /// The run associated with the completion
51
+ run_id: String,
52
+ },
53
+ }
54
+
55
+ /// Errors thrown by [crate::Worker::complete_activity_task]
56
+ #[derive(thiserror::Error, Debug)]
57
+ pub enum CompleteActivityError {
58
+ /// Lang SDK sent us a malformed activity completion. This likely means a bug in the lang sdk.
59
+ #[error("Lang SDK sent us a malformed activity completion ({reason}): {completion:?}")]
60
+ MalformedActivityCompletion {
61
+ /// Reason the completion was malformed
62
+ reason: String,
63
+ /// The completion, which may not be included to avoid unnecessary copies.
64
+ completion: Option<ActivityExecutionResult>,
65
+ },
66
+ }
67
+
68
+ /// Errors thrown inside of workflow machines
69
+ #[derive(thiserror::Error, Debug)]
70
+ pub enum WFMachinesError {
71
+ #[error("Nondeterminism error: {0}")]
72
+ Nondeterminism(String),
73
+ #[error("Fatal error in workflow machines: {0}")]
74
+ Fatal(String),
75
+
76
+ #[error("Unrecoverable network error while fetching history: {0}")]
77
+ HistoryFetchingError(tonic::Status),
78
+ }
79
+
80
+ impl WFMachinesError {
81
+ pub fn evict_reason(&self) -> EvictionReason {
82
+ match self {
83
+ WFMachinesError::Nondeterminism(_) => EvictionReason::Nondeterminism,
84
+ WFMachinesError::Fatal(_) | WFMachinesError::HistoryFetchingError(_) => {
85
+ EvictionReason::Fatal
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ impl From<TimestampError> for WFMachinesError {
92
+ fn from(_: TimestampError) -> Self {
93
+ Self::Fatal("Could not decode timestamp".to_string())
94
+ }
95
+ }
@@ -0,0 +1,109 @@
1
+ pub mod errors;
2
+ pub mod telemetry;
3
+ pub mod worker;
4
+
5
+ use crate::{
6
+ errors::{CompleteActivityError, CompleteWfError, PollActivityError, PollWfError},
7
+ worker::WorkerConfig,
8
+ };
9
+ use temporal_sdk_core_protos::coresdk::{
10
+ activity_task::ActivityTask, workflow_activation::WorkflowActivation,
11
+ workflow_completion::WorkflowActivationCompletion, ActivityHeartbeat, ActivityTaskCompletion,
12
+ };
13
+
14
+ /// This trait is the primary way by which language specific SDKs interact with the core SDK.
15
+ /// It represents one worker, which has a (potentially shared) client for connecting to the service
16
+ /// and is bound to a specific task queue.
17
+ #[async_trait::async_trait]
18
+ pub trait Worker: Send + Sync {
19
+ /// Ask the worker for some work, returning a [WorkflowActivation]. It is then the language
20
+ /// SDK's responsibility to call the appropriate workflow code with the provided inputs. Blocks
21
+ /// indefinitely until such work is available or [Worker::shutdown] is called.
22
+ ///
23
+ /// It is important to understand that all activations must be responded to. There can only
24
+ /// be one outstanding activation for a particular run of a workflow at any time. If an
25
+ /// activation is not responded to, it will cause that workflow to become stuck forever.
26
+ ///
27
+ /// Activations that contain only a `remove_from_cache` job should not cause the workflow code
28
+ /// to be invoked and may be responded to with an empty command list. Eviction jobs may also
29
+ /// appear with other jobs, but will always appear last in the job list. In this case it is
30
+ /// expected that the workflow code will be invoked, and the response produced as normal, but
31
+ /// the caller should evict the run after doing so.
32
+ ///
33
+ /// It is rarely a good idea to call poll concurrently. It handles polling the server
34
+ /// concurrently internally.
35
+ async fn poll_workflow_activation(&self) -> Result<WorkflowActivation, PollWfError>;
36
+
37
+ /// Ask the worker for some work, returning an [ActivityTask]. It is then the language SDK's
38
+ /// responsibility to call the appropriate activity code with the provided inputs. Blocks
39
+ /// indefinitely until such work is available or [Worker::shutdown] is called.
40
+ ///
41
+ /// The returned activation is guaranteed to be for the same task queue / worker which was
42
+ /// provided as the `task_queue` argument.
43
+ ///
44
+ /// It is rarely a good idea to call poll concurrently. It handles polling the server
45
+ /// concurrently internally.
46
+ async fn poll_activity_task(&self) -> Result<ActivityTask, PollActivityError>;
47
+
48
+ /// Tell the worker that a workflow activation has completed. May be freely called concurrently.
49
+ async fn complete_workflow_activation(
50
+ &self,
51
+ completion: WorkflowActivationCompletion,
52
+ ) -> Result<(), CompleteWfError>;
53
+
54
+ /// Tell the worker that an activity has finished executing. May be freely called concurrently.
55
+ async fn complete_activity_task(
56
+ &self,
57
+ completion: ActivityTaskCompletion,
58
+ ) -> Result<(), CompleteActivityError>;
59
+
60
+ /// Notify the Temporal service that an activity is still alive. Long running activities that
61
+ /// take longer than `activity_heartbeat_timeout` to finish must call this function in order to
62
+ /// report progress, otherwise the activity will timeout and a new attempt will be scheduled.
63
+ ///
64
+ /// The first heartbeat request will be sent immediately, subsequent rapid calls to this
65
+ /// function will result in heartbeat requests being aggregated and the last one received during
66
+ /// the aggregation period will be sent to the server, where that period is defined as half the
67
+ /// heartbeat timeout.
68
+ ///
69
+ /// Unlike Java/Go SDKs we do not return cancellation status as part of heartbeat response and
70
+ /// instead send it as a separate activity task to the lang, decoupling heartbeat and
71
+ /// cancellation processing.
72
+ ///
73
+ /// For now activity still need to send heartbeats if they want to receive cancellation
74
+ /// requests. In the future we will change this and will dispatch cancellations more
75
+ /// proactively. Note that this function does not block on the server call and returns
76
+ /// immediately. Underlying validation errors are swallowed and logged, this has been agreed to
77
+ /// be optimal behavior for the user as we don't want to break activity execution due to badly
78
+ /// configured heartbeat options.
79
+ fn record_activity_heartbeat(&self, details: ActivityHeartbeat);
80
+
81
+ /// Request that a workflow be evicted by its run id. This will generate a workflow activation
82
+ /// with the eviction job inside it to be eventually returned by
83
+ /// [Worker::poll_workflow_activation]. If the workflow had any existing outstanding activations,
84
+ /// such activations are invalidated and subsequent completions of them will do nothing and log
85
+ /// a warning.
86
+ fn request_workflow_eviction(&self, run_id: &str);
87
+
88
+ /// Return this worker's config
89
+ fn get_config(&self) -> &WorkerConfig;
90
+
91
+ /// Initiate shutdown. See [Worker::shutdown], this is just a sync version that starts the
92
+ /// process. You can then wait on `shutdown` or [Worker::finalize_shutdown].
93
+ fn initiate_shutdown(&self);
94
+
95
+ /// Initiates async shutdown procedure, eventually ceases all polling of the server and shuts
96
+ /// down this worker. [Worker::poll_workflow_activation] should be called until it
97
+ /// returns [PollWfError::ShutDown] to ensure that any workflows which are still undergoing
98
+ /// replay have an opportunity to finish. This means that the lang sdk will need to call
99
+ /// [Worker::complete_workflow_activation] for those workflows until they are done. At that point,
100
+ /// the lang SDK can end the process, or drop the [Worker] instance, which will close the
101
+ /// connection.
102
+ async fn shutdown(&self);
103
+
104
+ /// Completes shutdown and frees all resources. You should avoid simply dropping workers, as
105
+ /// this does not allow async tasks to report any panics that may have occurred cleanly.
106
+ ///
107
+ /// This should be called only after [Worker::shutdown] has resolved.
108
+ async fn finalize_shutdown(self);
109
+ }
@@ -0,0 +1,147 @@
1
+ use opentelemetry::metrics::Meter;
2
+ use std::{
3
+ collections::HashMap,
4
+ net::SocketAddr,
5
+ time::{Duration, SystemTime, UNIX_EPOCH},
6
+ };
7
+ use tracing_core::Level;
8
+ use url::Url;
9
+
10
+ /// Each core runtime instance has a telemetry subsystem associated with it, this trait defines the
11
+ /// operations that lang might want to perform on that telemetry after it's initialized.
12
+ pub trait CoreTelemetry {
13
+ /// Each worker buffers logs that should be shuttled over to lang so that they may be rendered
14
+ /// with the user's desired logging library. Use this function to grab the most recent buffered
15
+ /// logs since the last time it was called. A fixed number of such logs are retained at maximum,
16
+ /// with the oldest being dropped when full.
17
+ ///
18
+ /// Returns the list of logs from oldest to newest. Returns an empty vec if the feature is not
19
+ /// configured.
20
+ fn fetch_buffered_logs(&self) -> Vec<CoreLog>;
21
+
22
+ /// If metrics gathering is enabled, returns the OTel meter for core telemetry, which can be
23
+ /// used to create metrics instruments, or passed to things that create/record metrics (ex:
24
+ /// clients).
25
+ fn get_metric_meter(&self) -> Option<&Meter>;
26
+ }
27
+
28
+ /// Telemetry configuration options. Construct with [TelemetryOptionsBuilder]
29
+ #[derive(Debug, Clone, derive_builder::Builder)]
30
+ #[non_exhaustive]
31
+ pub struct TelemetryOptions {
32
+ /// Optional trace exporter - set as None to disable.
33
+ #[builder(setter(into, strip_option), default)]
34
+ pub tracing: Option<TraceExportConfig>,
35
+ /// Optional logger - set as None to disable.
36
+ #[builder(setter(into, strip_option), default)]
37
+ pub logging: Option<Logger>,
38
+ /// Optional metrics exporter - set as None to disable.
39
+ #[builder(setter(into, strip_option), default)]
40
+ pub metrics: Option<MetricsExporter>,
41
+
42
+ /// If set true, do not prefix metrics with `temporal_`. Will be removed eventually as
43
+ /// the prefix is consistent with other SDKs.
44
+ #[builder(default)]
45
+ pub no_temporal_prefix_for_metrics: bool,
46
+
47
+ /// Specifies the aggregation temporality for metric export. Defaults to cumulative.
48
+ #[builder(default = "MetricTemporality::Cumulative")]
49
+ pub metric_temporality: MetricTemporality,
50
+ }
51
+
52
+ /// Options for exporting to an OpenTelemetry Collector
53
+ #[derive(Debug, Clone)]
54
+ pub struct OtelCollectorOptions {
55
+ /// The url of the OTel collector to export telemetry and metrics to. Lang SDK should also
56
+ /// export to this same collector.
57
+ pub url: Url,
58
+ /// Optional set of HTTP headers to send to the Collector, e.g for authentication.
59
+ pub headers: HashMap<String, String>,
60
+ /// Optionally specify how frequently metrics should be exported. Defaults to 1 second.
61
+ pub metric_periodicity: Option<Duration>,
62
+ }
63
+
64
+ /// Configuration for the external export of traces
65
+ #[derive(Debug, Clone)]
66
+ pub struct TraceExportConfig {
67
+ /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
68
+ pub filter: String,
69
+ /// Where they should go
70
+ pub exporter: TraceExporter,
71
+ }
72
+
73
+ /// Control where traces are exported.
74
+ #[derive(Debug, Clone)]
75
+ pub enum TraceExporter {
76
+ /// Export traces to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
77
+ Otel(OtelCollectorOptions),
78
+ }
79
+
80
+ /// Control where metrics are exported
81
+ #[derive(Debug, Clone)]
82
+ pub enum MetricsExporter {
83
+ /// Export metrics to an OpenTelemetry Collector <https://opentelemetry.io/docs/collector/>.
84
+ Otel(OtelCollectorOptions),
85
+ /// Expose metrics directly via an embedded http server bound to the provided address.
86
+ Prometheus(SocketAddr),
87
+ }
88
+
89
+ /// Control where logs go
90
+ #[derive(Debug, Clone)]
91
+ pub enum Logger {
92
+ /// Log directly to console.
93
+ Console {
94
+ /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
95
+ filter: String,
96
+ },
97
+ /// Forward logs to Lang - collectable with `fetch_global_buffered_logs`.
98
+ Forward {
99
+ /// An [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/struct.EnvFilter.html) filter string.
100
+ filter: String,
101
+ },
102
+ }
103
+
104
+ /// Types of aggregation temporality for metric export.
105
+ /// See: <https://github.com/open-telemetry/opentelemetry-specification/blob/ce50e4634efcba8da445cc23523243cb893905cb/specification/metrics/datamodel.md#temporality>
106
+ #[derive(Debug, Clone, Copy)]
107
+ pub enum MetricTemporality {
108
+ /// Successive data points repeat the starting timestamp
109
+ Cumulative,
110
+ /// Successive data points advance the starting timestamp
111
+ Delta,
112
+ }
113
+
114
+ impl Default for TelemetryOptions {
115
+ fn default() -> Self {
116
+ TelemetryOptionsBuilder::default().build().unwrap()
117
+ }
118
+ }
119
+
120
+ /// A log line (which ultimately came from a tracing event) exported from Core->Lang
121
+ #[derive(Debug)]
122
+ pub struct CoreLog {
123
+ /// The module within core this message originated from
124
+ pub target: String,
125
+ /// Log message
126
+ pub message: String,
127
+ /// Time log was generated (not when it was exported to lang)
128
+ pub timestamp: SystemTime,
129
+ /// Message level
130
+ pub level: Level,
131
+ /// Arbitrary k/v pairs (span k/vs are collapsed with event k/vs here). We could change this
132
+ /// to include them in `span_contexts` instead, but there's probably not much value for log
133
+ /// forwarding.
134
+ pub fields: HashMap<String, serde_json::Value>,
135
+ /// A list of the outermost to the innermost span names
136
+ pub span_contexts: Vec<String>,
137
+ }
138
+
139
+ impl CoreLog {
140
+ /// Return timestamp as ms since epoch
141
+ pub fn millis_since_epoch(&self) -> u128 {
142
+ self.timestamp
143
+ .duration_since(UNIX_EPOCH)
144
+ .unwrap_or(Duration::ZERO)
145
+ .as_millis()
146
+ }
147
+ }
@@ -0,0 +1,148 @@
1
+ use std::time::Duration;
2
+
3
+ /// Defines per-worker configuration options
4
+ #[derive(Debug, Clone, derive_builder::Builder)]
5
+ #[builder(setter(into), build_fn(validate = "Self::validate"))]
6
+ #[non_exhaustive]
7
+ pub struct WorkerConfig {
8
+ /// The Temporal service namespace this worker is bound to
9
+ pub namespace: String,
10
+ /// What task queue will this worker poll from? This task queue name will be used for both
11
+ /// workflow and activity polling.
12
+ pub task_queue: String,
13
+ /// A string that should be unique to the set of code this worker uses. IE: All the workflow,
14
+ /// activity, interceptor, and data converter code.
15
+ pub worker_build_id: String,
16
+ /// A human-readable string that can identify this worker. Using something like sdk version
17
+ /// and host name is a good default. If set, overrides the identity set (if any) on the client
18
+ /// used by this worker.
19
+ #[builder(default)]
20
+ pub client_identity_override: Option<String>,
21
+ /// If set nonzero, workflows will be cached and sticky task queues will be used, meaning that
22
+ /// history updates are applied incrementally to suspended instances of workflow execution.
23
+ /// Workflows are evicted according to a least-recently-used policy one the cache maximum is
24
+ /// reached. Workflows may also be explicitly evicted at any time, or as a result of errors
25
+ /// or failures.
26
+ #[builder(default = "0")]
27
+ pub max_cached_workflows: usize,
28
+ /// The maximum allowed number of workflow tasks that will ever be given to this worker at one
29
+ /// time. Note that one workflow task may require multiple activations - so the WFT counts as
30
+ /// "outstanding" until all activations it requires have been completed.
31
+ ///
32
+ /// Cannot be larger than `max_cached_workflows`.
33
+ #[builder(default = "100")]
34
+ pub max_outstanding_workflow_tasks: usize,
35
+ /// The maximum number of activity tasks that will ever be given to this worker concurrently
36
+ #[builder(default = "100")]
37
+ pub max_outstanding_activities: usize,
38
+ /// The maximum number of local activity tasks that will ever be given to this worker
39
+ /// concurrently
40
+ #[builder(default = "100")]
41
+ pub max_outstanding_local_activities: usize,
42
+ /// Maximum number of concurrent poll workflow task requests we will perform at a time on this
43
+ /// worker's task queue. See also [WorkerConfig::nonsticky_to_sticky_poll_ratio]. Must be at
44
+ /// least 1.
45
+ #[builder(default = "5")]
46
+ pub max_concurrent_wft_polls: usize,
47
+ /// [WorkerConfig::max_concurrent_wft_polls] * this number = the number of max pollers that will
48
+ /// be allowed for the nonsticky queue when sticky tasks are enabled. If both defaults are used,
49
+ /// the sticky queue will allow 4 max pollers while the nonsticky queue will allow one. The
50
+ /// minimum for either poller is 1, so if `max_concurrent_wft_polls` is 1 and sticky queues are
51
+ /// enabled, there will be 2 concurrent polls.
52
+ #[builder(default = "0.2")]
53
+ pub nonsticky_to_sticky_poll_ratio: f32,
54
+ /// Maximum number of concurrent poll activity task requests we will perform at a time on this
55
+ /// worker's task queue
56
+ #[builder(default = "5")]
57
+ pub max_concurrent_at_polls: usize,
58
+ /// If set to true this worker will only handle workflow tasks and local activities, it will not
59
+ /// poll for activity tasks.
60
+ #[builder(default = "false")]
61
+ pub no_remote_activities: bool,
62
+ /// How long a workflow task is allowed to sit on the sticky queue before it is timed out
63
+ /// and moved to the non-sticky queue where it may be picked up by any worker.
64
+ #[builder(default = "Duration::from_secs(10)")]
65
+ pub sticky_queue_schedule_to_start_timeout: Duration,
66
+
67
+ /// Longest interval for throttling activity heartbeats
68
+ #[builder(default = "Duration::from_secs(60)")]
69
+ pub max_heartbeat_throttle_interval: Duration,
70
+
71
+ /// Default interval for throttling activity heartbeats in case
72
+ /// `ActivityOptions.heartbeat_timeout` is unset.
73
+ /// When the timeout *is* set in the `ActivityOptions`, throttling is set to
74
+ /// `heartbeat_timeout * 0.8`.
75
+ #[builder(default = "Duration::from_secs(30)")]
76
+ pub default_heartbeat_throttle_interval: Duration,
77
+
78
+ /// Sets the maximum number of activities per second the task queue will dispatch, controlled
79
+ /// server-side. Note that this only takes effect upon an activity poll request. If multiple
80
+ /// workers on the same queue have different values set, they will thrash with the last poller
81
+ /// winning.
82
+ #[builder(default)]
83
+ pub max_task_queue_activities_per_second: Option<f64>,
84
+
85
+ /// Limits the number of activities per second that this worker will process. The worker will
86
+ /// not poll for new activities if by doing so it might receive and execute an activity which
87
+ /// would cause it to exceed this limit. Negative, zero, or NaN values will cause building
88
+ /// the options to fail.
89
+ #[builder(default)]
90
+ pub max_worker_activities_per_second: Option<f64>,
91
+
92
+ /// # UNDER DEVELOPMENT
93
+ /// If set to true this worker will opt-in to the whole-worker versioning feature.
94
+ /// `worker_build_id` will be used as the version.
95
+ /// todo: link to feature docs
96
+ #[builder(default = "false")]
97
+ pub use_worker_versioning: bool,
98
+
99
+ /// If set false (default), shutdown will not finish until all pending evictions have been
100
+ /// issued and replied to. If set true shutdown will be considered complete when the only
101
+ /// remaining work is pending evictions.
102
+ ///
103
+ /// This flag is useful during tests to avoid needing to deal with lots of uninteresting
104
+ /// evictions during shutdown. Alternatively, if a lang implementation finds it easy to clean
105
+ /// up during shutdown, setting this true saves some back-and-forth.
106
+ #[builder(default = "false")]
107
+ pub ignore_evicts_on_shutdown: bool,
108
+ }
109
+
110
+ impl WorkerConfig {
111
+ pub fn max_nonsticky_polls(&self) -> usize {
112
+ ((self.max_concurrent_wft_polls as f32 * self.nonsticky_to_sticky_poll_ratio) as usize)
113
+ .max(1)
114
+ }
115
+ pub fn max_sticky_polls(&self) -> usize {
116
+ self.max_concurrent_wft_polls
117
+ .saturating_sub(self.max_nonsticky_polls())
118
+ .max(1)
119
+ }
120
+ }
121
+
122
+ impl WorkerConfigBuilder {
123
+ fn validate(&self) -> Result<(), String> {
124
+ if self.max_concurrent_wft_polls == Some(0) {
125
+ return Err("`max_concurrent_wft_polls` must be at least 1".to_owned());
126
+ }
127
+ if self.max_concurrent_at_polls == Some(0) {
128
+ return Err("`max_concurrent_at_polls` must be at least 1".to_owned());
129
+ }
130
+ if self.max_cached_workflows > Some(0)
131
+ && self.max_outstanding_workflow_tasks > self.max_cached_workflows
132
+ {
133
+ return Err(
134
+ "Maximum concurrent workflow tasks cannot exceed the maximum number of cached \
135
+ workflows"
136
+ .to_owned(),
137
+ );
138
+ }
139
+ if let Some(Some(ref x)) = self.max_worker_activities_per_second {
140
+ if !x.is_normal() || x.is_sign_negative() {
141
+ return Err(
142
+ "`max_worker_activities_per_second` must be positive and nonzero".to_owned(),
143
+ );
144
+ }
145
+ }
146
+ Ok(())
147
+ }
148
+ }