@temporalio/core-bridge 1.14.2-canary-release-testing.0 → 1.16.0

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 (233) hide show
  1. package/Cargo.lock +794 -650
  2. package/bridge-macros/src/derive_tryintojs.rs +40 -0
  3. package/lib/native.d.ts +24 -3
  4. package/package.json +4 -4
  5. package/releases/aarch64-apple-darwin/index.node +0 -0
  6. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  7. package/releases/x86_64-apple-darwin/index.node +0 -0
  8. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  9. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  10. package/sdk-core/.github/workflows/per-pr.yml +6 -6
  11. package/sdk-core/AGENTS.md +42 -31
  12. package/sdk-core/Cargo.toml +4 -1
  13. package/sdk-core/README.md +19 -13
  14. package/sdk-core/crates/client/Cargo.toml +4 -0
  15. package/sdk-core/crates/client/README.md +139 -0
  16. package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
  17. package/sdk-core/crates/client/src/callback_based.rs +7 -0
  18. package/sdk-core/crates/client/src/errors.rs +294 -0
  19. package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +370 -159
  20. package/sdk-core/crates/client/src/lib.rs +920 -1326
  21. package/sdk-core/crates/client/src/metrics.rs +24 -33
  22. package/sdk-core/crates/client/src/options_structs.rs +457 -0
  23. package/sdk-core/crates/client/src/replaceable.rs +5 -4
  24. package/sdk-core/crates/client/src/request_extensions.rs +8 -9
  25. package/sdk-core/crates/client/src/retry.rs +99 -54
  26. package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +104 -29
  27. package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
  28. package/sdk-core/crates/common/Cargo.toml +62 -3
  29. package/sdk-core/crates/common/build.rs +742 -12
  30. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
  31. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/create-release.yml +0 -5
  32. package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
  33. package/sdk-core/crates/common/protos/api_upstream/README.md +8 -0
  34. package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
  35. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +3329 -2647
  36. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +2734 -708
  37. package/sdk-core/crates/common/protos/api_upstream/temporal/api/activity/v1/message.proto +155 -3
  38. package/sdk-core/crates/common/protos/api_upstream/temporal/api/command/v1/message.proto +26 -0
  39. package/sdk-core/crates/common/protos/api_upstream/temporal/api/common/v1/message.proto +8 -1
  40. package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +27 -1
  41. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/activity.proto +81 -0
  42. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -0
  43. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +4 -0
  44. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +15 -0
  45. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +63 -15
  46. package/sdk-core/crates/common/protos/api_upstream/temporal/api/errordetails/v1/message.proto +8 -0
  47. package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
  48. package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +111 -17
  49. package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +21 -0
  50. package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +20 -1
  51. package/sdk-core/crates/common/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +4 -0
  52. package/sdk-core/crates/common/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
  53. package/sdk-core/crates/common/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -0
  54. package/sdk-core/crates/common/protos/api_upstream/temporal/api/worker/v1/message.proto +4 -7
  55. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflow/v1/message.proto +80 -22
  56. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +347 -23
  57. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +242 -43
  58. package/sdk-core/crates/common/protos/local/temporal/sdk/core/core_interface.proto +15 -0
  59. package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +9 -2
  60. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +8 -0
  61. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +22 -5
  62. package/sdk-core/crates/common/src/activity_definition.rs +20 -0
  63. package/sdk-core/crates/common/src/data_converters.rs +770 -0
  64. package/sdk-core/crates/common/src/envconfig.rs +5 -0
  65. package/sdk-core/crates/common/src/lib.rs +15 -211
  66. package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
  67. package/sdk-core/crates/common/src/priority.rs +110 -0
  68. package/sdk-core/crates/common/src/protos/canned_histories.rs +19 -0
  69. package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
  70. package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
  71. package/sdk-core/crates/common/src/protos/mod.rs +134 -27
  72. package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
  73. package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
  74. package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +11 -16
  75. package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
  76. package/sdk-core/crates/common/src/telemetry/metrics.rs +272 -225
  77. package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
  78. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
  79. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
  80. package/sdk-core/crates/common/src/telemetry.rs +278 -19
  81. package/sdk-core/crates/common/src/worker.rs +68 -636
  82. package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
  83. package/sdk-core/crates/macros/Cargo.toml +5 -1
  84. package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
  85. package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
  86. package/sdk-core/crates/macros/src/lib.rs +138 -512
  87. package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
  88. package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
  89. package/sdk-core/crates/sdk/Cargo.toml +19 -6
  90. package/sdk-core/crates/sdk/README.md +415 -0
  91. package/sdk-core/crates/sdk/src/activities.rs +417 -0
  92. package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
  93. package/sdk-core/crates/sdk/src/lib.rs +759 -442
  94. package/sdk-core/crates/sdk/src/workflow_context/options.rs +64 -35
  95. package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
  96. package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
  97. package/sdk-core/crates/sdk/src/workflows.rs +711 -0
  98. package/sdk-core/crates/sdk-core/Cargo.toml +59 -65
  99. package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +45 -54
  100. package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
  101. package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
  102. package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
  103. package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +22 -21
  104. package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
  105. package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
  106. package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
  107. package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +647 -27
  108. package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +46 -41
  109. package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +13 -16
  110. package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
  111. package/sdk-core/crates/sdk-core/src/lib.rs +60 -123
  112. package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
  113. package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +411 -32
  114. package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
  115. package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
  116. package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +183 -198
  117. package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -281
  118. package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +35 -16
  119. package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
  120. package/sdk-core/crates/sdk-core/src/worker/activities/activity_heartbeat_manager.rs +1 -0
  121. package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
  122. package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
  123. package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +11 -5
  124. package/sdk-core/crates/sdk-core/src/worker/client.rs +104 -86
  125. package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +10 -14
  126. package/sdk-core/crates/sdk-core/src/worker/mod.rs +1175 -241
  127. package/sdk-core/crates/sdk-core/src/worker/nexus.rs +150 -23
  128. package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
  129. package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
  130. package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +25 -27
  131. package/sdk-core/crates/sdk-core/src/worker/tuner.rs +64 -44
  132. package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
  133. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/patch_state_machine.rs +5 -8
  134. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
  135. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +28 -4
  136. package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +20 -41
  137. package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +50 -9
  138. package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
  139. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
  140. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
  141. package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
  142. package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
  143. package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
  144. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
  145. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
  146. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
  147. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
  148. package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
  149. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
  150. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
  151. package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
  152. package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
  153. package/sdk-core/crates/sdk-core/tests/common/mod.rs +281 -236
  154. package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
  155. package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +9 -14
  156. package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -66
  157. package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +306 -268
  158. package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
  159. package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
  160. package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
  161. package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +37 -38
  162. package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +49 -40
  163. package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +447 -300
  164. package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
  165. package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +157 -157
  166. package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
  167. package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -463
  168. package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
  169. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +389 -265
  170. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +250 -185
  171. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -49
  172. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
  173. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +437 -327
  174. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -58
  175. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -30
  176. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -251
  177. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
  178. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +110 -46
  179. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -149
  180. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -32
  181. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1040
  182. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -43
  183. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +402 -245
  184. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +343 -207
  185. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
  186. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
  187. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +155 -140
  188. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -113
  189. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -44
  190. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -48
  191. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -56
  192. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +365 -242
  193. package/sdk-core/crates/sdk-core/tests/main.rs +22 -16
  194. package/sdk-core/crates/sdk-core/tests/manual_tests.rs +233 -187
  195. package/sdk-core/crates/sdk-core/tests/runner.rs +4 -6
  196. package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +73 -27
  197. package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
  198. package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
  199. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
  200. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
  201. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
  202. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
  203. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
  204. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
  205. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
  206. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
  207. package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +8 -1
  208. package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +37 -26
  209. package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +180 -87
  210. package/sdk-core/crates/sdk-core-c-bridge/src/lib.rs +89 -5
  211. package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +10 -16
  212. package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +59 -67
  213. package/sdk-core/crates/sdk-core-c-bridge/src/testing.rs +10 -10
  214. package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +57 -22
  215. package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +108 -12
  216. package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +9 -52
  217. package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +74 -91
  218. package/sdk-core/rustfmt.toml +2 -1
  219. package/src/client.rs +206 -289
  220. package/src/helpers/try_into_js.rs +88 -2
  221. package/src/metrics.rs +277 -35
  222. package/src/runtime.rs +94 -45
  223. package/src/testing.rs +9 -16
  224. package/src/worker.rs +86 -68
  225. package/ts/native.ts +39 -3
  226. package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
  227. package/sdk-core/crates/common/src/errors.rs +0 -85
  228. package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
  229. package/sdk-core/crates/macros/LICENSE.txt +0 -21
  230. package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
  231. package/sdk-core/crates/sdk/src/app_data.rs +0 -37
  232. package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
  233. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
