@temporalio/core-bridge 1.9.2 → 1.10.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 (177) hide show
  1. package/Cargo.lock +754 -473
  2. package/Cargo.toml +3 -3
  3. package/lib/index.d.ts +33 -2
  4. package/lib/index.js.map +1 -1
  5. package/package.json +4 -4
  6. package/releases/aarch64-apple-darwin/index.node +0 -0
  7. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  8. package/releases/x86_64-apple-darwin/index.node +0 -0
  9. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  10. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  11. package/scripts/build.js +4 -3
  12. package/sdk-core/.cargo/config.toml +2 -4
  13. package/sdk-core/.github/workflows/heavy.yml +1 -1
  14. package/sdk-core/.github/workflows/per-pr.yml +6 -4
  15. package/sdk-core/Cargo.toml +10 -3
  16. package/sdk-core/README.md +4 -6
  17. package/sdk-core/client/Cargo.toml +13 -5
  18. package/sdk-core/client/src/lib.rs +123 -34
  19. package/sdk-core/client/src/metrics.rs +70 -18
  20. package/sdk-core/client/src/proxy.rs +85 -0
  21. package/sdk-core/client/src/raw.rs +67 -5
  22. package/sdk-core/client/src/worker_registry/mod.rs +5 -3
  23. package/sdk-core/client/src/workflow_handle/mod.rs +3 -1
  24. package/sdk-core/core/Cargo.toml +31 -37
  25. package/sdk-core/core/src/abstractions/take_cell.rs +3 -3
  26. package/sdk-core/core/src/abstractions.rs +176 -108
  27. package/sdk-core/core/src/core_tests/activity_tasks.rs +4 -13
  28. package/sdk-core/core/src/core_tests/determinism.rs +2 -1
  29. package/sdk-core/core/src/core_tests/local_activities.rs +3 -3
  30. package/sdk-core/core/src/core_tests/mod.rs +3 -3
  31. package/sdk-core/core/src/core_tests/queries.rs +42 -5
  32. package/sdk-core/core/src/core_tests/workers.rs +2 -3
  33. package/sdk-core/core/src/core_tests/workflow_tasks.rs +115 -15
  34. package/sdk-core/core/src/ephemeral_server/mod.rs +109 -136
  35. package/sdk-core/core/src/internal_flags.rs +8 -8
  36. package/sdk-core/core/src/lib.rs +16 -11
  37. package/sdk-core/core/src/pollers/mod.rs +11 -5
  38. package/sdk-core/core/src/pollers/poll_buffer.rs +48 -29
  39. package/sdk-core/core/src/protosext/mod.rs +32 -32
  40. package/sdk-core/core/src/protosext/protocol_messages.rs +14 -24
  41. package/sdk-core/core/src/retry_logic.rs +2 -2
  42. package/sdk-core/core/src/telemetry/log_export.rs +10 -9
  43. package/sdk-core/core/src/telemetry/metrics.rs +233 -330
  44. package/sdk-core/core/src/telemetry/mod.rs +11 -38
  45. package/sdk-core/core/src/telemetry/otel.rs +355 -0
  46. package/sdk-core/core/src/telemetry/prometheus_server.rs +36 -23
  47. package/sdk-core/core/src/test_help/mod.rs +80 -59
  48. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +6 -6
  49. package/sdk-core/core/src/worker/activities/local_activities.rs +46 -43
  50. package/sdk-core/core/src/worker/activities.rs +45 -46
  51. package/sdk-core/core/src/worker/client/mocks.rs +8 -7
  52. package/sdk-core/core/src/worker/client.rs +40 -39
  53. package/sdk-core/core/src/worker/mod.rs +72 -42
  54. package/sdk-core/core/src/worker/slot_provider.rs +28 -28
  55. package/sdk-core/core/src/worker/slot_supplier.rs +1 -0
  56. package/sdk-core/core/src/worker/tuner/fixed_size.rs +52 -0
  57. package/sdk-core/core/src/worker/tuner/resource_based.rs +561 -0
  58. package/sdk-core/core/src/worker/tuner.rs +122 -0
  59. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +6 -6
  60. package/sdk-core/core/src/worker/workflow/history_update.rs +27 -53
  61. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +4 -17
  62. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -10
  63. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +4 -11
  64. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +17 -35
  65. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +0 -8
  66. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +1 -5
  67. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +0 -5
  68. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +0 -5
  69. package/sdk-core/core/src/worker/workflow/machines/mod.rs +0 -14
  70. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +0 -5
  71. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +0 -5
  72. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -10
  73. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +3 -10
  74. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +12 -8
  75. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +0 -10
  76. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +6 -13
  77. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +27 -37
  78. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +3 -14
  79. package/sdk-core/core/src/worker/workflow/managed_run.rs +84 -54
  80. package/sdk-core/core/src/worker/workflow/mod.rs +63 -160
  81. package/sdk-core/core/src/worker/workflow/run_cache.rs +22 -13
  82. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +16 -3
  83. package/sdk-core/core/src/worker/workflow/wft_poller.rs +15 -12
  84. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +39 -78
  85. package/sdk-core/core-api/Cargo.toml +6 -5
  86. package/sdk-core/core-api/src/errors.rs +8 -0
  87. package/sdk-core/core-api/src/telemetry/metrics.rs +75 -4
  88. package/sdk-core/core-api/src/telemetry.rs +7 -1
  89. package/sdk-core/core-api/src/worker.rs +212 -56
  90. package/sdk-core/fsm/Cargo.toml +3 -0
  91. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  92. package/sdk-core/sdk/Cargo.toml +5 -7
  93. package/sdk-core/sdk/src/app_data.rs +3 -3
  94. package/sdk-core/sdk/src/lib.rs +5 -3
  95. package/sdk-core/sdk/src/workflow_context/options.rs +1 -1
  96. package/sdk-core/sdk/src/workflow_context.rs +10 -9
  97. package/sdk-core/sdk/src/workflow_future.rs +1 -1
  98. package/sdk-core/sdk-core-protos/Cargo.toml +8 -6
  99. package/sdk-core/sdk-core-protos/build.rs +1 -10
  100. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +3 -0
  101. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/ci.yml +26 -0
  102. package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +42 -20
  103. package/sdk-core/sdk-core-protos/protos/api_upstream/README.md +2 -0
  104. package/sdk-core/sdk-core-protos/protos/api_upstream/api-linter.yaml +36 -26
  105. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.lock +2 -0
  106. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/struct.proto +95 -0
  107. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +9632 -0
  108. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +7337 -0
  109. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/payload_description.txt +2 -0
  110. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +45 -11
  111. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +22 -4
  112. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/command_type.proto +2 -0
  113. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +44 -0
  114. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +18 -3
  115. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +20 -0
  116. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +30 -0
  117. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/update.proto +7 -8
  118. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +23 -5
  119. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +20 -0
  120. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +25 -0
  121. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +141 -15
  122. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +12 -0
  123. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +193 -0
  124. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +73 -6
  125. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +46 -4
  126. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +4 -0
  127. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +2 -2
  128. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +116 -0
  129. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +134 -0
  130. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +274 -29
  131. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +57 -1
  132. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +10 -12
  133. package/sdk-core/sdk-core-protos/src/history_builder.rs +1 -1
  134. package/sdk-core/sdk-core-protos/src/lib.rs +54 -51
  135. package/sdk-core/sdk-core-protos/src/task_token.rs +11 -2
  136. package/sdk-core/test-utils/Cargo.toml +7 -4
  137. package/sdk-core/test-utils/src/histfetch.rs +1 -1
  138. package/sdk-core/test-utils/src/lib.rs +44 -62
  139. package/sdk-core/tests/fuzzy_workflow.rs +5 -2
  140. package/sdk-core/tests/heavy_tests.rs +114 -17
  141. package/sdk-core/tests/integ_tests/activity_functions.rs +1 -1
  142. package/sdk-core/tests/integ_tests/client_tests.rs +2 -2
  143. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +38 -26
  144. package/sdk-core/tests/integ_tests/metrics_tests.rs +126 -17
  145. package/sdk-core/tests/integ_tests/polling_tests.rs +118 -2
  146. package/sdk-core/tests/integ_tests/update_tests.rs +3 -5
  147. package/sdk-core/tests/integ_tests/visibility_tests.rs +3 -3
  148. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +1 -1
  149. package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +1 -1
  150. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -1
  151. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  152. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +3 -3
  153. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +5 -4
  154. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -2
  155. package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +6 -10
  156. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +9 -7
  157. package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +1 -1
  158. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +14 -9
  159. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
  160. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +6 -13
  161. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +9 -6
  162. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +5 -5
  163. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +1 -1
  164. package/sdk-core/tests/integ_tests/workflow_tests.rs +115 -11
  165. package/sdk-core/tests/main.rs +2 -2
  166. package/src/conversions.rs +57 -0
  167. package/src/lib.rs +1 -0
  168. package/src/runtime.rs +51 -35
  169. package/ts/index.ts +67 -3
  170. package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +0 -117
  171. package/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +0 -24
  172. package/sdk-core/sdk/src/payload_converter.rs +0 -11
  173. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/Dockerfile +0 -2
  174. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/docker-compose.yml +0 -15
  175. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/pipeline.yml +0 -10
  176. package/sdk-core/test-utils/src/wf_input_saver.rs +0 -50
  177. package/sdk-core/tests/wf_input_replay.rs +0 -32
