@temporalio/core-bridge 1.15.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 (209) hide show
  1. package/Cargo.lock +172 -70
  2. package/lib/native.d.ts +1 -1
  3. package/package.json +2 -2
  4. package/releases/aarch64-apple-darwin/index.node +0 -0
  5. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  6. package/releases/x86_64-apple-darwin/index.node +0 -0
  7. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  8. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  9. package/sdk-core/.github/workflows/per-pr.yml +6 -6
  10. package/sdk-core/AGENTS.md +41 -30
  11. package/sdk-core/Cargo.toml +3 -0
  12. package/sdk-core/README.md +15 -9
  13. package/sdk-core/crates/client/Cargo.toml +4 -0
  14. package/sdk-core/crates/client/README.md +139 -0
  15. package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
  16. package/sdk-core/crates/client/src/callback_based.rs +7 -0
  17. package/sdk-core/crates/client/src/errors.rs +294 -0
  18. package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +280 -159
  19. package/sdk-core/crates/client/src/lib.rs +920 -1326
  20. package/sdk-core/crates/client/src/metrics.rs +24 -33
  21. package/sdk-core/crates/client/src/options_structs.rs +457 -0
  22. package/sdk-core/crates/client/src/replaceable.rs +5 -4
  23. package/sdk-core/crates/client/src/request_extensions.rs +8 -9
  24. package/sdk-core/crates/client/src/retry.rs +99 -54
  25. package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +1 -1
  26. package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
  27. package/sdk-core/crates/common/Cargo.toml +61 -2
  28. package/sdk-core/crates/common/build.rs +742 -12
  29. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
  30. package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
  31. package/sdk-core/crates/common/protos/api_upstream/buf.yaml +0 -3
  32. package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
  33. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +1166 -770
  34. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +1243 -750
  35. package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +2 -2
  36. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -3
  37. package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
  38. package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +4 -0
  39. package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
  40. package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +16 -1
  41. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -6
  42. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +88 -33
  43. package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +4 -2
  44. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -0
  45. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +5 -5
  46. package/sdk-core/crates/common/src/activity_definition.rs +20 -0
  47. package/sdk-core/crates/common/src/data_converters.rs +770 -0
  48. package/sdk-core/crates/common/src/envconfig.rs +5 -0
  49. package/sdk-core/crates/common/src/lib.rs +15 -211
  50. package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
  51. package/sdk-core/crates/common/src/priority.rs +110 -0
  52. package/sdk-core/crates/common/src/protos/canned_histories.rs +3 -0
  53. package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
  54. package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
  55. package/sdk-core/crates/common/src/protos/mod.rs +122 -27
  56. package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
  57. package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
  58. package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +5 -7
  59. package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
  60. package/sdk-core/crates/common/src/telemetry/metrics.rs +268 -223
  61. package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
  62. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
  63. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
  64. package/sdk-core/crates/common/src/telemetry.rs +264 -4
  65. package/sdk-core/crates/common/src/worker.rs +68 -603
  66. package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
  67. package/sdk-core/crates/macros/Cargo.toml +5 -1
  68. package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
  69. package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
  70. package/sdk-core/crates/macros/src/lib.rs +138 -512
  71. package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
  72. package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
  73. package/sdk-core/crates/sdk/Cargo.toml +19 -6
  74. package/sdk-core/crates/sdk/README.md +415 -0
  75. package/sdk-core/crates/sdk/src/activities.rs +417 -0
  76. package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
  77. package/sdk-core/crates/sdk/src/lib.rs +757 -442
  78. package/sdk-core/crates/sdk/src/workflow_context/options.rs +45 -35
  79. package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
  80. package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
  81. package/sdk-core/crates/sdk/src/workflows.rs +711 -0
  82. package/sdk-core/crates/sdk-core/Cargo.toml +57 -64
  83. package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +41 -35
  84. package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
  85. package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
  86. package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
  87. package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +13 -15
  88. package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
  89. package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
  90. package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
  91. package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +493 -26
  92. package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +4 -8
  93. package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +7 -7
  94. package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
  95. package/sdk-core/crates/sdk-core/src/lib.rs +41 -111
  96. package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
  97. package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +118 -19
  98. package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
  99. package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
  100. package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +179 -196
  101. package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -280
  102. package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +6 -9
  103. package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
  104. package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
  105. package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
  106. package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +9 -5
  107. package/sdk-core/crates/sdk-core/src/worker/client.rs +103 -81
  108. package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +7 -11
  109. package/sdk-core/crates/sdk-core/src/worker/mod.rs +1124 -229
  110. package/sdk-core/crates/sdk-core/src/worker/nexus.rs +145 -23
  111. package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
  112. package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
  113. package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +13 -13
  114. package/sdk-core/crates/sdk-core/src/worker/tuner.rs +28 -8
  115. package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
  116. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
  117. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +16 -3
  118. package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +14 -18
  119. package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +4 -6
  120. package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
  121. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
  122. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
  123. package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
  124. package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
  125. package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
  126. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
  127. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
  128. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
  129. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
  130. package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
  131. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
  132. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
  133. package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
  134. package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
  135. package/sdk-core/crates/sdk-core/tests/common/mod.rs +241 -196
  136. package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
  137. package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +3 -5
  138. package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -64
  139. package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +298 -252
  140. package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
  141. package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
  142. package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
  143. package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +16 -12
  144. package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +48 -40
  145. package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +327 -255
  146. package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
  147. package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +147 -126
  148. package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
  149. package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -453
  150. package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
  151. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +360 -231
  152. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +248 -185
  153. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -43
  154. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
  155. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +428 -315
  156. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -56
  157. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -28
  158. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -243
  159. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
  160. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +101 -42
  161. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -147
  162. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -28
  163. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1036
  164. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -41
  165. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +397 -238
  166. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +340 -188
  167. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
  168. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
  169. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +154 -137
  170. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -105
  171. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -38
  172. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -40
  173. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -54
  174. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +363 -226
  175. package/sdk-core/crates/sdk-core/tests/main.rs +17 -15
  176. package/sdk-core/crates/sdk-core/tests/manual_tests.rs +207 -152
  177. package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +65 -34
  178. package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
  179. package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
  180. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
  181. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
  182. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
  183. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
  184. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
  185. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
  186. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
  187. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
  188. package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +7 -1
  189. package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +14 -14
  190. package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +83 -74
  191. package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +9 -14
  192. package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +1 -2
  193. package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +13 -13
  194. package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +6 -6
  195. package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +3 -4
  196. package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +62 -75
  197. package/sdk-core/rustfmt.toml +2 -1
  198. package/src/client.rs +205 -318
  199. package/src/metrics.rs +22 -30
  200. package/src/runtime.rs +4 -5
  201. package/src/worker.rs +15 -18
  202. package/ts/native.ts +1 -1
  203. package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
  204. package/sdk-core/crates/common/src/errors.rs +0 -85
  205. package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
  206. package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
  207. package/sdk-core/crates/sdk/src/app_data.rs +0 -37
  208. package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
  209. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
