@temporalio/core-bridge 0.13.0 → 0.16.3

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 (77) hide show
  1. package/Cargo.lock +203 -78
  2. package/Cargo.toml +3 -3
  3. package/index.d.ts +195 -0
  4. package/index.node +0 -0
  5. package/package.json +10 -6
  6. package/releases/aarch64-apple-darwin/index.node +0 -0
  7. package/releases/{x86_64-pc-windows-gnu → 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 +77 -34
  12. package/sdk-core/.buildkite/docker/Dockerfile +1 -1
  13. package/sdk-core/CODEOWNERS +1 -1
  14. package/sdk-core/Cargo.toml +6 -5
  15. package/sdk-core/fsm/Cargo.toml +1 -1
  16. package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +2 -2
  17. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +8 -9
  18. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +13 -7
  19. package/sdk-core/fsm/rustfsm_trait/Cargo.toml +2 -2
  20. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +1 -1
  21. package/sdk-core/protos/local/activity_result.proto +10 -1
  22. package/sdk-core/protos/local/workflow_activation.proto +6 -3
  23. package/sdk-core/sdk-core-protos/Cargo.toml +4 -4
  24. package/sdk-core/sdk-core-protos/src/lib.rs +44 -49
  25. package/sdk-core/src/core_tests/activity_tasks.rs +5 -5
  26. package/sdk-core/src/core_tests/child_workflows.rs +55 -29
  27. package/sdk-core/src/core_tests/determinism.rs +19 -9
  28. package/sdk-core/src/core_tests/mod.rs +3 -3
  29. package/sdk-core/src/core_tests/retry.rs +96 -2
  30. package/sdk-core/src/core_tests/workers.rs +1 -1
  31. package/sdk-core/src/core_tests/workflow_tasks.rs +278 -4
  32. package/sdk-core/src/errors.rs +27 -44
  33. package/sdk-core/src/lib.rs +13 -3
  34. package/sdk-core/src/machines/activity_state_machine.rs +44 -5
  35. package/sdk-core/src/machines/child_workflow_state_machine.rs +31 -11
  36. package/sdk-core/src/machines/complete_workflow_state_machine.rs +1 -1
  37. package/sdk-core/src/machines/continue_as_new_workflow_state_machine.rs +1 -1
  38. package/sdk-core/src/machines/mod.rs +18 -23
  39. package/sdk-core/src/machines/patch_state_machine.rs +8 -8
  40. package/sdk-core/src/machines/signal_external_state_machine.rs +22 -1
  41. package/sdk-core/src/machines/timer_state_machine.rs +21 -3
  42. package/sdk-core/src/machines/transition_coverage.rs +3 -3
  43. package/sdk-core/src/machines/workflow_machines.rs +11 -11
  44. package/sdk-core/src/pending_activations.rs +27 -22
  45. package/sdk-core/src/pollers/gateway.rs +28 -7
  46. package/sdk-core/src/pollers/poll_buffer.rs +6 -5
  47. package/sdk-core/src/pollers/retry.rs +193 -136
  48. package/sdk-core/src/prototype_rust_sdk/workflow_context.rs +61 -46
  49. package/sdk-core/src/prototype_rust_sdk/workflow_future.rs +13 -12
  50. package/sdk-core/src/prototype_rust_sdk.rs +17 -23
  51. package/sdk-core/src/telemetry/metrics.rs +2 -4
  52. package/sdk-core/src/telemetry/mod.rs +6 -7
  53. package/sdk-core/src/test_help/canned_histories.rs +17 -93
  54. package/sdk-core/src/test_help/history_builder.rs +51 -2
  55. package/sdk-core/src/test_help/history_info.rs +2 -2
  56. package/sdk-core/src/test_help/mod.rs +21 -34
  57. package/sdk-core/src/worker/activities/activity_heartbeat_manager.rs +246 -138
  58. package/sdk-core/src/worker/activities.rs +47 -45
  59. package/sdk-core/src/worker/config.rs +11 -0
  60. package/sdk-core/src/worker/dispatcher.rs +5 -5
  61. package/sdk-core/src/worker/mod.rs +86 -56
  62. package/sdk-core/src/workflow/driven_workflow.rs +3 -3
  63. package/sdk-core/src/workflow/history_update.rs +1 -1
  64. package/sdk-core/src/workflow/mod.rs +2 -1
  65. package/sdk-core/src/workflow/workflow_tasks/cache_manager.rs +13 -17
  66. package/sdk-core/src/workflow/workflow_tasks/concurrency_manager.rs +10 -18
  67. package/sdk-core/src/workflow/workflow_tasks/mod.rs +72 -57
  68. package/sdk-core/test_utils/Cargo.toml +1 -1
  69. package/sdk-core/test_utils/src/lib.rs +2 -2
  70. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +131 -2
  71. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +2 -2
  72. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +49 -0
  73. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +2 -2
  74. package/sdk-core/tests/integ_tests/workflow_tests.rs +74 -47
  75. package/src/conversions.rs +17 -0
  76. package/src/errors.rs +0 -7
  77. package/src/lib.rs +0 -20
@@ -9,7 +9,10 @@ use crate::{
9
9
  use anyhow::bail;
10
10
  use std::time::SystemTime;
11
11
  use temporal_sdk_core_protos::{
12
- coresdk::common::{build_has_change_marker_details, NamespacedWorkflowExecution},
12
+ coresdk::common::{
13
+ build_has_change_marker_details, NamespacedWorkflowExecution, Payload as CorePayload,
14
+ },
15
+ coresdk::IntoPayloadsExt,
13
16
  temporal::api::{
14
17
  common::v1::{Payload, Payloads, WorkflowExecution, WorkflowType},
15
18
  enums::v1::{EventType, WorkflowTaskFailedCause},
@@ -136,6 +139,52 @@ impl TestHistoryBuilder {
136
139
  self.build_and_push_event(EventType::WorkflowExecutionCanceled, attrs.into());
137
140
  }
138
141
 
142
+ pub fn add_activity_task_scheduled(&mut self, activity_id: impl Into<String>) -> i64 {
143
+ self.add_get_event_id(
144
+ EventType::ActivityTaskScheduled,
145
+ Some(
146
+ history_event::Attributes::ActivityTaskScheduledEventAttributes(
147
+ ActivityTaskScheduledEventAttributes {
148
+ activity_id: activity_id.into(),
149
+ ..Default::default()
150
+ },
151
+ ),
152
+ ),
153
+ )
154
+ }
155
+ pub fn add_activity_task_started(&mut self, scheduled_event_id: i64) -> i64 {
156
+ self.add_get_event_id(
157
+ EventType::ActivityTaskStarted,
158
+ Some(
159
+ history_event::Attributes::ActivityTaskStartedEventAttributes(
160
+ ActivityTaskStartedEventAttributes {
161
+ scheduled_event_id,
162
+ ..Default::default()
163
+ },
164
+ ),
165
+ ),
166
+ )
167
+ }
168
+
169
+ pub fn add_activity_task_completed(
170
+ &mut self,
171
+ scheduled_event_id: i64,
172
+ started_event_id: i64,
173
+ payload: CorePayload,
174
+ ) {
175
+ self.add(
176
+ EventType::ActivityTaskCompleted,
177
+ history_event::Attributes::ActivityTaskCompletedEventAttributes(
178
+ ActivityTaskCompletedEventAttributes {
179
+ scheduled_event_id,
180
+ started_event_id,
181
+ result: vec![payload].into_payloads(),
182
+ ..Default::default()
183
+ },
184
+ ),
185
+ );
186
+ }
187
+
139
188
  pub fn add_activity_task_cancel_requested(&mut self, scheduled_event_id: i64) {
140
189
  let attrs = ActivityTaskCancelRequestedEventAttributes {
141
190
  scheduled_event_id,
@@ -309,7 +358,7 @@ impl TestHistoryBuilder {
309
358
  },
310
359
  )) = &evt.attributes
311
360
  {
312
- self.original_run_id = original_execution_run_id.to_owned();
361
+ self.original_run_id = original_execution_run_id.clone();
313
362
  };
314
363
  self.events.push(evt);
315
364
  }
@@ -105,14 +105,14 @@ impl HistoryInfo {
105
105
  }
106
106
 
107
107
  /// Non-test code should *not* rely on just counting workflow tasks b/c of pagination
108
- pub(crate) fn wf_task_count(&self) -> usize {
108
+ pub(crate) const fn wf_task_count(&self) -> usize {
109
109
  self.wf_task_count
110
110
  }
111
111
  }
112
112
 
113
113
  impl From<HistoryInfo> for HistoryUpdate {
114
114
  fn from(v: HistoryInfo) -> Self {
115
- HistoryUpdate::new_from_events(v.events, v.previous_started_event_id)
115
+ Self::new_from_events(v.events, v.previous_started_event_id)
116
116
  }
117
117
  }
118
118
 
@@ -47,6 +47,7 @@ use temporal_sdk_core_protos::{
47
47
 
48
48
  pub type Result<T, E = anyhow::Error> = std::result::Result<T, E>;
49
49
  pub const TEST_Q: &str = "q";
50
+ pub static NO_MORE_WORK_ERROR_MSG: &str = "No more work to do";
50
51
 
51
52
  /// When constructing responses for mocks, indicates how a given response should be built
52
53
  #[derive(derive_more::From, Debug, Clone, Copy, Eq, PartialEq, Hash)]
@@ -57,12 +58,12 @@ pub enum ResponseType {
57
58
 
58
59
  impl From<&usize> for ResponseType {
59
60
  fn from(u: &usize) -> Self {
60
- ResponseType::ToTaskNum(*u)
61
+ Self::ToTaskNum(*u)
61
62
  }
62
63
  }
63
64
  // :shrug:
64
- impl From<&ResponseType> for ResponseType {
65
- fn from(r: &ResponseType) -> Self {
65
+ impl From<&Self> for ResponseType {
66
+ fn from(r: &Self) -> Self {
66
67
  *r
67
68
  }
68
69
  }
@@ -164,7 +165,7 @@ pub struct MockWorker {
164
165
 
165
166
  impl Default for MockWorker {
166
167
  fn default() -> Self {
167
- MockWorker {
168
+ Self {
168
169
  wf_poller: Box::from(mock_poller()),
169
170
  act_poller: None,
170
171
  config: WorkerConfig::default_test_q(),
@@ -174,14 +175,14 @@ impl Default for MockWorker {
174
175
 
175
176
  impl MockWorker {
176
177
  pub fn new(q: &str, wf_poller: BoxedWFPoller) -> Self {
177
- MockWorker {
178
+ Self {
178
179
  wf_poller,
179
180
  act_poller: None,
180
181
  config: WorkerConfig::default(q),
181
182
  }
182
183
  }
183
184
  pub fn for_queue(q: &str) -> Self {
184
- MockWorker {
185
+ Self {
185
186
  wf_poller: Box::from(mock_poller()),
186
187
  act_poller: None,
187
188
  config: WorkerConfig::default(q),
@@ -193,15 +194,12 @@ impl<SG> MocksHolder<SG>
193
194
  where
194
195
  SG: ServerGatewayApis + Send + Sync + 'static,
195
196
  {
196
- pub fn from_mock_workers(
197
- sg: SG,
198
- mock_workers: impl IntoIterator<Item = MockWorker>,
199
- ) -> MocksHolder<SG> {
197
+ pub fn from_mock_workers(sg: SG, mock_workers: impl IntoIterator<Item = MockWorker>) -> Self {
200
198
  let mock_pollers = mock_workers
201
199
  .into_iter()
202
200
  .map(|w| (w.config.task_queue.clone(), w))
203
201
  .collect();
204
- MocksHolder {
202
+ Self {
205
203
  sg,
206
204
  mock_pollers,
207
205
  outstanding_task_map: None,
@@ -209,16 +207,12 @@ where
209
207
  }
210
208
 
211
209
  /// Uses the provided list of tasks to create a mock poller for the `TEST_Q`
212
- pub fn from_gateway_with_responses<WFT, ACT>(
213
- sg: SG,
214
- wf_tasks: WFT,
215
- act_tasks: ACT,
216
- ) -> MocksHolder<SG>
210
+ pub fn from_gateway_with_responses<WFT, ACT>(sg: SG, wf_tasks: WFT, act_tasks: ACT) -> Self
217
211
  where
218
212
  WFT: IntoIterator<Item = PollWorkflowTaskQueueResponse>,
219
213
  ACT: IntoIterator<Item = PollActivityTaskQueueResponse>,
220
- <WFT as IntoIterator>::IntoIter: std::marker::Send + 'static,
221
- <ACT as IntoIterator>::IntoIter: std::marker::Send + 'static,
214
+ <WFT as IntoIterator>::IntoIter: Send + 'static,
215
+ <ACT as IntoIterator>::IntoIter: Send + 'static,
222
216
  {
223
217
  let mut mock_pollers = HashMap::new();
224
218
  let mock_poller = mock_poller_from_resps(wf_tasks);
@@ -234,7 +228,7 @@ where
234
228
  .unwrap(),
235
229
  },
236
230
  );
237
- MocksHolder {
231
+ Self {
238
232
  sg,
239
233
  mock_pollers,
240
234
  outstanding_task_map: None,
@@ -246,7 +240,7 @@ pub fn mock_poller_from_resps<T, I>(tasks: I) -> BoxedPoller<T>
246
240
  where
247
241
  T: Send + Sync + 'static,
248
242
  I: IntoIterator<Item = T>,
249
- <I as IntoIterator>::IntoIter: std::marker::Send + 'static,
243
+ <I as IntoIterator>::IntoIter: Send + 'static,
250
244
  {
251
245
  let mut mock_poller = mock_poller();
252
246
  let mut tasks = tasks.into_iter();
@@ -254,9 +248,7 @@ where
254
248
  if let Some(t) = tasks.next() {
255
249
  Some(Ok(t))
256
250
  } else {
257
- Some(Err(tonic::Status::out_of_range(
258
- "Ran out of mock responses!",
259
- )))
251
+ Some(Err(tonic::Status::cancelled(NO_MORE_WORK_ERROR_MSG)))
260
252
  }
261
253
  });
262
254
  Box::new(mock_poller) as BoxedPoller<T>
@@ -412,7 +404,7 @@ pub fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder<MockServerGateway
412
404
  let cur_attempt = attempts_at_task_num.entry(to_task_num).or_insert(1);
413
405
  let mut r = hist_to_poll_resp(
414
406
  &hist.hist,
415
- hist.wf_id.to_owned(),
407
+ hist.wf_id.clone(),
416
408
  *to_task_num,
417
409
  hist.task_q.clone(),
418
410
  );
@@ -430,7 +422,7 @@ pub fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder<MockServerGateway
430
422
  }
431
423
 
432
424
  let mut mock_pollers = HashMap::new();
433
- for (task_q, mut queue_tasks) in task_queues_to_resps.into_iter() {
425
+ for (task_q, mut queue_tasks) in task_queues_to_resps {
434
426
  let mut mock_poller = mock_poller();
435
427
 
436
428
  // The poller will return history from any workflow runs that do not have currently
@@ -438,11 +430,7 @@ pub fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder<MockServerGateway
438
430
  let outstanding = outstanding_wf_task_tokens.clone();
439
431
  mock_poller
440
432
  .expect_poll()
441
- .times(
442
- correct_num_polls
443
- .map::<TimesRange, _>(Into::into)
444
- .unwrap_or_else(|| RangeFull.into()),
445
- )
433
+ .times(correct_num_polls.map_or_else(|| RangeFull.into(), Into::<TimesRange>::into))
446
434
  .returning(move || {
447
435
  for (_, tasks) in queue_tasks.iter_mut() {
448
436
  // Must extract run id from a workflow task associated with this workflow
@@ -458,7 +446,7 @@ pub fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder<MockServerGateway
458
446
  }
459
447
  }
460
448
  }
461
- Some(Err(tonic::Status::cancelled("No more work to do")))
449
+ Some(Err(tonic::Status::cancelled(NO_MORE_WORK_ERROR_MSG)))
462
450
  });
463
451
  let mw = MockWorker::new(&task_q, Box::from(mock_poller));
464
452
  mock_pollers.insert(task_q, mw);
@@ -477,8 +465,7 @@ pub fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder<MockServerGateway
477
465
  .withf(cfg.expect_fail_wft_matcher)
478
466
  .times(
479
467
  cfg.num_expected_fails
480
- .map::<TimesRange, _>(Into::into)
481
- .unwrap_or_else(|| RangeFull.into()),
468
+ .map_or_else(|| RangeFull.into(), Into::<TimesRange>::into),
482
469
  )
483
470
  .returning(move |tt, _, _| {
484
471
  outstanding.write().remove_by_right(&tt);
@@ -557,7 +544,7 @@ pub(crate) async fn poll_and_reply<'a>(
557
544
  eviction_mode: WorkflowCachingPolicy,
558
545
  expect_and_reply: &'a [AsserterWithReply<'a>],
559
546
  ) {
560
- poll_and_reply_clears_outstanding_evicts(core, None, eviction_mode, expect_and_reply).await
547
+ poll_and_reply_clears_outstanding_evicts(core, None, eviction_mode, expect_and_reply).await;
561
548
  }
562
549
 
563
550
  pub(crate) async fn poll_and_reply_clears_outstanding_evicts<'a>(