@@ -46,7 +46,6 @@ use temporal_sdk_core_protos::{
46
46
  },
47
47
  common::v1::SearchAttributes,
48
48
  enums::v1::CommandType,
49
- history::v1::HistoryEvent,
50
49
  },
51
50
  };
52
51
 
@@ -237,10 +236,6 @@ impl WFMachinesAdapter for PatchMachine {
237
236
  ) -> Result<Vec<MachineResponse>, WFMachinesError> {
238
237
  panic!("Patch machine does not produce commands")
239
238
  }
240
-
241
- fn matches_event(&self, event: &HistoryEvent) -> bool {
242
- event.get_patch_marker_details().is_some()
243
- }
244
239
  }
245
240
 
246
241
  impl Cancellable for PatchMachine {}
@@ -19,7 +19,7 @@ use temporal_sdk_core_protos::{
19
19
  common::v1::WorkflowExecution as UpstreamWE,
20
20
  enums::v1::{CommandType, EventType, SignalExternalWorkflowExecutionFailedCause},
21
21
  failure::v1::{failure::FailureInfo, ApplicationFailureInfo, CanceledFailureInfo, Failure},
22
- history::v1::{history_event, HistoryEvent},
22
+ history::v1::history_event,
23
23
  },
24
24
  };
25
25
 