@@ -0,0 +1,110 @@
1
+ use crate::protos::temporal::api::common;
2
+
3
+ /// Priority contains metadata that controls relative ordering of task processing
4
+ /// when tasks are backlogged in a queue. Initially, Priority will be used in
5
+ /// activity and workflow task queues, which are typically where backlogs exist.
6
+ /// Other queues in the server (such as transfer and timer queues) and rate
7
+ /// limiting decisions do not use Priority, but may in the future.
8
+ ///
9
+ /// Priority is attached to workflows and activities. Activities and child
10
+ /// workflows inherit Priority from the workflow that created them, but may
11
+ /// override fields when they are started or modified.
12
+ ///
13
+ /// All fields default to `None`, which means "inherit from the calling workflow"
14
+ /// or, if there is no calling workflow, "use the server default."
15
+ ///
16
+ /// Despite being named "Priority", this type also contains fields that
17
+ /// control "fairness" mechanisms.
18
+ ///
19
+ /// The overall semantics of Priority are:
20
+ /// (more will be added here later)
21
+ /// 1. First, consider "priority_key": lower number goes first.
22
+ #[derive(Debug, Clone, Default, PartialEq)]
23
+ pub struct Priority {
24
+ /// Priority key is a positive integer from 1 to n, where smaller integers
25
+ /// correspond to higher priorities (tasks run sooner). In general, tasks in
26
+ /// a queue should be processed in close to priority order, although small
27
+ /// deviations are possible.
28
+ ///
29
+ /// The maximum priority value (minimum priority) is determined by server
30
+ /// configuration, and defaults to 5.
31
+ ///
32
+ /// The server default priority is `(min + max) / 2`. With the default max
33
+ /// of 5 and min of 1, that comes out to 3.
34
+ ///
35
+ /// `None` means inherit from the calling workflow or use the server default.
36
+ pub priority_key: Option<u32>,
37
+
38
+ /// Fairness key is a short string that's used as a key for a fairness
39
+ /// balancing mechanism. It may correspond to a tenant id, or to a fixed
40
+ /// string like "high" or "low".
41
+ ///
42
+ /// The fairness mechanism attempts to dispatch tasks for a given key in
43
+ /// proportion to its weight. For example, using a thousand distinct tenant
44
+ /// ids, each with a weight of 1.0 (the default) will result in each tenant
45
+ /// getting a roughly equal share of task dispatch throughput.
46
+ ///
47
+ /// (Note: this does not imply equal share of worker capacity! Fairness
48
+ /// decisions are made based on queue statistics, not current worker load.)
49
+ ///
50
+ /// As another example, using keys "high" and "low" with weight 9.0 and 1.0
51
+ /// respectively will prefer dispatching "high" tasks over "low" tasks at a
52
+ /// 9:1 ratio, while allowing either key to use all worker capacity if the
53
+ /// other is not present.
54
+ ///
55
+ /// All fairness mechanisms, including rate limits, are best-effort and
56
+ /// probabilistic. The results may not match what a "perfect" algorithm with
57
+ /// infinite resources would produce. The more unique keys are used, the less
58
+ /// accurate the results will be.
59
+ ///
60
+ /// Fairness keys are limited to 64 bytes.
61
+ ///
62
+ /// `None` means inherit from the calling workflow or use the server default
63
+ /// (empty string).
64
+ pub fairness_key: Option<String>,
65
+
66
+ /// Fairness weight for a task can come from multiple sources for
67
+ /// flexibility. From highest to lowest precedence:
68
+ /// 1. Weights for a small set of keys can be overridden in task queue
69
+ /// configuration with an API.
70
+ /// 2. It can be attached to the workflow/activity in this field.
71
+ /// 3. The server default weight of 1.0 will be used.
72
+ ///
73
+ /// Weight values are clamped by the server to the range \[0.001, 1000\].
74
+ ///
75
+ /// `None` means inherit from the calling workflow or use the server default
76
+ /// (1.0).
77
+ pub fairness_weight: Option<f32>,
78
+ }
79
+
80
+ impl From<Priority> for common::v1::Priority {
81
+ fn from(priority: Priority) -> Self {
82
+ common::v1::Priority {
83
+ priority_key: priority.priority_key.unwrap_or(0) as i32,
84
+ fairness_key: priority.fairness_key.unwrap_or_default(),
85
+ fairness_weight: priority.fairness_weight.unwrap_or(0.0),
86
+ }
87
+ }
88
+ }
89
+
90
+ impl From<common::v1::Priority> for Priority {
91
+ fn from(priority: common::v1::Priority) -> Self {
92
+ Self {
93
+ priority_key: if priority.priority_key == 0 {
94
+ None
95
+ } else {
96
+ Some(priority.priority_key as u32)
97
+ },
98
+ fairness_key: if priority.fairness_key.is_empty() {
99
+ None
100
+ } else {
101
+ Some(priority.fairness_key)
102
+ },
103
+ fairness_weight: if priority.fairness_weight == 0.0 {
104
+ None
105
+ } else {
106
+ Some(priority.fairness_weight)
107
+ },
108
+ }
109
+ }
110
+ }
@@ -30,6 +30,7 @@ pub fn single_timer(timer_id: &str) -> TestHistoryBuilder {
30
30
  t
31
31
  }