@@ -0,0 +1,297 @@
1
+ //! Handle for completing activities asynchronously via a client.
2
+
3
+ use crate::{NamespacedClient, errors::AsyncActivityError, grpc::WorkflowService};
4
+ use temporalio_common::protos::{
5
+ TaskToken,
6
+ temporal::api::{
7
+ common::v1::Payloads,
8
+ failure::v1::Failure,
9
+ workflowservice::v1::{
10
+ RecordActivityTaskHeartbeatByIdRequest, RecordActivityTaskHeartbeatByIdResponse,
11
+ RecordActivityTaskHeartbeatRequest, RecordActivityTaskHeartbeatResponse,
12
+ RespondActivityTaskCanceledByIdRequest, RespondActivityTaskCanceledRequest,
13
+ RespondActivityTaskCompletedByIdRequest, RespondActivityTaskCompletedRequest,
14
+ RespondActivityTaskFailedByIdRequest, RespondActivityTaskFailedRequest,
15
+ },
16
+ },
17
+ };
18
+ use tonic::IntoRequest;
19
+
20
+ /// Identifies an async activity for completion outside a worker.
21
+ #[derive(Debug, Clone)]
22
+ pub enum ActivityIdentifier {
23
+ /// Identify activity by its task token
24
+ TaskToken(TaskToken),
25
+ /// Identify activity by workflow and activity IDs.
26
+ ById {
27
+ /// ID of the workflow that scheduled this activity.
28
+ workflow_id: String,
29
+ /// Run ID of the workflow (optional - if not provided, targets the latest run).
30
+ run_id: String,
31
+ /// ID of the activity to complete.
32
+ activity_id: String,
33
+ },
34
+ }
35
+
36
+ impl ActivityIdentifier {
37
+ /// Create an identifier from a task token.
38
+ pub fn from_task_token(token: TaskToken) -> Self {
39
+ Self::TaskToken(token)
40
+ }
41
+
42
+ /// Create an identifier from workflow and activity IDs. Use an empty run id to target the
43
+ /// latest workflow execution.
44
+ pub fn by_id(
45
+ workflow_id: impl Into<String>,
46
+ run_id: impl Into<String>,
47
+ activity_id: impl Into<String>,
48
+ ) -> Self {
49
+ Self::ById {
50
+ workflow_id: workflow_id.into(),
51
+ run_id: run_id.into(),
52
+ activity_id: activity_id.into(),
53
+ }
54
+ }
55
+ }
56
+
57
+ /// Handle for completing activities asynchronously (outside the worker).
58
+ pub struct AsyncActivityHandle<CT> {
59
+ client: CT,
60
+ identifier: ActivityIdentifier,
61
+ }
62
+
63
+ impl<CT> AsyncActivityHandle<CT> {
64
+ /// Create a new async activity handle.
65
+ pub fn new(client: CT, identifier: ActivityIdentifier) -> Self {
66
+ Self { client, identifier }
67
+ }
68
+
69
+ /// Get the identifier for this activity.
70
+ pub fn identifier(&self) -> &ActivityIdentifier {
71
+ &self.identifier
72
+ }
73
+
74
+ /// Get a reference to the underlying client.
75
+ pub fn client(&self) -> &CT {
76
+ &self.client
77
+ }
78
+ }
79
+
80
+ impl<CT: WorkflowService + NamespacedClient + Clone> AsyncActivityHandle<CT> {
81
+ /// Complete the activity with a successful result.
82
+ pub async fn complete(&self, result: Option<Payloads>) -> Result<(), AsyncActivityError> {
83
+ match &self.identifier {
84
+ ActivityIdentifier::TaskToken(token) => {
85
+ WorkflowService::respond_activity_task_completed(
86
+ &mut self.client.clone(),
87
+ RespondActivityTaskCompletedRequest {
88
+ task_token: token.0.clone(),
89
+ result,
90
+ identity: self.client.identity(),
91
+ namespace: self.client.namespace(),
92
+ ..Default::default()
93
+ }
94
+ .into_request(),
95
+ )
96
+ .await
97
+ .map_err(AsyncActivityError::from_status)?;
98
+ }
99
+ ActivityIdentifier::ById {
100
+ workflow_id,
101
+ run_id,
102
+ activity_id,
103
+ } => {
104
+ WorkflowService::respond_activity_task_completed_by_id(
105
+ &mut self.client.clone(),
106
+ RespondActivityTaskCompletedByIdRequest {
107
+ namespace: self.client.namespace(),
108
+ workflow_id: workflow_id.clone(),
109
+ run_id: run_id.clone(),
110
+ activity_id: activity_id.clone(),
111
+ result,
112
+ identity: self.client.identity(),
113
+ }
114
+ .into_request(),
115
+ )
116
+ .await
117
+ .map_err(AsyncActivityError::from_status)?;
118
+ }
119
+ }
120
+ Ok(())
121
+ }
122
+
123
+ /// Fail the activity with a failure.
124
+ pub async fn fail(
125
+ &self,
126
+ failure: Failure,
127
+ last_heartbeat_details: Option<Payloads>,
128
+ ) -> Result<(), AsyncActivityError> {
129
+ match &self.identifier {
130
+ ActivityIdentifier::TaskToken(token) => {
131
+ WorkflowService::respond_activity_task_failed(
132
+ &mut self.client.clone(),
133
+ RespondActivityTaskFailedRequest {
134
+ task_token: token.0.clone(),
135
+ failure: Some(failure),
136
+ identity: self.client.identity(),
137
+ namespace: self.client.namespace(),
138
+ last_heartbeat_details,
139
+ ..Default::default()
140
+ }
141
+ .into_request(),
142
+ )
143
+ .await
144
+ .map_err(AsyncActivityError::from_status)?;
145
+ }
146
+ ActivityIdentifier::ById {
147
+ workflow_id,
148
+ run_id,
149
+ activity_id,
150
+ } => {
151
+ WorkflowService::respond_activity_task_failed_by_id(
152
+ &mut self.client.clone(),
153
+ RespondActivityTaskFailedByIdRequest {
154
+ namespace: self.client.namespace(),
155
+ workflow_id: workflow_id.clone(),
156
+ run_id: run_id.clone(),
157
+ activity_id: activity_id.clone(),
158
+ failure: Some(failure),
159
+ identity: self.client.identity(),
160
+ last_heartbeat_details,
161
+ }
162
+ .into_request(),
163
+ )
164
+ .await
165
+ .map_err(AsyncActivityError::from_status)?;
166
+ }
167
+ }
168
+ Ok(())
169
+ }
170
+
171
+ /// Reports the activity as canceled.
172
+ pub async fn report_cancelation(
173
+ &self,
174
+ details: Option<Payloads>,
175
+ ) -> Result<(), AsyncActivityError> {
176
+ match &self.identifier {
177
+ ActivityIdentifier::TaskToken(token) => {
178
+ WorkflowService::respond_activity_task_canceled(
179
+ &mut self.client.clone(),
180
+ RespondActivityTaskCanceledRequest {
181
+ task_token: token.0.clone(),
182
+ details,
183
+ identity: self.client.identity(),
184
+ namespace: self.client.namespace(),
185
+ ..Default::default()
186
+ }
187
+ .into_request(),
188
+ )
189
+ .await
190
+ .map_err(AsyncActivityError::from_status)?;
191
+ }
192
+ ActivityIdentifier::ById {
193
+ workflow_id,
194
+ run_id,
195
+ activity_id,
196
+ } => {
197
+ WorkflowService::respond_activity_task_canceled_by_id(
198
+ &mut self.client.clone(),
199
+ RespondActivityTaskCanceledByIdRequest {
200
+ namespace: self.client.namespace(),
201
+ workflow_id: workflow_id.clone(),
202
+ run_id: run_id.clone(),
203
+ activity_id: activity_id.clone(),
204
+ details,
205
+ identity: self.client.identity(),
206
+ ..Default::default()
207
+ }
208
+ .into_request(),
209
+ )
210
+ .await
211
+ .map_err(AsyncActivityError::from_status)?;
212
+ }
213
+ }
214
+ Ok(())
215
+ }
216
+
217
+ /// Record a heartbeat for the activity.
218
+ ///
219
+ /// Heartbeats let the server know the activity is still running and can carry
220
+ /// progress information. The response indicates if cancellation has been requested.
221
+ pub async fn heartbeat(
222
+ &self,
223
+ details: Option<Payloads>,
224
+ ) -> Result<ActivityHeartbeatResponse, AsyncActivityError> {
225
+ match &self.identifier {
226
+ ActivityIdentifier::TaskToken(token) => {
227
+ let resp = WorkflowService::record_activity_task_heartbeat(
228
+ &mut self.client.clone(),
229
+ RecordActivityTaskHeartbeatRequest {
230
+ task_token: token.0.clone(),
231
+ details,
232
+ identity: self.client.identity(),
233
+ namespace: self.client.namespace(),
234
+ }
235
+ .into_request(),
236
+ )
237
+ .await
238
+ .map_err(AsyncActivityError::from_status)?
239
+ .into_inner();
240
+ Ok(ActivityHeartbeatResponse::from(resp))
241
+ }
242
+ ActivityIdentifier::ById {
243
+ workflow_id,
244
+ run_id,
245
+ activity_id,
246
+ } => {
247
+ let resp = WorkflowService::record_activity_task_heartbeat_by_id(
248
+ &mut self.client.clone(),
249
+ RecordActivityTaskHeartbeatByIdRequest {
250
+ namespace: self.client.namespace(),
251
+ workflow_id: workflow_id.clone(),
252
+ run_id: run_id.clone(),
253
+ activity_id: activity_id.clone(),
254
+ details,
255
+ identity: self.client.identity(),
256
+ }
257
+ .into_request(),
258
+ )
259
+ .await
260
+ .map_err(AsyncActivityError::from_status)?
261
+ .into_inner();
262
+ Ok(ActivityHeartbeatResponse::from(resp))
263
+ }
264
+ }
265
+ }
266
+ }
267
+
268
+ /// Response from a heartbeat call.
269
+ #[derive(Debug, Clone)]
270
+ pub struct ActivityHeartbeatResponse {
271
+ /// True if the activity has been asked to cancel itself.
272
+ pub cancel_requested: bool,
273
+ /// True if the activity is paused.
274
+ pub activity_paused: bool,
275
+ /// True if the activity was reset.
276
+ pub activity_reset: bool,
277
+ }
278
+
279
+ impl From<RecordActivityTaskHeartbeatResponse> for ActivityHeartbeatResponse {
280
+ fn from(resp: RecordActivityTaskHeartbeatResponse) -> Self {
281
+ Self {
282
+ cancel_requested: resp.cancel_requested,
283
+ activity_paused: resp.activity_paused,
284
+ activity_reset: resp.activity_reset,
285
+ }
286
+ }
287
+ }
288
+
289
+ impl From<RecordActivityTaskHeartbeatByIdResponse> for ActivityHeartbeatResponse {
290
+ fn from(resp: RecordActivityTaskHeartbeatByIdResponse) -> Self {
291
+ Self {
292
+ cancel_requested: resp.cancel_requested,
293
+ activity_paused: resp.activity_paused,
294
+ activity_reset: resp.activity_reset,
295
+ }
296
+ }
297
+ }
@@ -15,6 +15,7 @@ use tonic::{Status, metadata::GRPC_CONTENT_TYPE};
15
15
  use tower::Service;