@@ -260,15 +260,6 @@ impl WFMachinesAdapter for SignalExternalMachine {
260
260
  }
261
261
  })
262
262
  }
263
-
264
- fn matches_event(&self, event: &HistoryEvent) -> bool {
265
- matches!(
266
- event.event_type(),
267
- EventType::ExternalWorkflowExecutionSignaled
268
- | EventType::SignalExternalWorkflowExecutionInitiated
269
- | EventType::SignalExternalWorkflowExecutionFailed
270
- )
271
- }
272
263
  }
273
264
 
274
265
  impl Cancellable for SignalExternalMachine {
@@ -16,7 +16,7 @@ use temporal_sdk_core_protos::{
16
16
  temporal::api::{
17
17
  command::v1::Command,
18
18
  enums::v1::{CommandType, EventType},
19
- history::v1::{history_event, HistoryEvent, TimerFiredEventAttributes},
19
+ history::v1::{history_event, TimerFiredEventAttributes},
20
20
  },
21
21
  };
22
22
 
@@ -233,13 +233,6 @@ impl WFMachinesAdapter for TimerMachine {
233
233
  TimerMachineCommand::IssueCancelCmd(c) => vec![MachineResponse::IssueNewCommand(c)],
234
234
  })
235
235
  }
236
-
237
- fn matches_event(&self, event: &HistoryEvent) -> bool {
238
- matches!(
239
- event.event_type(),
240
- EventType::TimerStarted | EventType::TimerCanceled | EventType::TimerFired
241
- )
242
- }
243
236
  }
244
237
 
