temporalio 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +180 -7
  3. data/bridge/Cargo.lock +208 -76
  4. data/bridge/Cargo.toml +5 -2
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +20 -10
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +227 -59
  9. data/bridge/sdk-core/client/src/metrics.rs +17 -8
  10. data/bridge/sdk-core/client/src/raw.rs +13 -12
  11. data/bridge/sdk-core/client/src/retry.rs +132 -43
  12. data/bridge/sdk-core/core/Cargo.toml +28 -15
  13. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  14. data/bridge/sdk-core/core/src/abstractions.rs +225 -36
  15. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +217 -79
  16. data/bridge/sdk-core/core/src/core_tests/determinism.rs +165 -2
  17. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +565 -34
  18. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -90
  19. data/bridge/sdk-core/core/src/core_tests/workers.rs +3 -5
  20. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  21. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +430 -67
  22. data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +106 -12
  23. data/bridge/sdk-core/core/src/internal_flags.rs +136 -0
  24. data/bridge/sdk-core/core/src/lib.rs +148 -34
  25. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  26. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  27. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  28. data/bridge/sdk-core/core/src/telemetry/metrics.rs +219 -140
  29. data/bridge/sdk-core/core/src/telemetry/mod.rs +326 -315
  30. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +20 -14
  31. data/bridge/sdk-core/core/src/test_help/mod.rs +85 -21
  32. data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +112 -156
  33. data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
  34. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +364 -128
  35. data/bridge/sdk-core/core/src/worker/activities.rs +263 -170
  36. data/bridge/sdk-core/core/src/worker/client/mocks.rs +23 -3
  37. data/bridge/sdk-core/core/src/worker/client.rs +48 -6
  38. data/bridge/sdk-core/core/src/worker/mod.rs +186 -75
  39. data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
  40. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +13 -24
  41. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +879 -226
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +101 -48
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -12
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -9
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +90 -32
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +6 -9
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -10
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -9
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +160 -83
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +36 -54
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +179 -0
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +104 -157
  53. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +8 -12
  54. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +9 -13
  55. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +10 -4
  56. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +14 -11
  57. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
  58. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +395 -299
  59. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +12 -20
  60. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +33 -18
  61. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +1032 -374
  62. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +525 -392
  63. data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
  64. data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +125 -0
  65. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -6
  66. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
  67. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
  68. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +456 -681
  69. data/bridge/sdk-core/core-api/Cargo.toml +6 -4
  70. data/bridge/sdk-core/core-api/src/errors.rs +1 -34
  71. data/bridge/sdk-core/core-api/src/lib.rs +7 -45
  72. data/bridge/sdk-core/core-api/src/telemetry.rs +141 -0
  73. data/bridge/sdk-core/core-api/src/worker.rs +27 -1
  74. data/bridge/sdk-core/etc/deps.svg +115 -140
  75. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  76. data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +18 -15
  77. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  78. data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +8 -3
  79. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
  80. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  81. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  82. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  83. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  84. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  85. data/bridge/sdk-core/protos/api_upstream/{temporal/api/enums/v1/cluster.proto → build/tools.go} +7 -18
  86. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +15 -26
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -9
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +10 -8
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +28 -2
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  104. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  105. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +62 -26
  106. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
  107. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +24 -61
  108. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  109. data/bridge/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
  110. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  111. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  112. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  113. data/bridge/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
  114. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  115. data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
  116. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  117. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  118. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +111 -36
  119. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +19 -5
  120. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +1 -0
  121. data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +1 -0
  122. data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +1 -0
  123. data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
  124. data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
  125. data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +1 -0
  126. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +9 -0
  127. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +9 -1
  128. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +6 -0
  129. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  130. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  131. data/bridge/sdk-core/sdk/Cargo.toml +4 -3
  132. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  133. data/bridge/sdk-core/sdk/src/lib.rs +94 -25
  134. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  135. data/bridge/sdk-core/sdk/src/workflow_future.rs +10 -13
  136. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +5 -2
  137. data/bridge/sdk-core/sdk-core-protos/build.rs +36 -2
  138. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +164 -104
  139. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +27 -23
  140. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +252 -74
  141. data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
  142. data/bridge/sdk-core/test-utils/Cargo.toml +4 -1
  143. data/bridge/sdk-core/test-utils/src/canned_histories.rs +106 -296
  144. data/bridge/sdk-core/test-utils/src/histfetch.rs +1 -1
  145. data/bridge/sdk-core/test-utils/src/lib.rs +161 -50
  146. data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
  147. data/bridge/sdk-core/test-utils/src/workflows.rs +29 -0
  148. data/bridge/sdk-core/tests/fuzzy_workflow.rs +130 -0
  149. data/bridge/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
  150. data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
  151. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
  152. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +239 -0
  153. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +4 -60
  154. data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
  155. data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
  156. data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -69
  157. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
  158. data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
  159. data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -0
  160. data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
  161. data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
  162. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +151 -116
  163. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +54 -0
  164. data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +7 -28
  165. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +115 -24
  166. data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
  167. data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
  168. data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
  169. data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
  170. data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -4
  171. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +27 -18
  172. data/bridge/sdk-core/tests/main.rs +8 -16
  173. data/bridge/sdk-core/tests/runner.rs +75 -36
  174. data/bridge/sdk-core/tests/wf_input_replay.rs +32 -0
  175. data/bridge/src/connection.rs +117 -82
  176. data/bridge/src/lib.rs +356 -42
  177. data/bridge/src/runtime.rs +10 -3
  178. data/bridge/src/test_server.rs +153 -0
  179. data/bridge/src/worker.rs +133 -9
  180. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  181. data/lib/gen/temporal/api/command/v1/message_pb.rb +10 -16
  182. data/lib/gen/temporal/api/common/v1/message_pb.rb +5 -1
  183. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  184. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -3
  185. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  186. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +5 -4
  187. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +9 -1
  188. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  189. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  190. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  191. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  192. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  193. data/lib/gen/temporal/api/enums/v1/update_pb.rb +7 -10
  194. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  195. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  196. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  197. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  198. data/lib/gen/temporal/api/history/v1/message_pb.rb +34 -25
  199. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +2 -1
  200. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +14 -51
  201. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  202. data/lib/gen/temporal/api/protocol/v1/message_pb.rb +30 -0
  203. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  204. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  205. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  206. data/lib/gen/temporal/api/sdk/v1/task_complete_metadata_pb.rb +23 -0
  207. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  208. data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +49 -0
  209. data/lib/gen/temporal/api/testservice/v1/service_pb.rb +21 -0
  210. data/lib/gen/temporal/api/update/v1/message_pb.rb +49 -3
  211. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  212. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  213. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +47 -20
  214. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  215. data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +13 -9
  216. data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +10 -6
  217. data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +13 -9
  218. data/lib/gen/temporal/sdk/core/common/common_pb.rb +7 -3
  219. data/lib/gen/temporal/sdk/core/core_interface_pb.rb +9 -3
  220. data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +7 -3
  221. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +28 -21
  222. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +32 -24
  223. data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +12 -5
  224. data/lib/temporalio/activity/context.rb +102 -0
  225. data/lib/temporalio/activity/info.rb +67 -0
  226. data/lib/temporalio/activity.rb +85 -0
  227. data/lib/temporalio/bridge/connect_options.rb +15 -0
  228. data/lib/temporalio/bridge/error.rb +8 -0
  229. data/lib/temporalio/bridge/retry_config.rb +24 -0
  230. data/lib/temporalio/bridge/tls_options.rb +19 -0
  231. data/lib/temporalio/bridge.rb +14 -0
  232. data/lib/{temporal → temporalio}/client/implementation.rb +57 -56
  233. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  234. data/lib/{temporal → temporalio}/client.rb +19 -32
  235. data/lib/temporalio/connection/retry_config.rb +44 -0
  236. data/lib/temporalio/connection/service.rb +20 -0
  237. data/lib/temporalio/connection/test_service.rb +92 -0
  238. data/lib/temporalio/connection/tls_options.rb +51 -0
  239. data/lib/temporalio/connection/workflow_service.rb +731 -0
  240. data/lib/temporalio/connection.rb +86 -0
  241. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  242. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  243. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  244. data/lib/{temporal → temporalio}/errors.rb +19 -1
  245. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  246. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  247. data/lib/temporalio/failure_converter.rb +7 -0
  248. data/lib/temporalio/interceptor/activity_inbound.rb +22 -0
  249. data/lib/temporalio/interceptor/activity_outbound.rb +24 -0
  250. data/lib/{temporal → temporalio}/interceptor/chain.rb +7 -6
  251. data/lib/{temporal → temporalio}/interceptor/client.rb +27 -2
  252. data/lib/temporalio/interceptor.rb +22 -0
  253. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  254. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  255. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  256. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  257. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  258. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  259. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  260. data/lib/temporalio/payload_converter.rb +14 -0
  261. data/lib/{temporal → temporalio}/retry_policy.rb +17 -7
  262. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  263. data/lib/temporalio/runtime.rb +25 -0
  264. data/lib/temporalio/testing/time_skipping_handle.rb +32 -0
  265. data/lib/temporalio/testing/time_skipping_interceptor.rb +23 -0
  266. data/lib/temporalio/testing/workflow_environment.rb +112 -0
  267. data/lib/temporalio/testing.rb +175 -0
  268. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  269. data/lib/temporalio/version.rb +3 -0
  270. data/lib/temporalio/worker/activity_runner.rb +114 -0
  271. data/lib/temporalio/worker/activity_worker.rb +164 -0
  272. data/lib/temporalio/worker/reactor.rb +46 -0
  273. data/lib/temporalio/worker/runner.rb +63 -0
  274. data/lib/temporalio/worker/sync_worker.rb +124 -0
  275. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  276. data/lib/temporalio/worker.rb +204 -0
  277. data/lib/temporalio/workflow/async.rb +46 -0
  278. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  279. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  280. data/lib/temporalio/workflow/future.rb +138 -0
  281. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  282. data/lib/temporalio/workflow/info.rb +76 -0
  283. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  284. data/lib/temporalio.rb +12 -3
  285. data/temporalio.gemspec +11 -6
  286. metadata +137 -64
  287. data/bridge/sdk-core/Cargo.lock +0 -2606
  288. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  289. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  290. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  291. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  292. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  293. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  294. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  295. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  296. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  297. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  298. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  299. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  300. data/lib/bridge.so +0 -0
  301. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  302. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  303. data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +0 -222
  304. data/lib/temporal/bridge.rb +0 -14
  305. data/lib/temporal/connection.rb +0 -736
  306. data/lib/temporal/failure_converter.rb +0 -8
  307. data/lib/temporal/payload_converter.rb +0 -14
  308. data/lib/temporal/runtime.rb +0 -22
  309. data/lib/temporal/version.rb +0 -3
  310. data/lib/temporal.rb +0 -8