32
32
 
33
+ /// Like [`single_timer`] but also completes the workflow.
33
34
  pub fn single_timer_wf_completes(timer_id: &str) -> TestHistoryBuilder {
34
35
  let mut t = single_timer(timer_id);
35
36
  t.add_workflow_task_completed();
@@ -974,12 +975,14 @@ pub fn timer_then_continue_as_new(timer_id: &str) -> TestHistoryBuilder {
974
975
  pub fn timer_wf_cancel_req_cancelled(timer_id: &str) -> TestHistoryBuilder {
975
976
  timer_cancel_req_then(timer_id, TestHistoryBuilder::add_cancelled)
976
977
  }
978
+ /// Timer with cancel request followed by workflow execution completed.
977
979
  pub fn timer_wf_cancel_req_completed(timer_id: &str) -> TestHistoryBuilder {
978
980
  timer_cancel_req_then(
979
981
  timer_id,
980
982
  TestHistoryBuilder::add_workflow_execution_completed,
981
983
  )
982
984
  }
985
+ /// Timer with cancel request followed by workflow execution failed.
983
986
  pub fn timer_wf_cancel_req_failed(timer_id: &str) -> TestHistoryBuilder {
984
987
  timer_cancel_req_then(timer_id, TestHistoryBuilder::add_workflow_execution_failed)
985
988
  }
@@ -30,11 +30,14 @@ use std::{
30
30
  };
31
31
  use uuid::Uuid;
32
32
 
33
+ /// The workflow type name used by default in test histories.
33
34
  pub static DEFAULT_WORKFLOW_TYPE: &str = "default_wf_type";
35
+ /// The activity type name used by default in test histories.
34
36
  pub static DEFAULT_ACTIVITY_TYPE: &str = "default_act_type";
35
37
 
36
38
  type Result<T, E = anyhow::Error> = std::result::Result<T, E>;
37
39
 
40
+ /// Builder for constructing synthetic workflow histories for testing.
38
41
  #[derive(Default, Clone, Debug)]
39
42
  pub struct TestHistoryBuilder {
40
43
  events: Vec<HistoryEvent>,
@@ -48,6 +51,7 @@ pub struct TestHistoryBuilder {
48
51
  }
49
52
 
50
53
  impl TestHistoryBuilder {
54
+ /// Construct from a pre-existing list of history events.
51
55
  pub fn from_history(events: Vec<HistoryEvent>) -> Self {
52
56
  let find_matching_id = |etype: EventType| {
53
57
  events
@@ -96,15 +100,18 @@ impl TestHistoryBuilder {
96
100
  self.add_workflow_task_completed();
97
101
  }
98
102
 
103
+ /// Add workflow task scheduled and started events.
99
104
  pub fn add_workflow_task_scheduled_and_started(&mut self) {
100
105
  self.add_workflow_task_scheduled();
101
106
  self.add_workflow_task_started();
102
107
  }
103
108
 
109
+ /// Add a workflow task scheduled event.
104
110
  pub fn add_workflow_task_scheduled(&mut self) {
105
111
  self.workflow_task_scheduled_event_id = self.add_by_type(EventType::WorkflowTaskScheduled);
106
112
  }
107
113
 
114
+ /// Add a workflow task started event.
108
115
  pub fn add_workflow_task_started(&mut self) {
109
116
  self.final_workflow_task_started_event_id = self.add(WorkflowTaskStartedEventAttributes {
110
117
  scheduled_event_id: self.workflow_task_scheduled_event_id,
@@ -113,6 +120,7 @@ impl TestHistoryBuilder {
113
120
  });
114
121
  }
115
122
 
123
+ /// Add a workflow task completed event.
116
124
  pub fn add_workflow_task_completed(&mut self) {
117
125
  let id = self.add(WorkflowTaskCompletedEventAttributes {
118
126
  scheduled_event_id: self.workflow_task_scheduled_event_id,
@@ -121,6 +129,7 @@ impl TestHistoryBuilder {
121
129
  self.previous_task_completed_id = id;
122
130
  }
123
131
 
132
+ /// Add a workflow task timed out event.
124
133
  pub fn add_workflow_task_timed_out(&mut self) {
125
134
  let attrs = WorkflowTaskTimedOutEventAttributes {
126
135
  scheduled_event_id: self.workflow_task_scheduled_event_id,
@@ -129,6 +138,7 @@ impl TestHistoryBuilder {
129
138
  self.build_and_push_event(EventType::WorkflowTaskTimedOut, attrs.into());
130
139
  }
131
140
 
141
+ /// Add a workflow execution completed event.
132
142
  pub fn add_workflow_execution_completed(&mut self) {
133
143
  let attrs = WorkflowExecutionCompletedEventAttributes {
134
144
  workflow_task_completed_event_id: self.previous_task_completed_id,
@@ -137,6 +147,7 @@ impl TestHistoryBuilder {
137
147
  self.build_and_push_event(EventType::WorkflowExecutionCompleted, attrs.into());
138
148
  }
139
149
 
150
+ /// Add a workflow execution terminated event.
140
151
  pub fn add_workflow_execution_terminated(&mut self) {
141
152
  let attrs = WorkflowExecutionTerminatedEventAttributes {
142
153
  ..Default::default()
@@ -144,6 +155,7 @@ impl TestHistoryBuilder {
144
155
  self.build_and_push_event(EventType::WorkflowExecutionTerminated, attrs.into());
145
156
  }
146
157
 
158
+ /// Add a workflow execution timed out event.
147
159
  pub fn add_workflow_execution_timed_out(&mut self) {
148
160
  let attrs = WorkflowExecutionTimedOutEventAttributes {
149
161
  ..Default::default()
@@ -151,6 +163,7 @@ impl TestHistoryBuilder {
151
163
  self.build_and_push_event(EventType::WorkflowExecutionTimedOut, attrs.into());
152
164
  }
153
165
 
166
+ /// Add a workflow execution failed event.
154
167
  pub fn add_workflow_execution_failed(&mut self) {
155
168
  let attrs = WorkflowExecutionFailedEventAttributes {
156
169
  workflow_task_completed_event_id: self.previous_task_completed_id,
@@ -159,21 +172,25 @@ impl TestHistoryBuilder {
159
172
  self.build_and_push_event(EventType::WorkflowExecutionFailed, attrs.into());
160
173
  }
161
174
 
175
+ /// Add a workflow execution continued-as-new event.
162
176
  pub fn add_continued_as_new(&mut self) {
163
177
  let attrs = WorkflowExecutionContinuedAsNewEventAttributes::default();
164
178
  self.build_and_push_event(EventType::WorkflowExecutionContinuedAsNew, attrs.into());
165
179
  }
166
180
 
181
+ /// Add a workflow execution cancel-requested event.
167
182
  pub fn add_cancel_requested(&mut self) {
168
183
  let attrs = WorkflowExecutionCancelRequestedEventAttributes::default();
169
184
  self.build_and_push_event(EventType::WorkflowExecutionCancelRequested, attrs.into());
170
185
  }
171
186
 
187
+ /// Add a workflow execution canceled event.
172
188
  pub fn add_cancelled(&mut self) {
173
189
  let attrs = WorkflowExecutionCanceledEventAttributes::default();
174
190
  self.build_and_push_event(EventType::WorkflowExecutionCanceled, attrs.into());
175
191
  }
176
192
 
193
+ /// Add an activity task scheduled event, returning the event ID.
177
194
  pub fn add_activity_task_scheduled(&mut self, activity_id: impl Into<String>) -> i64 {
178
195
  self.add(ActivityTaskScheduledEventAttributes {
179
196
  activity_id: activity_id.into(),
@@ -184,6 +201,7 @@ impl TestHistoryBuilder {
184
201
  })
185
202
  }
186
203
 
204
+ /// Add an activity task started event, returning the event ID.
187
205
  pub fn add_activity_task_started(&mut self, scheduled_event_id: i64) -> i64 {
188
206
  self.add(Attributes::ActivityTaskStartedEventAttributes(
189
207
  ActivityTaskStartedEventAttributes {
@@ -193,6 +211,7 @@ impl TestHistoryBuilder {
193
211
  ))
194
212
  }
195
213
 
214
+ /// Add an activity task completed event.
196
215
  pub fn add_activity_task_completed(
197
216
  &mut self,
198
217
  scheduled_event_id: i64,
@@ -207,6 +226,7 @@ impl TestHistoryBuilder {
207
226
  });
208
227
  }
209
228
 
229
+ /// Add an activity task cancel-requested event.
210
230
  pub fn add_activity_task_cancel_requested(&mut self, scheduled_event_id: i64) {
211
231
  let attrs = ActivityTaskCancelRequestedEventAttributes {
212
232
  scheduled_event_id,
@@ -215,6 +235,7 @@ impl TestHistoryBuilder {
215
235
  self.build_and_push_event(EventType::ActivityTaskCancelRequested, attrs.into());
216
236
  }
217
237
 
238
+ /// Add a workflow task failed event with a specific failure.
218
239
  pub fn add_workflow_task_failed_with_failure(
219
240
  &mut self,
220
241
  cause: WorkflowTaskFailedCause,
@@ -229,6 +250,7 @@ impl TestHistoryBuilder {
229
250
  self.build_and_push_event(EventType::WorkflowTaskFailed, attrs.into());
230
251
  }
231
252
 
253
+ /// Add a workflow task failed event with a new run ID.
232
254
  pub fn add_workflow_task_failed_new_id(
233
255
  &mut self,
234
256
  cause: WorkflowTaskFailedCause,
@@ -243,6 +265,7 @@ impl TestHistoryBuilder {
243
265
  self.build_and_push_event(EventType::WorkflowTaskFailed, attrs.into());
244
266
  }
245
267
 
268
+ /// Add a timer started event, returning the event ID.
246
269
  pub fn add_timer_started(&mut self, timer_id: String) -> i64 {
247
270
  self.add(TimerStartedEventAttributes {
248
271
  timer_id,
@@ -251,6 +274,7 @@ impl TestHistoryBuilder {
251
274
  })
252
275
  }
253
276
 
277
+ /// Add a timer fired event.
254
278
  pub fn add_timer_fired(&mut self, timer_started_evt_id: i64, timer_id: String) {
255
279
  self.add(TimerFiredEventAttributes {
256
280
  started_event_id: timer_started_evt_id,
@@ -258,6 +282,7 @@ impl TestHistoryBuilder {
258
282
  });
259
283
  }
260
284
 
285
+ /// Add a workflow execution signaled event.
261
286
  pub fn add_we_signaled(&mut self, signal_name: &str, payloads: Vec<Payload>) {
262
287
  let attrs = WorkflowExecutionSignaledEventAttributes {
263
288
  signal_name: signal_name.to_string(),
@@ -267,6 +292,7 @@ impl TestHistoryBuilder {
267
292
  self.build_and_push_event(EventType::WorkflowExecutionSignaled, attrs.into());
268
293
  }
269
294
 
295
+ /// Add a patch (has-change) marker event.
270
296
  pub fn add_has_change_marker(&mut self, patch_id: &str, deprecated: bool) {
271
297
  let attrs = MarkerRecordedEventAttributes {
272
298
  marker_name: PATCH_MARKER_NAME.to_string(),
@@ -277,6 +303,7 @@ impl TestHistoryBuilder {
277
303
  self.build_and_push_event(EventType::MarkerRecorded, attrs.into());
278
304
  }
279
305
 
306
+ /// Add a local activity marker event with optional payload/failure.
280
307
  pub fn add_local_activity_marker(
281
308
  &mut self,
282
309
  seq: u32,
@@ -305,6 +332,7 @@ impl TestHistoryBuilder {
305
332
  self.build_and_push_event(EventType::MarkerRecorded, attrs.into());
306
333
  }
307
334
 
335
+ /// Add a local activity result marker with a successful payload.
308
336
  pub fn add_local_activity_result_marker(
309
337
  &mut self,
310
338
  seq: u32,
@@ -314,6 +342,7 @@ impl TestHistoryBuilder {
314
342
  self.add_local_activity_marker(seq, activity_id, Some(payload), None, |_| {});
315
343
  }
316
344
 
345
+ /// Add a local activity result marker with a specific completion time.
317
346
  pub fn add_local_activity_result_marker_with_time(
318
347
  &mut self,
319
348
  seq: u32,
@@ -326,6 +355,7 @@ impl TestHistoryBuilder {
326
355
  });
327
356
  }
328
357
 
358
+ /// Add a local activity failure marker.
329
359
  pub fn add_local_activity_fail_marker(
330
360
  &mut self,
331
361
  seq: u32,
@@ -335,6 +365,7 @@ impl TestHistoryBuilder {
335
365
  self.add_local_activity_marker(seq, activity_id, None, Some(failure), |_| {});
336
366
  }
337
367
 
368
+ /// Add a local activity cancellation marker.
338
369
  pub fn add_local_activity_cancel_marker(&mut self, seq: u32, activity_id: &str) {
339
370
  self.add_local_activity_marker(
340
371
  seq,
@@ -354,6 +385,7 @@ impl TestHistoryBuilder {
354
385
  );
355
386
  }
356
387
 
388
+ /// Add an external signal workflow initiation event, returning the event ID.
357
389
  pub fn add_signal_wf(
358
390
  &mut self,
359
391
  signal_name: impl Into<String>,
@@ -371,6 +403,7 @@ impl TestHistoryBuilder {
371
403
  })
372
404
  }
373
405
 
406
+ /// Add an external workflow execution signaled event.
374
407
  pub fn add_external_signal_completed(&mut self, initiated_id: i64) {
375
408
  let attrs = ExternalWorkflowExecutionSignaledEventAttributes {
376
409
  initiated_event_id: initiated_id,
@@ -379,6 +412,7 @@ impl TestHistoryBuilder {
379
412
  self.build_and_push_event(EventType::ExternalWorkflowExecutionSignaled, attrs.into());
380
413
  }
381
414
 
415
+ /// Add a signal external workflow execution failed event.
382
416
  pub fn add_external_signal_failed(&mut self, initiated_id: i64) {
383
417
  let attrs = SignalExternalWorkflowExecutionFailedEventAttributes {
384
418
  initiated_event_id: initiated_id,
@@ -390,6 +424,7 @@ impl TestHistoryBuilder {
390
424
  );
391
425
  }
392
426
 
427
+ /// Add a cancel external workflow initiation event, returning the event ID.
393
428
  pub fn add_cancel_external_wf(&mut self, execution: NamespacedWorkflowExecution) -> i64 {
394
429
  self.add(
395
430
  RequestCancelExternalWorkflowExecutionInitiatedEventAttributes {
@@ -404,6 +439,7 @@ impl TestHistoryBuilder {
404
439
  )
405
440
  }
406
441
 
442
+ /// Add a cancel external workflow completed event.
407
443
  pub fn add_cancel_external_wf_completed(&mut self, initiated_id: i64) {
408
444
  let attrs = ExternalWorkflowExecutionCancelRequestedEventAttributes {
409
445
  initiated_event_id: initiated_id,
@@ -415,6 +451,7 @@ impl TestHistoryBuilder {
415
451
  );
416
452
  }
417
453
 
454
+ /// Add a cancel external workflow failed event.
418
455
  pub fn add_cancel_external_wf_failed(&mut self, initiated_id: i64) {
419
456
  let attrs = RequestCancelExternalWorkflowExecutionFailedEventAttributes {
420
457
  initiated_event_id: initiated_id,
@@ -426,12 +463,14 @@ impl TestHistoryBuilder {
426
463
  );
427
464
  }
428
465
 
466
+ /// Add a workflow execution started event with a custom workflow task timeout.
429
467
  pub fn add_wfe_started_with_wft_timeout(&mut self, dur: Duration) {
430
468
  let mut wesattrs = default_wes_attribs();
431
469
  wesattrs.workflow_task_timeout = Some(dur.try_into().unwrap());
432
470
  self.add(wesattrs);
433
471
  }
434
472
 
473
+ /// Add an upsert search attributes event for a patch marker.
435
474
  pub fn add_upsert_search_attrs_for_patch(&mut self, attribs: &[String]) {
436
475
  let mut indexed_fields = HashMap::new();
437
476
  indexed_fields.insert(
@@ -445,6 +484,7 @@ impl TestHistoryBuilder {
445
484
  self.build_and_push_event(EventType::UpsertWorkflowSearchAttributes, attrs.into());
446
485
  }
447
486
 
487
+ /// Add a workflow execution update accepted event, returning the event ID.
448
488
  pub fn add_update_accepted(
449
489
  &mut self,
450
490
  instance_id: impl Into<String>,
@@ -482,6 +522,7 @@ impl TestHistoryBuilder {
482
522
  self.build_and_push_event(EventType::WorkflowExecutionUpdateAccepted, attrs.into())
483
523
  }
484
524
 
525
+ /// Add a workflow execution update completed event.
485
526
  pub fn add_update_completed(&mut self, accepted_event_id: i64) {
486
527
  let attrs = WorkflowExecutionUpdateCompletedEventAttributes {
487
528
  meta: None,
@@ -493,6 +534,7 @@ impl TestHistoryBuilder {
493
534
  self.build_and_push_event(EventType::WorkflowExecutionUpdateCompleted, attrs.into());
494
535
  }
495
536
 
537
+ /// Returns the original run ID from the workflow execution started event.
496
538
  pub fn get_orig_run_id(&self) -> &str {
497
539
  &self.original_run_id
498
540
  }
@@ -509,6 +551,7 @@ impl TestHistoryBuilder {
509
551
  HistoryInfo::new_from_history(&self.events.clone().into(), None)
510
552
  }
511
553
 
554
+ /// Returns a single incremental workflow task's worth of history.
512
555
  pub fn get_one_wft(&self, from_wft_number: usize) -> Result<HistoryInfo, anyhow::Error> {
513
556
  let mut histinfo =
514
557
  HistoryInfo::new_from_history(&self.events.clone().into(), Some(from_wft_number))?;
@@ -625,6 +668,7 @@ fn default_attribs(et: EventType) -> Result<Attributes> {
625
668
  })
626
669
  }
627
670
 
671
+ /// Returns default workflow execution started attributes for testing.
628
672
  pub fn default_wes_attribs() -> WorkflowExecutionStartedEventAttributes {
629
673
  WorkflowExecutionStartedEventAttributes {
630
674
  original_execution_run_id: Uuid::new_v4().to_string(),
@@ -645,6 +689,7 @@ pub fn default_wes_attribs() -> WorkflowExecutionStartedEventAttributes {
645
689
  }
646
690
  }
647
691
 
692
+ /// Returns a default schedule-activity command for testing.
648
693
  pub fn default_act_sched() -> ScheduleActivity {
649
694
  ScheduleActivity {
650
695
  activity_type: DEFAULT_ACTIVITY_TYPE.to_string(),
@@ -131,10 +131,12 @@ impl HistoryInfo {
131
131
  self.events.drain(0..last_complete_ix);
132
132
  }
133
133
 
134
+ /// Returns a slice of all events in this history.
134
135
  pub fn events(&self) -> &[HistoryEvent] {
135
136
  &self.events
136
137
  }
137
138
 
139
+ /// Consumes this instance and returns the underlying events.
138
140
  pub fn into_events(self) -> Vec<HistoryEvent> {
139
141
  self.events
140
142
  }