245
238
  impl Cancellable for TimerMachine {
@@ -310,8 +303,8 @@ mod test {
310
303
  mock_cfg.num_expected_fails = 1;
311
304
  mock_cfg.expect_fail_wft_matcher = Box::new(move |_, cause, f| {
312
305
  matches!(cause, WorkflowTaskFailedCause::NonDeterministicError)
313
- && matches!(f, Some(Failure { source, .. })
314
- if source.contains("Timer fired event did not have expected timer id 1"))
306
+ && matches!(f, Some(Failure {message, .. })
307
+ if message.contains("Timer fired event did not have expected timer id 1"))
315
308
  });
316
309
  let mut worker = build_fake_sdk(mock_cfg);
317
310
  worker.register_wf(DEFAULT_WORKFLOW_TYPE, |ctx: WfContext| async move {
@@ -4,6 +4,7 @@
4
4
  //! never ever be removed from behind `#[cfg(test)]` compilation.
5
5
 
6
6
  use dashmap::{mapref::entry::Entry, DashMap, DashSet};
7
+ use once_cell::sync::Lazy;
7
8
  use std::{
8
9
  path::PathBuf,
9
10
  sync::{
@@ -15,13 +16,11 @@ use std::{
15
16
  };
16
17
 
17
18
  // During test we want to know about which transitions we've covered in state machines
18
- lazy_static::lazy_static! {
19
- static ref COVERED_TRANSITIONS: DashMap<String, DashSet<CoveredTransition>>
20
- = DashMap::new();
21
- static ref COVERAGE_SENDER: SyncSender<(String, CoveredTransition)> =
22
- spawn_save_coverage_at_end();
23
- static ref THREAD_HANDLE: Mutex<Option<JoinHandle<()>>> = Mutex::new(None);
24
- }
19
+ static COVERED_TRANSITIONS: Lazy<DashMap<String, DashSet<CoveredTransition>>> =
20
+ Lazy::new(DashMap::new);
21
+ static COVERAGE_SENDER: Lazy<SyncSender<(String, CoveredTransition)>> =
22
+ Lazy::new(spawn_save_coverage_at_end);
23
+ static THREAD_HANDLE: Lazy<Mutex<Option<JoinHandle<()>>>> = Lazy::new(|| Mutex::new(None));
25
24
 
26
25
  #[derive(Eq, PartialEq, Hash, Debug)]
27
26
  struct CoveredTransition {
@@ -30,7 +29,12 @@ struct CoveredTransition {
30
29
  event: String,
31
30
  }
32
31
 
33
- pub fn add_coverage(machine_name: String, from_state: String, to_state: String, event: String) {
32
+ pub(super) fn add_coverage(
33
+ machine_name: String,
34
+ from_state: String,
35
+ to_state: String,
36
+ event: String,
37
+ ) {
34
38
  let ct = CoveredTransition {
35
39
  from_state,
36
40
  to_state,
@@ -17,7 +17,6 @@ use temporal_sdk_core_protos::{
17
17
  common::v1::Payload,
18
18
  enums::v1::{CommandType, EventType},
19
19
  failure::v1::Failure,
20
- history::v1::HistoryEvent,
21
20
  protocol::v1::Message as ProtocolMessage,
22
21
  update::v1::{outcome, Acceptance, Outcome, Rejection, Response},
23
22
  },
@@ -271,15 +270,6 @@ impl WFMachinesAdapter for UpdateMachine {
271
270
  )?,
272
271
  })
273
272
  }
274
-
275
- fn matches_event(&self, event: &HistoryEvent) -> bool {
276
- matches!(
277
- event.event_type(),
278
- EventType::WorkflowExecutionUpdateAccepted
279
- | EventType::WorkflowExecutionUpdateRejected
280
- | EventType::WorkflowExecutionUpdateCompleted
281
- )
282
- }
283
273
  }
284
274
 
285
275
  impl TryFrom<CommandType> for UpdateMachineEvents {
@@ -15,8 +15,8 @@ use temporal_sdk_core_protos::{
15
15
  temporal::api::{
16
16
  command::v1::{command, Command, UpsertWorkflowSearchAttributesCommandAttributes},
17
17
  common::v1::SearchAttributes,
18
- enums::v1::{CommandType, EventType},
19
- history::v1::{history_event, HistoryEvent},
18
+ enums::v1::CommandType,
19
+ history::v1::history_event,
20
20
  },
21
21
  };
22
22
 
@@ -137,14 +137,6 @@ impl WFMachinesAdapter for UpsertSearchAttributesMachine {
137
137
  "UpsertWorkflowSearchAttributesMachine does not use commands".to_string(),
138
138
  ))
139
139
  }
140
-
141
- /// Filters for EventType::UpsertWorkflowSearchAttributes
142
- fn matches_event(&self, event: &HistoryEvent) -> bool {
143
- matches!(
144
- event.event_type(),
145
- EventType::UpsertWorkflowSearchAttributes
146
- )
147
- }
148
140
  }
149
141
 
150
142
  impl Cancellable for UpsertSearchAttributesMachine {}
@@ -214,8 +206,10 @@ mod tests {
214
206
  AsJsonPayloadExt,
215
207
  },
216
208
  temporal::api::{
217
- command::v1::command::Attributes, common::v1::Payload,
218
- history::v1::UpsertWorkflowSearchAttributesEventAttributes,
209
+ command::v1::command::Attributes,
210
+ common::v1::Payload,
211
+ enums::v1::EventType,
212
+ history::v1::{HistoryEvent, UpsertWorkflowSearchAttributesEventAttributes},
219
213
  },
220
214
  DEFAULT_WORKFLOW_TYPE,
221
215
  };
@@ -291,7 +285,6 @@ mod tests {
291
285
  ),
292
286
  ..Default::default()
293
287
  };
294
- assert!(sm.matches_event(&recorded_history_event));
295
288
  let cmd_recorded_sm_event = HistEventData {
296
289
  event: recorded_history_event,
297
290
  replaying: false,
@@ -92,18 +92,18 @@ pub(crate) struct WorkflowMachines {
92
92
  /// The event id of the most recent event processed. It's possible in some situations (ex legacy
93
93
  /// queries) to receive a history with no new workflow tasks. If the last history we processed
94
94
  /// also had no new tasks, we need a way to know not to apply the same events over again.
95
- pub last_processed_event: i64,
95
+ pub(crate) last_processed_event: i64,
96
96
  /// True if the workflow is replaying from history
97
- pub replaying: bool,
97
+ pub(crate) replaying: bool,
98
98
  /// Workflow identifier
99
- pub workflow_id: String,
99
+ pub(crate) workflow_id: String,
100
100
  /// Workflow type identifier. (Function name, class, etc)
101
- pub workflow_type: String,
101
+ pub(crate) workflow_type: String,
102
102
  /// Identifies the current run
103
- pub run_id: String,
103
+ pub(crate) run_id: String,
104
104
  /// Is set to true once we've seen the final event in workflow history, to avoid accidentally
105
105
  /// re-applying the final workflow task.
106
- pub have_seen_terminal_event: bool,
106
+ pub(crate) have_seen_terminal_event: bool,
107
107
  /// The time the workflow execution began, as told by the WEStarted event
108
108
  workflow_start_time: Option<SystemTime>,
109
109
  /// The time the workflow execution finished, as determined by when the machines handled
@@ -157,7 +157,7 @@ pub(crate) struct WorkflowMachines {
157
157
  drive_me: DrivenWorkflow,
158
158
 
159
159
  /// Metrics context
160
- pub metrics: MetricsContext,
160
+ pub(crate) metrics: MetricsContext,
161
161
  worker_config: Arc<WorkerConfig>,
162
162
  }
163
163
 
@@ -376,7 +376,6 @@ impl WorkflowMachines {
376
376
  has_pending_jobs: self.has_pending_jobs(),
377
377
  have_seen_terminal_event: self.have_seen_terminal_event,
378
378
  have_pending_la_resolutions: self.has_pending_la_resolutions(),
379
- last_processed_event: self.last_processed_event,
380
379
  me: self,
381
380
  }
382
381
  }
@@ -782,7 +781,7 @@ impl WorkflowMachines {
782
781
  };
783
782
  }
784
783
  if event.event_type() == EventType::Unspecified
785
- || event.event_type() == EventType::WorkflowExecutionUpdateRequested
784
+ || event.event_type() == EventType::WorkflowExecutionUpdateAdmitted
786
785
  || event.attributes.is_none()
787
786
  {
788
787
  return if !event.worker_may_ignore {
@@ -905,8 +904,8 @@ impl WorkflowMachines {
905
904
  fn handle_non_stateful_event(&mut self, event_dat: HistEventData) -> Result<()> {
906
905
  trace!(event = %event_dat.event, "handling non-stateful event");
907
906
  let event_id = event_dat.event.event_id;
908
- match EventType::from_i32(event_dat.event.event_type) {
909
- Some(EventType::WorkflowExecutionStarted) => {
907
+ match EventType::try_from(event_dat.event.event_type) {
908
+ Ok(EventType::WorkflowExecutionStarted) => {
910
909
  if let Some(history_event::Attributes::WorkflowExecutionStartedEventAttributes(
911
910
  attrs,
912
911
  )) = event_dat.event.attributes
@@ -932,13 +931,13 @@ impl WorkflowMachines {
932
931
  )));
933
932
  }
934
933
  }
935
- Some(EventType::WorkflowTaskScheduled) => {
934
+ Ok(EventType::WorkflowTaskScheduled) => {
936
935
  let wf_task_sm = WorkflowTaskMachine::new(self.next_started_event_id);
937
936
  let key = self.all_machines.insert(wf_task_sm.into());
938
937
  self.submachine_handle_event(key, event_dat)?;
939
938
  self.machines_by_event_id.insert(event_id, key);
940
939
  }
941
- Some(EventType::WorkflowExecutionSignaled) => {
940
+ Ok(EventType::WorkflowExecutionSignaled) => {
942
941
  if let Some(history_event::Attributes::WorkflowExecutionSignaledEventAttributes(
943
942
  attrs,
944
943
  )) = event_dat.event.attributes
@@ -949,7 +948,7 @@ impl WorkflowMachines {
949
948
  // err
950
949
  }
951
950
  }
952
- Some(EventType::WorkflowExecutionCancelRequested) => {
951
+ Ok(EventType::WorkflowExecutionCancelRequested) => {
953
952
  if let Some(
954
953
  history_event::Attributes::WorkflowExecutionCancelRequestedEventAttributes(
955
954
  attrs,
@@ -1293,21 +1292,12 @@ impl WorkflowMachines {
1293
1292
  self.process_cancellation(CommandID::LocalActivity(attrs.seq))?;
1294
1293
  }
1295
1294
  WFCommand::CompleteWorkflow(attrs) => {
1296
- if !self.replaying {
1297
- self.metrics.wf_completed();
1298
- }
1299
1295
  self.add_terminal_command(complete_workflow(attrs));
1300
1296
  }
1301
1297
  WFCommand::FailWorkflow(attrs) => {
1302
- if !self.replaying {
1303
- self.metrics.wf_failed();
1304
- }
1305
1298
  self.add_terminal_command(fail_workflow(attrs));
1306
1299
  }
1307
1300
  WFCommand::ContinueAsNew(attrs) => {
1308
- if !self.replaying {
1309
- self.metrics.wf_continued_as_new();
1310
- }
1311
1301
  let attrs = self.augment_continue_as_new_with_current_values(attrs);
1312
1302
  let use_compat = self.determine_use_compatible_flag(
1313
1303
  attrs.versioning_intent(),
@@ -1316,9 +1306,6 @@ impl WorkflowMachines {
1316
1306
  self.add_terminal_command(continue_as_new(attrs, use_compat));
1317
1307
  }
1318
1308
  WFCommand::CancelWorkflow(attrs) => {
1319
- if !self.replaying {
1320
- self.metrics.wf_canceled();
1321
- }
1322
1309
  self.add_terminal_command(cancel_workflow(attrs));
1323
1310
  }
1324
1311
  WFCommand::SetPatchMarker(attrs) => {
@@ -1535,7 +1522,7 @@ impl WorkflowMachines {
1535
1522
  .unwrap_or_default();
1536
1523
  }
1537
1524
  if attrs.retry_policy.is_none() {
1538
- attrs.retry_policy = started_info.retry_policy.clone();
1525
+ attrs.retry_policy.clone_from(&started_info.retry_policy);
1539
1526
  }
1540
1527
  }
1541
1528
  attrs
@@ -1560,25 +1547,28 @@ impl WorkflowMachines {
1560
1547
  /// Contains everything workflow machine internals need to bubble up when we're getting ready to
1561
1548
  /// respond with a WFT completion. Allows for lazy mutation of the machine, since mutation is not
1562
1549
  /// desired unless we are actually going to respond to the WFT, which may not always happen.
1563
- pub struct MachinesWFTResponseContent<'a> {
1550
+ pub(crate) struct MachinesWFTResponseContent<'a> {
1564
1551
  me: &'a mut WorkflowMachines,
1565
- pub replaying: bool,
1566
- pub has_pending_jobs: bool,
1567
- pub have_seen_terminal_event: bool,
1568
- pub have_pending_la_resolutions: bool,
1569
- pub last_processed_event: i64,
1552
+ pub(crate) replaying: bool,
1553
+ pub(crate) has_pending_jobs: bool,
1554
+ pub(crate) have_seen_terminal_event: bool,
1555
+ pub(crate) have_pending_la_resolutions: bool,
1570
1556
  }
1557
+
1571
1558
  impl<'a> MachinesWFTResponseContent<'a> {
1572
- pub fn commands(&self) -> Peekable<impl Iterator<Item = ProtoCommand> + '_> {
1559
+ pub(crate) fn commands(&self) -> Peekable<impl Iterator<Item = ProtoCommand> + '_> {
1573
1560
  self.me.get_commands().peekable()
1574
1561
  }
1575
- pub fn has_messages(&self) -> bool {
1562
+
1563
+ pub(crate) fn has_messages(&self) -> bool {
1576
1564
  !self.me.message_outbox.is_empty()
1577
1565
  }
1578
- pub fn messages(&mut self) -> Vec<ProtocolMessage> {
1566
+
1567
+ pub(crate) fn messages(&mut self) -> Vec<ProtocolMessage> {
1579
1568
  self.me.message_outbox.drain(..).collect()
1580
1569
  }
1581
- pub fn metadata_for_complete(&mut self) -> WorkflowTaskCompletedMetadata {
1570
+
1571
+ pub(crate) fn metadata_for_complete(&mut self) -> WorkflowTaskCompletedMetadata {
1582
1572
  self.me.get_metadata_for_wft_complete()
1583
1573
  }
1584
1574
  }
@@ -11,7 +11,7 @@ use std::{
11
11
  };
12
12
  use temporal_sdk_core_protos::temporal::api::{
13
13
  enums::v1::{CommandType, EventType, WorkflowTaskFailedCause},
14
- history::v1::{history_event::Attributes::WorkflowTaskFailedEventAttributes, HistoryEvent},
14
+ history::v1::history_event::Attributes::WorkflowTaskFailedEventAttributes,
15
15
  };
16
16
 
17
17
  fsm! {
@@ -88,17 +88,6 @@ impl WFMachinesAdapter for WorkflowTaskMachine {
88
88
  }
89
89
  }
90
90
  }
91
-
92
- fn matches_event(&self, event: &HistoryEvent) -> bool {
93
- matches!(
94
- event.event_type(),
95
- EventType::WorkflowTaskScheduled
96
- | EventType::WorkflowTaskStarted
97
- | EventType::WorkflowTaskTimedOut
98
- | EventType::WorkflowTaskCompleted
99
- | EventType::WorkflowTaskFailed
100
- )
101
- }
102
91
  }
103
92
 
104
93
  impl TryFrom<HistEventData> for WorkflowTaskMachineEvents {
@@ -136,9 +125,9 @@ impl TryFrom<HistEventData> for WorkflowTaskMachineEvents {
136
125
  Self::WorkflowTaskFailed(WFTFailedDat {
137
126
  new_run_id: match attributes {
138
127
  WorkflowTaskFailedEventAttributes(a) => {
139
- let cause = WorkflowTaskFailedCause::from_i32(a.cause);
128
+ let cause = WorkflowTaskFailedCause::try_from(a.cause);
140
129
  match cause {
141
- Some(WorkflowTaskFailedCause::ResetWorkflow) => {
130
+ Ok(WorkflowTaskFailedCause::ResetWorkflow) => {
142
131
  Some(a.new_run_id)
143
132
  }
144
133
  _ => None,