16
16
 
17
17
  /// gRPC request for use by a callback.
18
+ #[derive(Debug)]
18
19
  pub struct GrpcRequest {
19
20
  /// Fully qualified gRPC service name.
20
21
  pub service: String,
@@ -27,6 +28,7 @@ pub struct GrpcRequest {
27
28
  }
28
29
 
29
30
  /// Successful gRPC response returned by a callback.
31
+ #[derive(Debug)]
30
32
  pub struct GrpcSuccessResponse {
31
33
  /// Response headers.
32
34
  pub headers: HeaderMap,
@@ -46,6 +48,11 @@ pub struct CallbackBasedGrpcService {
46
48
  + Sync,
47
49
  >,
48
50
  }
51
+ impl std::fmt::Debug for CallbackBasedGrpcService {
52
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53
+ f.debug_struct("CallbackBasedGrpcService").finish()
54
+ }
55
+ }
49
56
 
50
57
  impl Service<Request<tonic::body::Body>> for CallbackBasedGrpcService {
51
58
  type Response = http::Response<tonic::body::Body>;
@@ -0,0 +1,294 @@
1
+ //! Contains errors that can be returned by clients.
2
+
3
+ use http::uri::InvalidUri;
4
+ use temporalio_common::{
5
+ data_converters::PayloadConversionError,
6
+ protos::temporal::api::{common::v1::Payload, failure::v1::Failure, query::v1::QueryRejected},
7
+ };
8
+ use tonic::Code;
9
+
10
+ /// Errors thrown while attempting to establish a connection to the server
11
+ #[derive(thiserror::Error, Debug)]
12
+ #[non_exhaustive]
13
+ pub enum ClientConnectError {
14
+ /// Invalid URI. Configuration error, fatal.
15
+ #[error("Invalid URI: {0:?}")]
16
+ InvalidUri(#[from] InvalidUri),
17
+ /// Invalid gRPC metadata headers. Configuration error.
18
+ #[error("Invalid headers: {0}")]
19
+ InvalidHeaders(#[from] InvalidHeaderError),
20
+ /// Server connection error. Crashing and restarting the worker is likely best.
21
+ #[error("Server connection error: {0:?}")]
22
+ TonicTransportError(#[from] tonic::transport::Error),
23
+ /// We couldn't successfully make the `get_system_info` call at connection time to establish
24
+ /// server capabilities / verify server is responding.
25
+ #[error("`get_system_info` call error after connection: {0:?}")]
26
+ SystemInfoCallError(tonic::Status),
27
+ }
28
+
29
+ /// Errors thrown when a gRPC metadata header is invalid.
30
+ #[derive(thiserror::Error, Debug)]
31
+ #[non_exhaustive]
32
+ pub enum InvalidHeaderError {
33
+ /// A binary header key was invalid
34
+ #[error("Invalid binary header key '{key}': {source}")]
35
+ InvalidBinaryHeaderKey {
36
+ /// The invalid key
37
+ key: String,
38
+ /// The source error from tonic
39
+ source: tonic::metadata::errors::InvalidMetadataKey,
40
+ },
41
+ /// An ASCII header key was invalid
42
+ #[error("Invalid ASCII header key '{key}': {source}")]
43
+ InvalidAsciiHeaderKey {
44
+ /// The invalid key
45
+ key: String,
46
+ /// The source error from tonic
47
+ source: tonic::metadata::errors::InvalidMetadataKey,
48
+ },
49
+ /// An ASCII header value was invalid
50
+ #[error("Invalid ASCII header value for key '{key}': {source}")]
51
+ InvalidAsciiHeaderValue {
52
+ /// The key
53
+ key: String,
54
+ /// The invalid value
55
+ value: String,
56
+ /// The source error from tonic
57
+ source: tonic::metadata::errors::InvalidMetadataValue,
58
+ },
59
+ }
60
+
61
+ /// Errors that can occur when starting a workflow.
62
+ #[derive(thiserror::Error, Debug)]
63
+ #[non_exhaustive]
64
+ pub enum WorkflowStartError {
65
+ /// The workflow already exists.
66
+ #[error("Workflow already started with run ID: {run_id:?}")]
67
+ AlreadyStarted {
68
+ /// Run ID of the already-started workflow if this was raised by the client.
69
+ run_id: Option<String>,
70
+ /// The original gRPC status from the server.
71
+ #[source]
72
+ source: tonic::Status,
73
+ },
74
+ /// Error converting the input to a payload.
75
+ #[error("Failed to serialize workflow input: {0}")]
76
+ PayloadConversion(#[from] PayloadConversionError),
77
+ /// An uncategorized rpc error from the server.
78
+ #[error("Server error: {0}")]
79
+ Rpc(#[from] tonic::Status),
80
+ }
81
+
82
+ /// Errors returned by query operations on [crate::WorkflowHandle].
83
+ #[derive(Debug, thiserror::Error)]
84
+ #[non_exhaustive]
85
+ pub enum WorkflowQueryError {
86
+ /// The workflow was not found.
87
+ #[error("Workflow not found")]
88
+ NotFound(#[source] tonic::Status),
89
+
90
+ /// The query was rejected based on the rejection condition.
91
+ #[error("Query rejected: workflow status {:?}", .0.status)]
92
+ Rejected(QueryRejected),
93
+
94
+ /// Error serializing input or deserializing output.
95
+ #[error("Payload conversion error: {0}")]
96
+ PayloadConversion(#[from] PayloadConversionError),
97
+
98
+ /// An uncategorized RPC error from the server.
99
+ #[error("Server error: {0}")]
100
+ Rpc(tonic::Status),
101
+
102
+ /// Other errors.
103
+ #[error(transparent)]
104
+ Other(#[from] Box<dyn std::error::Error + Send + Sync>),
105
+ }
106
+
107
+ impl WorkflowQueryError {
108
+ pub(crate) fn from_status(status: tonic::Status) -> Self {
109
+ if status.code() == Code::NotFound {
110
+ Self::NotFound(status)
111
+ } else {
112
+ Self::Rpc(status)
113
+ }
114
+ }
115
+ }
116
+
117
+ /// Errors returned by update operations on [crate::WorkflowHandle].
118
+ #[derive(Debug, thiserror::Error)]
119
+ #[non_exhaustive]
120
+ pub enum WorkflowUpdateError {
121
+ /// The workflow was not found.
122
+ #[error("Workflow not found")]
123
+ NotFound(#[source] tonic::Status),
124
+
125
+ /// The update failed with an application-level failure.
126
+ #[error("Update failed: {0:?}")]
127
+ Failed(Box<Failure>),
128
+
129
+ /// Error serializing input or deserializing output.
130
+ #[error("Payload conversion error: {0}")]
131
+ PayloadConversion(#[from] PayloadConversionError),
132
+
133
+ /// An uncategorized RPC error from the server.
134
+ #[error("Server error: {0}")]
135
+ Rpc(tonic::Status),
136
+
137
+ /// Other errors.
138
+ #[error(transparent)]
139
+ Other(#[from] Box<dyn std::error::Error + Send + Sync>),
140
+ }
141
+
142
+ impl WorkflowUpdateError {
143
+ pub(crate) fn from_status(status: tonic::Status) -> Self {
144
+ if status.code() == Code::NotFound {
145
+ Self::NotFound(status)
146
+ } else {
147
+ Self::Rpc(status)
148
+ }
149
+ }
150
+ }
151
+
152
+ /// Errors returned by workflow get_result operations.
153
+ #[derive(Debug, thiserror::Error)]
154
+ #[non_exhaustive]
155
+ pub enum WorkflowGetResultError {
156
+ /// The workflow finished in failure.
157
+ #[error("Workflow failed: {0:?}")]
158
+ Failed(Box<Failure>),
159
+
160
+ /// The workflow was cancelled.
161
+ #[error("Workflow cancelled")]
162
+ Cancelled {
163
+ /// Details provided at cancellation time.
164
+ details: Vec<Payload>,
165
+ },
166
+
167
+ /// The workflow was terminated.
168
+ #[error("Workflow terminated")]
169
+ Terminated {
170
+ /// Details provided at termination time.
171
+ details: Vec<Payload>,
172
+ },
173
+
174
+ /// The workflow timed out.
175
+ #[error("Workflow timed out")]
176
+ TimedOut,
177
+
178
+ /// The workflow continued as new.
179
+ #[error("Workflow continued as new")]
180
+ ContinuedAsNew,
181
+
182
+ /// The workflow was not found.
183
+ #[error("Workflow not found")]
184
+ NotFound(#[source] tonic::Status),
185
+
186
+ /// Error serializing input or deserializing output.
187
+ #[error("Payload conversion error: {0}")]
188
+ PayloadConversion(#[from] PayloadConversionError),
189
+
190
+ /// An uncategorized RPC error from the server.
191
+ #[error("Server error: {0}")]
192
+ Rpc(tonic::Status),
193
+
194
+ /// Other errors.
195
+ #[error(transparent)]
196
+ Other(#[from] Box<dyn std::error::Error + Send + Sync>),
197
+ }
198
+
199
+ impl From<WorkflowInteractionError> for WorkflowGetResultError {
200
+ fn from(err: WorkflowInteractionError) -> Self {
201
+ match err {
202
+ WorkflowInteractionError::NotFound(s) => Self::NotFound(s),
203
+ WorkflowInteractionError::PayloadConversion(e) => Self::PayloadConversion(e),
204
+ WorkflowInteractionError::Rpc(s) => Self::Rpc(s),
205
+ WorkflowInteractionError::Other(e) => Self::Other(e),
206
+ }
207
+ }
208
+ }
209
+
210
+ impl WorkflowGetResultError {
211
+ /// Returns `true` if this error represents a workflow-level non-success outcome
212
+ /// (Failed, Cancelled, Terminated, TimedOut, or ContinuedAsNew) rather than an
213
+ /// infrastructure/RPC error.
214
+ pub fn is_workflow_outcome(&self) -> bool {
215
+ matches!(
216
+ self,
217
+ Self::Failed(_)
218
+ | Self::Cancelled { .. }
219
+ | Self::Terminated { .. }
220
+ | Self::TimedOut
221
+ | Self::ContinuedAsNew
222
+ )
223
+ }
224
+ }
225
+
226
+ /// Errors returned by client methods that don't need more specific error types.
227
+ #[derive(thiserror::Error, Debug)]
228
+ #[non_exhaustive]
229
+ pub enum ClientError {
230
+ /// An uncategorized rpc error from the server.
231
+ #[error("Server error: {0}")]
232
+ Rpc(#[from] tonic::Status),
233
+ }
234
+
235
+ /// Errors returned by methods on [crate::WorkflowHandle] for general operations
236
+ /// like signal, cancel, terminate, describe, fetch_history, and get_result.
237
+ #[derive(Debug, thiserror::Error)]
238
+ #[non_exhaustive]
239
+ pub enum WorkflowInteractionError {
240
+ /// The workflow was not found.
241
+ #[error("Workflow not found")]
242
+ NotFound(#[source] tonic::Status),
243
+
244
+ /// Error serializing input or deserializing output.
245
+ #[error("Payload conversion error: {0}")]
246
+ PayloadConversion(#[from] PayloadConversionError),
247
+
248
+ /// An uncategorized RPC error from the server.
249
+ #[error("Server error: {0}")]
250
+ Rpc(tonic::Status),
251
+
252
+ /// Other errors.
253
+ #[error(transparent)]
254
+ Other(#[from] Box<dyn std::error::Error + Send + Sync>),
255
+ }
256
+
257
+ impl WorkflowInteractionError {
258
+ pub(crate) fn from_status(status: tonic::Status) -> Self {
259
+ if status.code() == Code::NotFound {
260
+ Self::NotFound(status)
261
+ } else {
262
+ Self::Rpc(status)
263
+ }
264
+ }
265
+ }
266
+
267
+ /// Errors that can occur when completing an activity asynchronously.
268
+ #[derive(Debug, thiserror::Error)]
269
+ #[non_exhaustive]
270
+ pub enum AsyncActivityError {
271
+ /// The activity was not found (e.g., already completed, cancelled, or never existed).
272
+ #[error("Activity not found")]
273
+ NotFound(#[source] tonic::Status),
274
+ /// An uncategorized rpc error from the server.
275
+ #[error("Server error: {0}")]
276
+ Rpc(#[from] tonic::Status),
277
+ }
278
+
279
+ impl AsyncActivityError {
280
+ pub(crate) fn from_status(status: tonic::Status) -> Self {
281
+ if status.code() == Code::NotFound {
282
+ Self::NotFound(status)
283
+ } else {
284
+ Self::Rpc(status)
285
+ }
286
+ }
287
+ }
288
+
289
+ /// Errors that can occur when constructing a [`crate::Client`].
290
+ ///
291
+ /// Currently has no variants, but may be extended in the future.
292
+ #[derive(Debug, thiserror::Error)]
293
+ #[non_exhaustive]
294
+ pub enum ClientNewError {}