@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
package/ts/native.ts CHANGED
@@ -71,7 +71,11 @@ export type LogExporterOptions =
71
71
  receiver: (entries: JsonString<LogEntry>[]) => void;
72
72
  };
73
73
 
74
- export type MetricExporterOptions = PrometheusMetricsExporterOptions | OtelMetricsExporterOptions | null;
74
+ export type MetricExporterOptions =
75
+ | PrometheusMetricsExporterOptions
76
+ | OtelMetricsExporterOptions
77
+ | BufferedMetricsExporterOptions
78
+ | null;
75
79
 
76
80
  export interface PrometheusMetricsExporterOptions {
77
81
  type: 'prometheus';
@@ -95,6 +99,12 @@ export interface OtelMetricsExporterOptions {
95
99
  protocol: 'http' | 'grpc';
96
100
  }
97
101
 
102
+ export interface BufferedMetricsExporterOptions {
103
+ type: 'buffer';
104
+ maxBufferSize: number;
105
+ useSecondsForDurations: boolean;
106
+ }
107
+
98
108
  ////////////////////////////////////////////////////////////////////////////////////////////////////
99
109
  // Client
100
110
  ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -168,7 +178,7 @@ export interface RpcCall {
168
178
 
169
179
  export declare function newWorker(client: Client, workerOptions: WorkerOptions): Worker;
170
180
 
171
- export declare function workerValidate(worker: Worker): Promise<void>;
181
+ export declare function workerValidate(worker: Worker): Promise<Buffer>;
172
182
 
173
183
  export declare function workerPollWorkflowActivation(worker: Worker): Promise<Buffer>;
174
184
 
@@ -188,6 +198,8 @@ export declare function workerInitiateShutdown(worker: Worker): void;
188
198
 
189
199
  export declare function workerFinalizeShutdown(worker: Worker): Promise<void>;
190
200
 
201
+ export declare function workerReplaceClient(worker: Worker, client: Client): void;
202
+
191
203
  export interface Worker {
192
204
  type: 'worker';
193
205
  }
@@ -245,7 +257,7 @@ export type PollerBehavior =
245
257
  export type WorkerDeploymentOptions = {
246
258
  version: WorkerDeploymentVersion;
247
259
  useWorkerVersioning: boolean;
248
- defaultVersioningBehavior: VersioningBehavior;
260
+ defaultVersioningBehavior: Option<VersioningBehavior>;
249
261
  };
250
262
 
251
263
  export type WorkerDeploymentVersion = {
@@ -523,3 +535,27 @@ export declare function setMetricGaugeF64Value(
523
535
  value: number,
524
536
  attrs: JsonString<MetricAttributes>
525
537
  ): void;
538
+
539
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
540
+ // Buffered Metrics
541
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
542
+
543
+ export declare function runtimeRetrieveBufferedMetrics(runtime: Runtime): BufferedMetricUpdate[];
544
+
545
+ export interface BufferedMetricUpdate {
546
+ metric: BufferedMetric;
547
+ value: number;
548
+ attributes: MetricAttributes;
549
+ }
550
+
551
+ export interface BufferedMetric {
552
+ name: string;
553
+ description: string;
554
+ unit: string;
555
+ kind: BufferedMetricKind;
556
+ valueType: BufferedMetricValueType;
557
+ }
558
+
559
+ export type BufferedMetricKind = 'counter' | 'histogram' | 'gauge';
560
+
561
+ export type BufferedMetricValueType = 'int' | 'float';
@@ -1,212 +0,0 @@
1
- use crate::WorkflowService;
2
- use anyhow::{anyhow, bail};
3
- use std::{fmt::Debug, marker::PhantomData};
4
- use temporalio_common::protos::{
5
- coresdk::FromPayloadsExt,
6
- temporal::api::{
7
- common::v1::{Payload, WorkflowExecution},
8
- enums::v1::HistoryEventFilterType,
9
- failure::v1::Failure,
10
- history::v1::history_event::Attributes,
11
- workflowservice::v1::GetWorkflowExecutionHistoryRequest,
12
- },
13
- };
14
- use tonic::IntoRequest;
15
-
16
- /// Enumerates terminal states for a particular workflow execution
17
- // TODO: Add non-proto failure types, flesh out details, etc.
18
- #[derive(Debug)]
19
- #[allow(clippy::large_enum_variant)]
20
- pub enum WorkflowExecutionResult<T> {
21
- /// The workflow finished successfully
22
- Succeeded(T),
23
- /// The workflow finished in failure
24
- Failed(Failure),
25
- /// The workflow was cancelled
26
- Cancelled(Vec<Payload>),
27
- /// The workflow was terminated
28
- Terminated(Vec<Payload>),
29
- /// The workflow timed out
30
- TimedOut,
31
- /// The workflow continued as new
32
- ContinuedAsNew,
33
- }
34
-
35
- impl<T> WorkflowExecutionResult<T>
36
- where
37
- T: Debug,
38
- {
39
- /// Unwrap the result, panicking if it was not a success
40
- pub fn unwrap_success(self) -> T {
41
- match self {
42
- Self::Succeeded(t) => t,
43
- o => panic!("Expected success, got {o:?}"),
44
- }
45
- }
46
- }
47
-
48
- /// Options for fetching workflow results
49
- #[derive(Debug, Clone, Copy)]
50
- pub struct GetWorkflowResultOptions {
51
- /// If true (the default), follows to the next workflow run in the execution chain while
52
- /// retrieving results.
53
- pub follow_runs: bool,
54
- }
55
- impl Default for GetWorkflowResultOptions {
56
- fn default() -> Self {
57
- Self { follow_runs: true }
58
- }
59
- }
60
-
61
- /// A workflow handle which can refer to a specific workflow run, or a chain of workflow runs with
62
- /// the same workflow id.
63
- pub struct WorkflowHandle<ClientT, ResultT> {
64
- client: ClientT,
65
- info: WorkflowExecutionInfo,
66
-
67
- _res_type: PhantomData<ResultT>,
68
- }
69
-
70
- /// Holds needed information to refer to a specific workflow run, or workflow execution chain
71
- #[derive(Debug)]
72
- pub struct WorkflowExecutionInfo {
73
- /// Namespace the workflow lives in
74
- pub namespace: String,
75
- /// The workflow's id
76
- pub workflow_id: String,
77
- /// If set, target this specific run of the workflow
78
- pub run_id: Option<String>,
79
- }
80
-
81
- impl WorkflowExecutionInfo {
82
- /// Bind the workflow info to a specific client, turning it into a workflow handle
83
- pub fn bind_untyped<CT>(self, client: CT) -> UntypedWorkflowHandle<CT>
84
- where
85
- CT: WorkflowService + Clone,
86
- {
87
- UntypedWorkflowHandle::new(client, self)
88
- }
89
- }
90
-
91
- /// A workflow handle to a workflow with unknown types. Uses raw payloads.
92
- pub(crate) type UntypedWorkflowHandle<CT> = WorkflowHandle<CT, Vec<Payload>>;
93
-
94
- impl<CT, RT> WorkflowHandle<CT, RT>
95
- where
96
- CT: WorkflowService + Clone,
97
- // TODO: Make more generic, capable of (de)serialization w/ serde
98
- RT: FromPayloadsExt,
99
- {
100
- pub(crate) fn new(client: CT, info: WorkflowExecutionInfo) -> Self {
101
- Self {
102
- client,
103
- info,
104
- _res_type: PhantomData::<RT>,
105
- }
106
- }
107
-
108
- /// Get the workflow execution info
109
- pub fn info(&self) -> &WorkflowExecutionInfo {
110
- &self.info
111
- }
112
-
113
- /// Get the client attached to this handle
114
- pub fn client(&self) -> &CT {
115
- &self.client
116
- }
117
-
118
- /// Await the result of the workflow execution
119
- pub async fn get_workflow_result(
120
- &self,
121
- opts: GetWorkflowResultOptions,
122
- ) -> Result<WorkflowExecutionResult<RT>, anyhow::Error> {
123
- let mut next_page_tok = vec![];
124
- let mut run_id = self.info.run_id.clone().unwrap_or_default();
125
- loop {
126
- let server_res = self
127
- .client
128
- .clone()
129
- .get_workflow_execution_history(
130
- GetWorkflowExecutionHistoryRequest {
131
- namespace: self.info.namespace.to_string(),
132
- execution: Some(WorkflowExecution {
133
- workflow_id: self.info.workflow_id.clone(),
134
- run_id: run_id.clone(),
135
- }),
136
- skip_archival: true,
137
- wait_new_event: true,
138
- history_event_filter_type: HistoryEventFilterType::CloseEvent as i32,
139
- next_page_token: next_page_tok.clone(),
140
- ..Default::default()
141
- }
142
- .into_request(),
143
- )
144
- .await?
145
- .into_inner();
146
-
147
- let mut history = server_res
148
- .history
149
- .ok_or_else(|| anyhow!("Server returned an empty history!"))?;
150
-
151
- if history.events.is_empty() {
152
- next_page_tok = server_res.next_page_token;
153
- continue;
154
- }
155
- // If page token was previously set, clear it.
156
- next_page_tok = vec![];
157
-
158
- let event_attrs = history.events.pop().and_then(|ev| ev.attributes);
159
-
160
- macro_rules! follow {
161
- ($attrs:ident) => {
162
- if opts.follow_runs && $attrs.new_execution_run_id != "" {
163
- run_id = $attrs.new_execution_run_id;
164
- continue;
165
- }
166
- };
167
- }
168
-
169
- break match event_attrs {
170
- Some(Attributes::WorkflowExecutionCompletedEventAttributes(attrs)) => {
171
- follow!(attrs);
172
- Ok(WorkflowExecutionResult::Succeeded(RT::from_payloads(
173
- attrs.result,
174
- )))
175
- }
176
- Some(Attributes::WorkflowExecutionFailedEventAttributes(attrs)) => {
177
- follow!(attrs);
178
- Ok(WorkflowExecutionResult::Failed(
179
- attrs.failure.unwrap_or_default(),
180
- ))
181
- }
182
- Some(Attributes::WorkflowExecutionCanceledEventAttributes(attrs)) => Ok(
183
- WorkflowExecutionResult::Cancelled(Vec::from_payloads(attrs.details)),
184
- ),
185
- Some(Attributes::WorkflowExecutionTimedOutEventAttributes(attrs)) => {
186
- follow!(attrs);
187
- Ok(WorkflowExecutionResult::TimedOut)
188
- }
189
- Some(Attributes::WorkflowExecutionTerminatedEventAttributes(attrs)) => Ok(
190
- WorkflowExecutionResult::Terminated(Vec::from_payloads(attrs.details)),
191
- ),
192
- Some(Attributes::WorkflowExecutionContinuedAsNewEventAttributes(attrs)) => {
193
- if opts.follow_runs {
194
- if !attrs.new_execution_run_id.is_empty() {
195
- run_id = attrs.new_execution_run_id;
196
- continue;
197
- } else {
198
- bail!("New execution run id was empty in continue as new event!");
199
- }
200
- } else {
201
- Ok(WorkflowExecutionResult::ContinuedAsNew)
202
- }
203
- }
204
- o => Err(anyhow!(
205
- "Server returned an event that didn't match the CloseEvent filter. \
206
- This is either a server bug or a new event the SDK does not understand. \
207
- Event details: {o:?}"
208
- )),
209
- };
210
- }
211
- }
212
- }
@@ -1,85 +0,0 @@
1
- //! Error types exposed by public APIs
2
-
3
- use crate::protos::coresdk::activity_result::ActivityExecutionResult;
4
-
5
- /// Errors thrown by [crate::Worker::validate]
6
- #[derive(thiserror::Error, Debug)]
7
- pub enum WorkerValidationError {
8
- /// The namespace provided to the worker does not exist on the server.
9
- #[error("Namespace {namespace} was not found or otherwise could not be described: {source:?}")]
10
- NamespaceDescribeError {
11
- source: tonic::Status,
12
- namespace: String,
13
- },
14
- }
15
-
16
- /// Errors thrown by [crate::Worker] polling methods
17
- #[derive(thiserror::Error, Debug)]
18
- pub enum PollError {
19
- /// [crate::Worker::shutdown] was called, and there are no more tasks to be handled from this
20
- /// poll function. Lang must call [crate::Worker::complete_workflow_activation],
21
- /// [crate::Worker::complete_activity_task], or
22
- /// [crate::Worker::complete_nexus_task] for any remaining tasks, and then may exit.
23
- #[error("Core is shut down and there are no more tasks of this kind")]
24
- ShutDown,
25
- /// Unhandled error when calling the temporal server. Core will attempt to retry any non-fatal
26
- /// errors, so lang should consider this fatal.
27
- #[error("Unhandled grpc error when polling: {0:?}")]
28
- TonicError(#[from] tonic::Status),
29
- }
30
-
31
- /// Errors thrown by [crate::Worker::complete_workflow_activation]
32
- #[derive(thiserror::Error, Debug)]
33
- #[allow(clippy::large_enum_variant)]
34
- pub enum CompleteWfError {
35
- /// Lang SDK sent us a malformed workflow completion. This likely means a bug in the lang sdk.
36
- #[error("Lang SDK sent us a malformed workflow completion for run ({run_id}): {reason}")]
37
- MalformedWorkflowCompletion {
38
- /// Reason the completion was malformed
39
- reason: String,
40
- /// The run associated with the completion
41
- run_id: String,
42
- },
43
- /// Workflows have not been enabled on this worker.
44
- #[error("Workflows are not enabled on this worker")]
45
- WorkflowNotEnabled,
46
- }
47
-
48
- /// Errors thrown by [crate::Worker::complete_activity_task]
49
- #[derive(thiserror::Error, Debug)]
50
- #[allow(clippy::large_enum_variant)]
51
- pub enum CompleteActivityError {
52
- /// Lang SDK sent us a malformed activity completion. This likely means a bug in the lang sdk.
53
- #[error("Lang SDK sent us a malformed activity completion ({reason}): {completion:?}")]
54
- MalformedActivityCompletion {
55
- /// Reason the completion was malformed
56
- reason: String,
57
- /// The completion, which may not be included to avoid unnecessary copies.
58
- completion: Option<ActivityExecutionResult>,
59
- },
60
- /// Activities have not been enabled on this worker.
61
- #[error("Activities are not enabled on this worker")]
62
- ActivityNotEnabled,
63
- }
64
-
65
- /// Errors thrown by [crate::Worker::complete_nexus_task]
66
- #[derive(thiserror::Error, Debug)]
67
- pub enum CompleteNexusError {
68
- /// Lang SDK sent us a malformed nexus completion. This likely means a bug in the lang sdk.
69
- #[error("Lang SDK sent us a malformed nexus completion: {reason}")]
70
- MalformedNexusCompletion {
71
- /// Reason the completion was malformed
72
- reason: String,
73
- },
74
- /// Nexus has not been enabled on this worker. If a user registers any Nexus handlers, the
75
- #[error("Nexus is not enabled on this worker")]
76
- NexusNotEnabled,
77
- }
78
-
79
- /// Errors we can encounter during workflow processing which we may treat as either WFT failures
80
- /// or whole-workflow failures depending on user preference.
81
- #[derive(Clone, Debug, Eq, PartialEq, Hash)]
82
- pub enum WorkflowErrorType {
83
- /// A nondeterminism error
84
- Nondeterminism,
85
- }
@@ -1,129 +0,0 @@
1
- use temporalio_common::worker::{WorkerConfigBuilder, WorkerTaskTypes, WorkerVersioningStrategy};
2
-
3
- fn default_versioning_strategy() -> WorkerVersioningStrategy {
4
- WorkerVersioningStrategy::None {
5
- build_id: String::new(),
6
- }
7
- }
8
-
9
- #[test]
10
- fn test_default_configuration_polls_all_types() {
11
- let config = WorkerConfigBuilder::default()
12
- .namespace("default")
13
- .task_queue("test-queue")
14
- .versioning_strategy(default_versioning_strategy())
15
- .task_types(WorkerTaskTypes::all())
16
- .build()
17
- .expect("Failed to build default config");
18
-
19
- let effective = &config.task_types;
20
- assert!(
21
- effective.enable_workflows,
22
- "Should poll workflows by default"
23
- );
24
- assert!(
25
- effective.enable_local_activities,
26
- "should poll local activities by default"
27
- );
28
- assert!(
29
- effective.enable_remote_activities,
30
- "Should poll remote activities by default"
31
- );
32
- assert!(effective.enable_nexus, "Should poll nexus by default");
33
- }
34
-
35
- #[test]
36
- fn test_invalid_task_types_fails_validation() {
37
- // empty task types
38
- let result = WorkerConfigBuilder::default()
39
- .namespace("default")
40
- .task_queue("test-queue")
41
- .versioning_strategy(default_versioning_strategy())
42
- .task_types(WorkerTaskTypes {
43
- enable_workflows: false,
44
- enable_local_activities: false,
45
- enable_remote_activities: false,
46
- enable_nexus: false,
47
- })
48
- .build();
49
-
50
- assert!(result.is_err(), "Empty task_types should fail validation");
51
- let err = result.err().unwrap().to_string();
52
- assert!(
53
- err.contains("At least one task type"),
54
- "Error should mention task types: {err}",
55
- );
56
-
57
- // local activities with no workflows
58
- let result = WorkerConfigBuilder::default()
59
- .namespace("default")
60
- .task_queue("test-queue")
61
- .versioning_strategy(default_versioning_strategy())
62
- .task_types(WorkerTaskTypes {
63
- enable_workflows: false,
64
- enable_local_activities: true,
65
- enable_remote_activities: false,
66
- enable_nexus: false,
67
- })
68
- .build();
69
-
70
- assert!(result.is_err(), "Empty task_types should fail validation");
71
- let err = result.err().unwrap().to_string();
72
- assert!(
73
- err.contains("cannot enable local activities without workflows"),
74
- "Error should mention task types: {err}",
75
- );
76
- }
77
-
78
- #[test]
79
- fn test_all_combinations() {
80
- let combinations = [
81
- (WorkerTaskTypes::workflow_only(), "workflows only"),
82
- (WorkerTaskTypes::activity_only(), "activities only"),
83
- (WorkerTaskTypes::nexus_only(), "nexus only"),
84
- (
85
- WorkerTaskTypes {
86
- enable_workflows: true,
87
- enable_local_activities: true,
88
- enable_remote_activities: true,
89
- enable_nexus: false,
90
- },
91
- "workflows + activities",
92
- ),
93
- (
94
- WorkerTaskTypes {
95
- enable_workflows: true,
96
- enable_local_activities: true,
97
- enable_remote_activities: false,
98
- enable_nexus: true,
99
- },
100
- "workflows + nexus",
101
- ),
102
- (
103
- WorkerTaskTypes {
104
- enable_workflows: false,
105
- enable_local_activities: false,
106
- enable_remote_activities: true,
107
- enable_nexus: true,
108
- },
109
- "activities + nexus",
110
- ),
111
- (WorkerTaskTypes::all(), "all types"),
112
- ];
113
-
114
- for (task_types, description) in combinations {
115
- let config = WorkerConfigBuilder::default()
116
- .namespace("default")
117
- .task_queue("test-queue")
118
- .versioning_strategy(default_versioning_strategy())
119
- .task_types(task_types)
120
- .build()
121
- .unwrap_or_else(|e| panic!("Failed to build config for {description}: {e:?}"));
122
-
123
- let effective = config.task_types;
124
- assert_eq!(
125
- effective, task_types,
126
- "Effective types should match for {description}",
127
- );
128
- }
129
- }
@@ -1,21 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2021 Temporal Technologies, Inc. All Rights Reserved
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.