@@ -1,825 +0,0 @@
1
- #![allow(
2
- // Non-camel-case types needed since this is exported as a C header and we
3
- // want C-like underscores in our type names
4
- non_camel_case_types,
5
-
6
- // We choose to have narrow "unsafe" blocks instead of marking entire
7
- // functions as unsafe. Even the example in clippy's docs at
8
- // https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
9
- // cause a rustc warning for unnecessary inner-unsafe when marked on fn.
10
- // This check only applies to "pub" functions which are all exposed via C
11
- // API.
12
- clippy::not_unsafe_ptr_arg_deref,
13
- )]
14
-
15
- mod wrappers;
16
-
17
- use bridge::{init_response, CreateWorkerRequest, InitResponse};
18
- use prost::Message;
19
- use std::sync::Arc;
20
- use temporal_sdk_core::{
21
- fetch_global_buffered_logs, telemetry_init, Client, ClientOptions, RetryClient,
22
- };
23
- use temporal_sdk_core_api::Worker;
24
- use temporal_sdk_core_protos::coresdk::{
25
- bridge,
26
- bridge::{CreateClientRequest, InitTelemetryRequest},
27
- };
28
-
29
- /// A set of bytes owned by Core. No fields within nor any bytes references must
30
- /// ever be mutated outside of Core. This must always be passed to
31
- /// tmprl_bytes_free when no longer in use.
32
- #[repr(C)]
33
- pub struct tmprl_bytes_t {
34
- bytes: *const u8,
35
- len: libc::size_t,
36
- /// For internal use only.
37
- cap: libc::size_t,
38
- /// For internal use only.
39
- disable_free: bool,
40
- }
41
-
42
- impl tmprl_bytes_t {
43
- fn from_vec(vec: Vec<u8>) -> tmprl_bytes_t {
44
- // Mimics Vec::into_raw_parts that's only available in nightly
45
- let mut vec = std::mem::ManuallyDrop::new(vec);
46
- tmprl_bytes_t {
47
- bytes: vec.as_mut_ptr(),
48
- len: vec.len(),
49
- cap: vec.capacity(),
50
- disable_free: false,
51
- }
52
- }
53
-
54
- fn from_vec_disable_free(vec: Vec<u8>) -> tmprl_bytes_t {
55
- let mut b = tmprl_bytes_t::from_vec(vec);
56
- b.disable_free = true;
57
- b
58
- }
59
-
60
- fn into_raw(self) -> *mut tmprl_bytes_t {
61
- Box::into_raw(Box::new(self))
62
- }
63
- }
64
-
65
- /// Required because these instances are used by lazy_static and raw pointers
66
- /// are not usually safe for send/sync.
67
- unsafe impl Send for tmprl_bytes_t {}
68
- unsafe impl Sync for tmprl_bytes_t {}
69
-
70
- impl Drop for tmprl_bytes_t {
71
- fn drop(&mut self) {
72
- // In cases where freeing is disabled (or technically some other
73
- // drop-but-not-freed situation though we don't expect any), the bytes
74
- // remain non-null so we re-own them here
75
- if !self.bytes.is_null() {
76
- unsafe { Vec::from_raw_parts(self.bytes as *mut u8, self.len, self.cap) };
77
- }
78
- }
79
- }
80
-
81
- /// Free a set of bytes. The first parameter can be null in cases where a [tmprl_worker_t] instance
82
- /// isn't available. If the second parameter is null, this is a no-op.
83
- #[no_mangle]
84
- pub extern "C" fn tmprl_bytes_free(worker: *mut tmprl_worker_t, bytes: *const tmprl_bytes_t) {
85
- // Bail if freeing is disabled
86
- unsafe {
87
- if bytes.is_null() || (*bytes).disable_free {
88
- return;
89
- }
90
- }
91
- let bytes = bytes as *mut tmprl_bytes_t;
92
- // Return vec back to core before dropping bytes
93
- let vec = unsafe { Vec::from_raw_parts((*bytes).bytes as *mut u8, (*bytes).len, (*bytes).cap) };
94
- // Set to null so the byte dropper doesn't try to free it
95
- unsafe { (*bytes).bytes = std::ptr::null_mut() };
96
- // Return only if worker is non-null
97
- if !worker.is_null() {
98
- let worker = unsafe { &mut *worker };
99
- worker.return_buf(vec);
100
- }
101
- unsafe {
102
- let _ = Box::from_raw(bytes);
103
- }
104
- }
105
-
106
- /// Used for maintaining pointer to user data across threads. See
107
- /// https://doc.rust-lang.org/nomicon/send-and-sync.html.
108
- struct UserDataHandle(*mut libc::c_void);
109
- unsafe impl Send for UserDataHandle {}
110
- unsafe impl Sync for UserDataHandle {}
111
-
112
- impl From<UserDataHandle> for *mut libc::c_void {
113
- fn from(v: UserDataHandle) -> Self {
114
- v.0
115
- }
116
- }
117
-
118
- lazy_static::lazy_static! {
119
- static ref DEFAULT_INIT_RESPONSE_BYTES: tmprl_bytes_t = {
120
- tmprl_bytes_t::from_vec_disable_free(bridge::InitResponse::default().encode_to_vec())
121
- };
122
-
123
- static ref DEFAULT_REGISTER_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
124
- tmprl_bytes_t::from_vec_disable_free(bridge::RegisterWorkerResponse::default().encode_to_vec())
125
- };
126
-
127
- static ref DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
128
- tmprl_bytes_t::from_vec_disable_free(bridge::ShutdownWorkerResponse::default().encode_to_vec())
129
- };
130
-
131
- static ref DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES: tmprl_bytes_t = {
132
- tmprl_bytes_t::from_vec_disable_free(bridge::CompleteWorkflowActivationResponse::default().encode_to_vec())
133
- };
134
-
135
- static ref DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES: tmprl_bytes_t = {
136
- tmprl_bytes_t::from_vec_disable_free(bridge::CompleteActivityTaskResponse::default().encode_to_vec())
137
- };
138
-
139
- static ref DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES: tmprl_bytes_t = {
140
- tmprl_bytes_t::from_vec_disable_free(bridge::RecordActivityHeartbeatResponse::default().encode_to_vec())
141
- };
142
-
143
- static ref DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES: tmprl_bytes_t = {
144
- tmprl_bytes_t::from_vec_disable_free(bridge::RequestWorkflowEvictionResponse::default().encode_to_vec())
145
- };
146
- }
147
-
148
- /// A runtime owned by Core. This must be passed to [tmprl_runtime_free] when no longer in use. This
149
- /// should not be freed until every call to every [tmprl_worker_t] instance created with this
150
- /// runtime has been shutdown. In practice, since the actual runtime is behind an [Arc], it's
151
- /// currently OK, but that's an implementation detail.
152
- pub struct tmprl_runtime_t {
153
- // This is the same runtime shared with worker instances
154
- tokio_runtime: Arc<tokio::runtime::Runtime>,
155
- }
156
-
157
- /// Create a new runtime. The result is never null and must be freed via
158
- /// tmprl_runtime_free when no longer in use.
159
- #[no_mangle]
160
- pub extern "C" fn tmprl_runtime_new() -> *mut tmprl_runtime_t {
161
- Box::into_raw(Box::new(tmprl_runtime_t {
162
- // TODO(cretz): Options to configure thread pool?
163
- tokio_runtime: Arc::new(
164
- tokio::runtime::Builder::new_multi_thread()
165
- .enable_all()
166
- .build()
167
- .unwrap(),
168
- ),
169
- }))
170
- }
171
-
172
- /// Free a previously created runtime.
173
- #[no_mangle]
174
- pub extern "C" fn tmprl_runtime_free(runtime: *mut tmprl_runtime_t) {
175
- if !runtime.is_null() {
176
- unsafe {
177
- let _ = Box::from_raw(runtime);
178
- }
179
- }
180
- }
181
-
182
- /// A worker instance owned by Core. This must be passed to [tmprl_worker_shutdown]
183
- /// when no longer in use which will free the resources.
184
- pub struct tmprl_worker_t {
185
- tokio_runtime: Arc<tokio::runtime::Runtime>,
186
- // We are not concerned with the overhead of dynamic dispatch at this time
187
- worker: Arc<dyn Worker>,
188
- }
189
-
190
- /// Callback called by [tmprl_worker_init] on completion. The first parameter of the
191
- /// callback is user data passed into the original function. The second
192
- /// parameter is a worker instance if the call is successful or null if not. If
193
- /// present, the worker instance must be freed via [tmprl_worker_shutdown] when no
194
- /// longer in use. The third parameter of the callback is a byte array for a
195
- /// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
196
- type tmprl_worker_init_callback = unsafe extern "C" fn(
197
- user_data: *mut libc::c_void,
198
- worker: *mut tmprl_worker_t,
199
- resp: *const tmprl_bytes_t,
200
- );
201
-
202
- /// Callback called on function completion. The first parameter of the callback
203
- /// is user data passed into the original function. The second parameter of the
204
- /// callback is a never-null byte array for a response protobuf message which
205
- /// must be freed via [tmprl_bytes_free].
206
- type tmprl_callback =
207
- unsafe extern "C" fn(user_data: *mut libc::c_void, core: *const tmprl_bytes_t);
208
-
209
- /// Create a new worker instance.
210
- ///
211
- /// `runtime` and `client` are both required and must outlive this instance.
212
- /// `req_proto` and `req_proto_len` represent a byte array for a [CreateWorkerRequest] protobuf
213
- /// message.
214
- /// The callback is invoked on completion.
215
- #[no_mangle]
216
- pub extern "C" fn tmprl_worker_init(
217
- runtime: *mut tmprl_runtime_t,
218
- client: *mut tmprl_client_t,
219
- req_proto: *const u8,
220
- req_proto_len: libc::size_t,
221
- user_data: *mut libc::c_void,
222
- callback: tmprl_worker_init_callback,
223
- ) {
224
- let (runtime, client) = unsafe { (&*runtime, &*client) };
225
- let req = match tmprl_worker_t::decode_proto::<CreateWorkerRequest>(req_proto, req_proto_len) {
226
- Ok(req) => req,
227
- Err(message) => {
228
- let resp = InitResponse {
229
- error: Some(init_response::Error { message }),
230
- };
231
- unsafe {
232
- callback(
233
- user_data,
234
- std::ptr::null_mut(),
235
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
236
- );
237
- }
238
- return;
239
- }
240
- };
241
- let user_data = UserDataHandle(user_data);
242
- match tmprl_worker_t::new(
243
- runtime.tokio_runtime.clone(),
244
- client.client.clone(),
245
- wrappers::WorkerConfig(req),
246
- ) {
247
- Ok(worker) => unsafe {
248
- callback(
249
- user_data.into(),
250
- Box::into_raw(Box::new(worker)),
251
- &*DEFAULT_INIT_RESPONSE_BYTES,
252
- );
253
- },
254
- Err(message) => {
255
- let resp = InitResponse {
256
- error: Some(init_response::Error { message }),
257
- };
258
- unsafe {
259
- callback(
260
- user_data.into(),
261
- std::ptr::null_mut(),
262
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
263
- );
264
- }
265
- }
266
- };
267
- }
268
-
269
- /// Shutdown and free a previously created worker.
270
- ///
271
- /// The req_proto and req_proto_len represent a byte array for a [bridge::ShutdownWorkerRequest]
272
- /// protobuf message, which currently contains nothing and are unused, but the parameters are kept
273
- /// for now.
274
- ///
275
- /// The callback is invoked on completion with a ShutdownWorkerResponse protobuf message.
276
- ///
277
- /// After the callback has been called, the worker struct will be freed and the pointer will no
278
- /// longer be valid.
279
- #[no_mangle]
280
- pub extern "C" fn tmprl_worker_shutdown(
281
- worker: *mut tmprl_worker_t,
282
- #[allow(unused_variables)] // We intentionally ignore the request
283
- req_proto: *const u8,
284
- #[allow(unused_variables)] req_proto_len: libc::size_t,
285
- user_data: *mut libc::c_void,
286
- callback: tmprl_callback,
287
- ) {
288
- let worker = unsafe { Box::from_raw(worker) };
289
- let user_data = UserDataHandle(user_data);
290
- worker.tokio_runtime.clone().spawn(async move {
291
- worker.shutdown().await;
292
- unsafe {
293
- callback(user_data.into(), &*DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES);
294
- }
295
- drop(worker);
296
- });
297
- }
298
-
299
- /// Initialize process-wide telemetry. Should only be called once, subsequent calls will be ignored
300
- /// by core.
301
- ///
302
- /// Unlike the other functions in this bridge, this blocks until initting is complete, as telemetry
303
- /// should typically be initialized before doing other work.
304
- ///
305
- /// Returns a byte array for a [InitResponse] protobuf message which must be freed via
306
- /// tmprl_bytes_free.
307
- #[no_mangle]
308
- pub extern "C" fn tmprl_telemetry_init(
309
- req_proto: *const u8,
310
- req_proto_len: libc::size_t,
311
- ) -> *const tmprl_bytes_t {
312
- let req = match tmprl_worker_t::decode_proto::<InitTelemetryRequest>(req_proto, req_proto_len) {
313
- Ok(req) => req,
314
- Err(message) => {
315
- let resp = InitResponse {
316
- error: Some(init_response::Error { message }),
317
- };
318
- return tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw();
319
- }
320
- };
321
-
322
- match wrappers::InitTelemetryRequest(req)
323
- .try_into()
324
- .map(|opts| telemetry_init(&opts))
325
- {
326
- Ok(_) => &*DEFAULT_INIT_RESPONSE_BYTES,
327
- Err(message) => {
328
- let resp = InitResponse {
329
- error: Some(init_response::Error { message }),
330
- };
331
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw()
332
- }
333
- }
334
- }
335
-
336
- /// A client instance owned by Core. This must be passed to [tmprl_client_free]
337
- /// when no longer in use which will free the resources.
338
- pub struct tmprl_client_t {
339
- client: Arc<RetryClient<Client>>,
340
- }
341
-
342
- impl tmprl_client_t {
343
- pub fn new(client: Arc<RetryClient<Client>>) -> Self {
344
- Self { client }
345
- }
346
- }
347
-
348
- /// Callback called by [tmprl_client_init] on completion. The first parameter of the
349
- /// callback is user data passed into the original function. The second
350
- /// parameter is a client instance if the call is successful or null if not. If
351
- /// present, the client instance must be freed via [tmprl_client_free] when no
352
- /// longer in use. The third parameter of the callback is a byte array for a
353
- /// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
354
- type tmprl_client_init_callback = unsafe extern "C" fn(
355
- user_data: *mut libc::c_void,
356
- client: *mut tmprl_client_t,
357
- resp: *const tmprl_bytes_t,
358
- );
359
-
360
- /// Initialize a client connection to the Temporal service.
361
- ///
362
- /// The runtime is required and must outlive this instance. The `req_proto` and `req_proto_len`
363
- /// represent a byte array for a [CreateClientRequest] protobuf message. The callback is invoked on
364
- /// completion.
365
- #[no_mangle]
366
- pub extern "C" fn tmprl_client_init(
367
- runtime: *mut tmprl_runtime_t,
368
- req_proto: *const u8,
369
- req_proto_len: libc::size_t,
370
- user_data: *mut libc::c_void,
371
- callback: tmprl_client_init_callback,
372
- ) {
373
- let runtime = unsafe { &*runtime };
374
- let (namespace, req) =
375
- match tmprl_worker_t::decode_proto::<CreateClientRequest>(req_proto, req_proto_len)
376
- .and_then(|cgr| {
377
- let ns = cgr.namespace.clone();
378
- wrappers::ClientOptions(cgr)
379
- .try_into()
380
- .map(|sgo: ClientOptions| (ns, sgo))
381
- }) {
382
- Ok(req) => req,
383
- Err(message) => {
384
- let resp = InitResponse {
385
- error: Some(init_response::Error { message }),
386
- };
387
- unsafe {
388
- callback(
389
- user_data,
390
- std::ptr::null_mut(),
391
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
392
- );
393
- }
394
- return;
395
- }
396
- };
397
-
398
- let user_data = UserDataHandle(user_data);
399
- runtime.tokio_runtime.spawn(async move {
400
- match req.connect(namespace, None, None).await {
401
- Ok(client) => unsafe {
402
- callback(
403
- user_data.into(),
404
- Box::into_raw(Box::new(tmprl_client_t::new(Arc::new(client)))),
405
- &*DEFAULT_INIT_RESPONSE_BYTES,
406
- );
407
- },
408
- Err(e) => {
409
- let resp = InitResponse {
410
- error: Some(init_response::Error {
411
- message: e.to_string(),
412
- }),
413
- };
414
- unsafe {
415
- callback(
416
- user_data.into(),
417
- std::ptr::null_mut(),
418
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
419
- );
420
- }
421
- }
422
- }
423
- });
424
- }
425
-
426
- /// Free a previously created client
427
- #[no_mangle]
428
- pub extern "C" fn tmprl_client_free(client: *mut tmprl_client_t) {
429
- unsafe { drop(Box::from_raw(client)) };
430
- }
431
-
432
- /// Poll for a workflow activation.
433
- ///
434
- /// The `req_proto` and `req_proto_len` represent a byte array for a
435
- /// [bridge::PollWorkflowActivationRequest] protobuf message, which currently contains nothing and
436
- /// is unused, but the parameters are kept for now.
437
- ///
438
- /// The callback is invoked on completion with a [bridge::PollWorkflowActivationResponse] protobuf
439
- /// message.
440
- #[no_mangle]
441
- pub extern "C" fn tmprl_poll_workflow_activation(
442
- worker: *mut tmprl_worker_t,
443
- #[allow(unused_variables)] // We intentionally ignore the request
444
- req_proto: *const u8,
445
- #[allow(unused_variables)] // We intentionally ignore the request
446
- req_proto_len: libc::size_t,
447
- user_data: *mut libc::c_void,
448
- callback: tmprl_callback,
449
- ) {
450
- let worker = unsafe { &mut *worker };
451
- let user_data = UserDataHandle(user_data);
452
- worker.tokio_runtime.clone().spawn(async move {
453
- let resp = bridge::PollWorkflowActivationResponse {
454
- response: Some(match worker.poll_workflow_activation().await {
455
- Ok(act) => bridge::poll_workflow_activation_response::Response::Activation(act),
456
- Err(err) => bridge::poll_workflow_activation_response::Response::Error(err),
457
- }),
458
- };
459
- unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
460
- });
461
- }
462
-
463
- /// Poll for an activity task.
464
- ///
465
- /// The `req_proto` and `req_proto_len` represent a byte array for a
466
- /// [bridge::PollActivityTaskRequest] protobuf message, which currently contains nothing and is
467
- /// unused, but the parameters are kept for now.
468
- ///
469
- /// The callback is invoked on completion with a [bridge::PollActivityTaskResponse] protobuf
470
- /// message.
471
- #[no_mangle]
472
- pub extern "C" fn tmprl_poll_activity_task(
473
- worker: *mut tmprl_worker_t,
474
- #[allow(unused_variables)] // We intentionally ignore the request
475
- req_proto: *const u8,
476
- #[allow(unused_variables)] // We intentionally ignore the request
477
- req_proto_len: libc::size_t,
478
- user_data: *mut libc::c_void,
479
- callback: tmprl_callback,
480
- ) {
481
- let worker = unsafe { &mut *worker };
482
- let user_data = UserDataHandle(user_data);
483
- worker.tokio_runtime.clone().spawn(async move {
484
- let resp = bridge::PollActivityTaskResponse {
485
- response: Some(match worker.poll_activity_task().await {
486
- Ok(task) => bridge::poll_activity_task_response::Response::Task(task),
487
- Err(err) => bridge::poll_activity_task_response::Response::Error(err),
488
- }),
489
- };
490
- unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
491
- });
492
- }
493
-
494
- /// Complete a workflow activation.
495
- ///
496
- /// The `req_proto` and `req_proto_len` represent a byte array for a
497
- /// [bridge::CompleteWorkflowActivationRequest] protobuf message. The callback is invoked on
498
- /// completion with a [bridge::CompleteWorkflowActivationResponse] protobuf message.
499
- #[no_mangle]
500
- pub extern "C" fn tmprl_complete_workflow_activation(
501
- worker: *mut tmprl_worker_t,
502
- req_proto: *const u8,
503
- req_proto_len: libc::size_t,
504
- user_data: *mut libc::c_void,
505
- callback: tmprl_callback,
506
- ) {
507
- let worker = unsafe { &mut *worker };
508
- let req = match tmprl_worker_t::decode_proto::<bridge::CompleteWorkflowActivationRequest>(
509
- req_proto,
510
- req_proto_len,
511
- ) {
512
- Ok(req) => req,
513
- Err(message) => {
514
- let resp = bridge::CompleteWorkflowActivationResponse {
515
- error: Some(bridge::complete_workflow_activation_response::Error { message }),
516
- };
517
- unsafe {
518
- callback(user_data, worker.encode_proto(&resp).into_raw());
519
- }
520
- return;
521
- }
522
- };
523
- let user_data = UserDataHandle(user_data);
524
- worker.tokio_runtime.clone().spawn(async move {
525
- match worker.complete_workflow_activation(req).await {
526
- Ok(()) => unsafe {
527
- callback(
528
- user_data.into(),
529
- &*DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES,
530
- );
531
- },
532
- Err(err) => {
533
- let resp = bridge::CompleteWorkflowActivationResponse { error: Some(err) };
534
- unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
535
- }
536
- }
537
- });
538
- }
539
-
540
- /// Complete an activity task.
541
- ///
542
- /// The `req_proto` and `req_proto_len` represent a byte array for a
543
- /// [bridge::CompleteActivityTaskRequest] protobuf message. The callback is invoked on completion
544
- /// with a [bridge::CompleteActivityTaskResponse] protobuf message.
545
- #[no_mangle]
546
- pub extern "C" fn tmprl_complete_activity_task(
547
- worker: *mut tmprl_worker_t,
548
- req_proto: *const u8,
549
- req_proto_len: libc::size_t,
550
- user_data: *mut libc::c_void,
551
- callback: tmprl_callback,
552
- ) {
553
- let worker = unsafe { &mut *worker };
554
- let req = match tmprl_worker_t::decode_proto::<bridge::CompleteActivityTaskRequest>(
555
- req_proto,
556
- req_proto_len,
557
- ) {
558
- Ok(req) => req,
559
- Err(message) => {
560
- let resp = bridge::CompleteActivityTaskResponse {
561
- error: Some(bridge::complete_activity_task_response::Error { message }),
562
- };
563
- unsafe {
564
- callback(user_data, worker.encode_proto(&resp).into_raw());
565
- }
566
- return;
567
- }
568
- };
569
- let user_data = UserDataHandle(user_data);
570
- worker.tokio_runtime.clone().spawn(async move {
571
- match worker.complete_activity_task(req).await {
572
- Ok(()) => unsafe {
573
- callback(
574
- user_data.into(),
575
- &*DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES,
576
- );
577
- },
578
- Err(err) => {
579
- let resp = bridge::CompleteActivityTaskResponse { error: Some(err) };
580
- unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
581
- }
582
- }
583
- });
584
- }
585
-
586
- /// Record an activity heartbeat.
587
- ///
588
- /// `req_proto` and `req_proto_len` represent a byte array for a
589
- /// [bridge::RecordActivityHeartbeatRequest] protobuf message. The callback is invoked on completion
590
- /// with a RecordActivityHeartbeatResponse protobuf message.
591
- #[no_mangle]
592
- pub extern "C" fn tmprl_record_activity_heartbeat(
593
- worker: *mut tmprl_worker_t,
594
- req_proto: *const u8,
595
- req_proto_len: libc::size_t,
596
- user_data: *mut libc::c_void,
597
- callback: tmprl_callback,
598
- ) {
599
- let worker = unsafe { &mut *worker };
600
- let req = match tmprl_worker_t::decode_proto::<bridge::RecordActivityHeartbeatRequest>(
601
- req_proto,
602
- req_proto_len,
603
- ) {
604
- Ok(req) => req,
605
- Err(message) => {
606
- let resp = bridge::RecordActivityHeartbeatResponse {
607
- error: Some(bridge::record_activity_heartbeat_response::Error { message }),
608
- };
609
- unsafe {
610
- callback(user_data, worker.encode_proto(&resp).into_raw());
611
- }
612
- return;
613
- }
614
- };
615
- let user_data = UserDataHandle(user_data);
616
- // We intentionally spawn even though the core call is not async so the
617
- // callback can be made in the tokio runtime
618
- worker.tokio_runtime.clone().spawn(async move {
619
- worker.record_activity_heartbeat(req);
620
- unsafe {
621
- callback(
622
- user_data.into(),
623
- &*DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES,
624
- );
625
- }
626
- });
627
- }
628
-
629
- /// Request a workflow eviction.
630
- ///
631
- /// The `req_proto` and `req_proto_len` represent a byte array for a
632
- /// [bridge::RequestWorkflowEvictionRequest] protobuf message. The callback is invoked on completion
633
- /// with a [bridge::RequestWorkflowEvictionResponse] protobuf message.
634
- #[no_mangle]
635
- pub extern "C" fn tmprl_request_workflow_eviction(
636
- worker: *mut tmprl_worker_t,
637
- req_proto: *const u8,
638
- req_proto_len: libc::size_t,
639
- user_data: *mut libc::c_void,
640
- callback: tmprl_callback,
641
- ) {
642
- let worker = unsafe { &mut *worker };
643
- let req = match tmprl_worker_t::decode_proto::<bridge::RequestWorkflowEvictionRequest>(
644
- req_proto,
645
- req_proto_len,
646
- ) {
647
- Ok(req) => req,
648
- Err(message) => {
649
- let resp = bridge::RequestWorkflowEvictionResponse {
650
- error: Some(bridge::request_workflow_eviction_response::Error { message }),
651
- };
652
- unsafe {
653
- callback(user_data, worker.encode_proto(&resp).into_raw());
654
- }
655
- return;
656
- }
657
- };
658
- let user_data = UserDataHandle(user_data);
659
- // We intentionally spawn even though the core call is not async so the
660
- // callback can be made in the tokio runtime
661
- worker.tokio_runtime.clone().spawn(async move {
662
- worker.request_workflow_eviction(req);
663
- unsafe {
664
- callback(
665
- user_data.into(),
666
- &*DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES,
667
- );
668
- }
669
- });
670
- }
671
-
672
- /// Fetch buffered logs. Blocks until complete. This is still using the callback since we might
673
- /// reasonably change log fetching to be async in the future.
674
- ///
675
- /// The `req_proto` and `req_proto_len` represent a byte array for a
676
- /// [bridge::FetchBufferedLogsRequest] protobuf message. The callback is invoked on completion with
677
- /// a [bridge::FetchBufferedLogsResponse] protobuf message.
678
- #[no_mangle]
679
- pub extern "C" fn tmprl_fetch_buffered_logs(
680
- #[allow(unused_variables)] // We intentionally ignore the request
681
- req_proto: *const u8,
682
- #[allow(unused_variables)] req_proto_len: libc::size_t,
683
- user_data: *mut libc::c_void,
684
- callback: tmprl_callback,
685
- ) {
686
- let user_data = UserDataHandle(user_data);
687
- // We intentionally spawn even though the core call is not async so the
688
- // callback can be made in the tokio runtime
689
- let resp = bridge::FetchBufferedLogsResponse {
690
- entries: fetch_global_buffered_logs()
691
- .into_iter()
692
- .map(|log| bridge::fetch_buffered_logs_response::LogEntry {
693
- message: log.message,
694
- timestamp: Some(log.timestamp.into()),
695
- level: match log.level {
696
- log::Level::Error => bridge::LogLevel::Error.into(),
697
- log::Level::Warn => bridge::LogLevel::Warn.into(),
698
- log::Level::Info => bridge::LogLevel::Info.into(),
699
- log::Level::Debug => bridge::LogLevel::Debug.into(),
700
- log::Level::Trace => bridge::LogLevel::Trace.into(),
701
- },
702
- })
703
- .collect(),
704
- };
705
-
706
- unsafe {
707
- callback(
708
- user_data.into(),
709
- // TODO: Creates vec every time since no worker/core instance. Can be fixed with a
710
- // pool if optimizations needed.
711
- tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
712
- )
713
- };
714
- }
715
-
716
- impl tmprl_worker_t {
717
- fn new(
718
- tokio_runtime: Arc<tokio::runtime::Runtime>,
719
- client: Arc<RetryClient<Client>>,
720
- opts: wrappers::WorkerConfig,
721
- ) -> Result<tmprl_worker_t, String> {
722
- Ok(tmprl_worker_t {
723
- tokio_runtime,
724
- worker: Arc::new(temporal_sdk_core::init_worker(opts.try_into()?, client)),
725
- })
726
- }
727
-
728
- async fn shutdown(&self) {
729
- self.worker.shutdown().await;
730
- }
731
-
732
- async fn poll_workflow_activation(
733
- &self,
734
- ) -> Result<
735
- temporal_sdk_core_protos::coresdk::workflow_activation::WorkflowActivation,
736
- bridge::poll_workflow_activation_response::Error,
737
- > {
738
- self.worker.poll_workflow_activation().await.map_err(|err| {
739
- bridge::poll_workflow_activation_response::Error {
740
- message: format!("{}", err),
741
- shutdown: matches!(err, temporal_sdk_core_api::errors::PollWfError::ShutDown),
742
- }
743
- })
744
- }
745
-
746
- async fn poll_activity_task(
747
- &self,
748
- ) -> Result<
749
- temporal_sdk_core_protos::coresdk::activity_task::ActivityTask,
750
- bridge::poll_activity_task_response::Error,
751
- > {
752
- self.worker.poll_activity_task().await.map_err(|err| {
753
- bridge::poll_activity_task_response::Error {
754
- message: format!("{}", err),
755
- shutdown: matches!(
756
- err,
757
- temporal_sdk_core_api::errors::PollActivityError::ShutDown
758
- ),
759
- }
760
- })
761
- }
762
-
763
- async fn complete_workflow_activation(
764
- &self,
765
- req: bridge::CompleteWorkflowActivationRequest,
766
- ) -> Result<(), bridge::complete_workflow_activation_response::Error> {
767
- self.worker
768
- .complete_workflow_activation(req.completion.unwrap_or_default())
769
- .await
770
- .map_err(|err| bridge::complete_workflow_activation_response::Error {
771
- message: format!("{}", err),
772
- })
773
- }
774
-
775
- async fn complete_activity_task(
776
- &self,
777
- req: bridge::CompleteActivityTaskRequest,
778
- ) -> Result<(), bridge::complete_activity_task_response::Error> {
779
- self.worker
780
- .complete_activity_task(req.completion.unwrap_or_default())
781
- .await
782
- .map_err(|err| bridge::complete_activity_task_response::Error {
783
- message: format!("{}", err),
784
- })
785
- }
786
-
787
- fn record_activity_heartbeat(&self, req: bridge::RecordActivityHeartbeatRequest) {
788
- self.worker
789
- .record_activity_heartbeat(req.heartbeat.unwrap_or_default());
790
- }
791
-
792
- fn request_workflow_eviction(&self, req: bridge::RequestWorkflowEvictionRequest) {
793
- self.worker.request_workflow_eviction(&req.run_id);
794
- }
795
-
796
- fn borrow_buf(&mut self) -> Vec<u8> {
797
- // We currently do not use a thread-safe byte pool, but if wanted, it
798
- // can be added here
799
- Vec::new()
800
- }
801
-
802
- fn return_buf(&mut self, _vec: Vec<u8>) {
803
- // We currently do not use a thread-safe byte pool, but if wanted, it
804
- // can be added here
805
- }
806
-
807
- fn encode_proto(&mut self, proto: &impl prost::Message) -> tmprl_bytes_t {
808
- let mut buf = self.borrow_buf();
809
- buf.clear();
810
- // Increase buf capacity if needed
811
- buf.reserve(proto.encoded_len());
812
- // Only fails if size not big enough which can't happen in our case
813
- proto.encode(&mut buf).unwrap();
814
- tmprl_bytes_t::from_vec(buf)
815
- }
816
-
817
- fn decode_proto<P>(bytes: *const u8, bytes_len: libc::size_t) -> Result<P, String>
818
- where
819
- P: prost::Message,
820
- P: Default,
821
- {
822
- P::decode(unsafe { std::slice::from_raw_parts(bytes, bytes_len) })
823
- .map_err(|err| format!("failed decoding proto: {}", err))
824
- }
825
- }