@temporalio/core-bridge 0.23.0 → 1.0.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 (135) hide show
  1. package/Cargo.lock +118 -15
  2. package/Cargo.toml +2 -1
  3. package/LICENSE.md +1 -1
  4. package/README.md +1 -1
  5. package/index.d.ts +47 -18
  6. package/package.json +7 -7
  7. package/releases/aarch64-apple-darwin/index.node +0 -0
  8. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  9. package/releases/x86_64-apple-darwin/index.node +0 -0
  10. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  11. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  12. package/sdk-core/.buildkite/docker/docker-compose.yaml +4 -2
  13. package/sdk-core/ARCHITECTURE.md +9 -7
  14. package/sdk-core/README.md +5 -1
  15. package/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
  16. package/sdk-core/bridge-ffi/src/wrappers.rs +0 -3
  17. package/sdk-core/client/src/lib.rs +26 -8
  18. package/sdk-core/client/src/raw.rs +166 -54
  19. package/sdk-core/client/src/retry.rs +9 -4
  20. package/sdk-core/client/src/workflow_handle/mod.rs +4 -2
  21. package/sdk-core/core/Cargo.toml +2 -0
  22. package/sdk-core/core/src/abstractions.rs +137 -16
  23. package/sdk-core/core/src/core_tests/activity_tasks.rs +258 -63
  24. package/sdk-core/core/src/core_tests/child_workflows.rs +1 -2
  25. package/sdk-core/core/src/core_tests/determinism.rs +2 -2
  26. package/sdk-core/core/src/core_tests/local_activities.rs +8 -7
  27. package/sdk-core/core/src/core_tests/queries.rs +146 -60
  28. package/sdk-core/core/src/core_tests/replay_flag.rs +1 -1
  29. package/sdk-core/core/src/core_tests/workers.rs +39 -23
  30. package/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  31. package/sdk-core/core/src/core_tests/workflow_tasks.rs +387 -280
  32. package/sdk-core/core/src/lib.rs +6 -4
  33. package/sdk-core/core/src/pollers/poll_buffer.rs +16 -10
  34. package/sdk-core/core/src/protosext/mod.rs +6 -6
  35. package/sdk-core/core/src/retry_logic.rs +1 -1
  36. package/sdk-core/core/src/telemetry/metrics.rs +21 -7
  37. package/sdk-core/core/src/telemetry/mod.rs +18 -4
  38. package/sdk-core/core/src/test_help/mod.rs +341 -109
  39. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +18 -9
  40. package/sdk-core/core/src/worker/activities/local_activities.rs +19 -16
  41. package/sdk-core/core/src/worker/activities.rs +156 -29
  42. package/sdk-core/core/src/worker/client.rs +1 -0
  43. package/sdk-core/core/src/worker/mod.rs +132 -659
  44. package/sdk-core/core/src/{workflow → worker/workflow}/bridge.rs +1 -1
  45. package/sdk-core/core/src/{workflow → worker/workflow}/driven_workflow.rs +1 -1
  46. package/sdk-core/core/src/{workflow → worker/workflow}/history_update.rs +16 -2
  47. package/sdk-core/core/src/{workflow → worker/workflow}/machines/activity_state_machine.rs +39 -4
  48. package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_external_state_machine.rs +5 -2
  49. package/sdk-core/core/src/{workflow → worker/workflow}/machines/cancel_workflow_state_machine.rs +1 -1
  50. package/sdk-core/core/src/{workflow → worker/workflow}/machines/child_workflow_state_machine.rs +2 -4
  51. package/sdk-core/core/src/{workflow → worker/workflow}/machines/complete_workflow_state_machine.rs +0 -0
  52. package/sdk-core/core/src/{workflow → worker/workflow}/machines/continue_as_new_workflow_state_machine.rs +1 -1
  53. package/sdk-core/core/src/{workflow → worker/workflow}/machines/fail_workflow_state_machine.rs +0 -0
  54. package/sdk-core/core/src/{workflow → worker/workflow}/machines/local_activity_state_machine.rs +2 -5
  55. package/sdk-core/core/src/{workflow → worker/workflow}/machines/mod.rs +1 -1
  56. package/sdk-core/core/src/{workflow → worker/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
  57. package/sdk-core/core/src/{workflow → worker/workflow}/machines/patch_state_machine.rs +1 -1
  58. package/sdk-core/core/src/{workflow → worker/workflow}/machines/side_effect_state_machine.rs +0 -0
  59. package/sdk-core/core/src/{workflow → worker/workflow}/machines/signal_external_state_machine.rs +4 -2
  60. package/sdk-core/core/src/{workflow → worker/workflow}/machines/timer_state_machine.rs +1 -2
  61. package/sdk-core/core/src/{workflow → worker/workflow}/machines/transition_coverage.rs +1 -1
  62. package/sdk-core/core/src/{workflow → worker/workflow}/machines/upsert_search_attributes_state_machine.rs +5 -7
  63. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines/local_acts.rs +2 -2
  64. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_machines.rs +40 -16
  65. package/sdk-core/core/src/{workflow → worker/workflow}/machines/workflow_task_state_machine.rs +0 -0
  66. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
  67. package/sdk-core/core/src/worker/workflow/managed_run.rs +627 -0
  68. package/sdk-core/core/src/worker/workflow/mod.rs +1115 -0
  69. package/sdk-core/core/src/worker/workflow/run_cache.rs +143 -0
  70. package/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
  71. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +936 -0
  72. package/sdk-core/core-api/src/errors.rs +3 -10
  73. package/sdk-core/core-api/src/lib.rs +2 -1
  74. package/sdk-core/core-api/src/worker.rs +26 -2
  75. package/sdk-core/etc/dynamic-config.yaml +2 -0
  76. package/sdk-core/integ-with-otel.sh +1 -1
  77. package/sdk-core/protos/api_upstream/Makefile +4 -4
  78. package/sdk-core/protos/api_upstream/api-linter.yaml +2 -0
  79. package/sdk-core/protos/api_upstream/buf.yaml +8 -9
  80. package/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +83 -0
  81. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -1
  82. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +40 -0
  83. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +3 -0
  84. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +3 -1
  85. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
  86. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +3 -0
  87. package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +32 -4
  88. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +69 -19
  89. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +13 -0
  90. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +163 -0
  91. package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +97 -0
  92. package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +300 -0
  93. package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +25 -0
  94. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +180 -3
  95. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +53 -3
  96. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +2 -2
  97. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +6 -5
  98. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -1
  99. package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +2 -1
  100. package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +0 -64
  101. package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +2 -1
  102. package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +11 -8
  103. package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +30 -25
  104. package/sdk-core/sdk/src/activity_context.rs +12 -5
  105. package/sdk-core/sdk/src/app_data.rs +37 -0
  106. package/sdk-core/sdk/src/lib.rs +76 -43
  107. package/sdk-core/sdk/src/workflow_context/options.rs +8 -6
  108. package/sdk-core/sdk/src/workflow_context.rs +14 -19
  109. package/sdk-core/sdk/src/workflow_future.rs +11 -6
  110. package/sdk-core/sdk-core-protos/src/history_builder.rs +19 -5
  111. package/sdk-core/sdk-core-protos/src/history_info.rs +11 -6
  112. package/sdk-core/sdk-core-protos/src/lib.rs +74 -176
  113. package/sdk-core/test-utils/src/lib.rs +85 -72
  114. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -9
  115. package/sdk-core/tests/integ_tests/polling_tests.rs +12 -0
  116. package/sdk-core/tests/integ_tests/queries_tests.rs +39 -22
  117. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +49 -4
  118. package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
  119. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  120. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +74 -13
  121. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +19 -0
  122. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
  123. package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -3
  124. package/sdk-core/tests/integ_tests/workflow_tests.rs +10 -23
  125. package/sdk-core/tests/load_tests.rs +8 -3
  126. package/sdk-core/tests/main.rs +2 -1
  127. package/src/conversions.rs +47 -39
  128. package/src/errors.rs +10 -21
  129. package/src/lib.rs +342 -325
  130. package/sdk-core/core/src/pending_activations.rs +0 -173
  131. package/sdk-core/core/src/worker/wft_delivery.rs +0 -81
  132. package/sdk-core/core/src/workflow/mod.rs +0 -478
  133. package/sdk-core/core/src/workflow/workflow_tasks/cache_manager.rs +0 -194
  134. package/sdk-core/core/src/workflow/workflow_tasks/concurrency_manager.rs +0 -418
  135. package/sdk-core/core/src/workflow/workflow_tasks/mod.rs +0 -989
@@ -1,173 +0,0 @@
1
- use parking_lot::RwLock;
2
- use slotmap::SlotMap;
3
- use std::collections::{HashMap, VecDeque};
4
- use temporal_sdk_core_protos::coresdk::workflow_activation::{
5
- remove_from_cache::EvictionReason, RemoveFromCache,
6
- };
7
-
8
- /// Tracks pending activations using an internal queue, while also allowing lookup and removal of
9
- /// any pending activations by run ID.
10
- #[derive(Default)]
11
- pub struct PendingActivations {
12
- inner: RwLock<PaInner>,
13
- }
14
-
15
- slotmap::new_key_type! { struct ActivationKey; }
16
-
17
- #[derive(Default)]
18
- struct PaInner {
19
- activations: SlotMap<ActivationKey, PendingActInfo>,
20
- by_run_id: HashMap<String, ActivationKey>,
21
- // Holds the actual queue of activations
22
- queue: VecDeque<ActivationKey>,
23
- }
24
-
25
- #[derive(Debug)]
26
- pub struct PendingActInfo {
27
- pub needs_eviction: Option<RemoveFromCache>,
28
- pub run_id: String,
29
- }
30
-
31
- impl PendingActivations {
32
- /// Indicate that a run needs to be activated
33
- pub fn notify_needs_activation(&self, run_id: &str) {
34
- let mut inner = self.inner.write();
35
-
36
- if inner.by_run_id.get(run_id).is_none() {
37
- let key = inner.activations.insert(PendingActInfo {
38
- needs_eviction: None,
39
- run_id: run_id.to_string(),
40
- });
41
- inner.by_run_id.insert(run_id.to_string(), key);
42
- inner.queue.push_back(key);
43
- };
44
- }
45
-
46
- pub fn notify_needs_eviction(&self, run_id: &str, message: String, reason: EvictionReason) {
47
- let mut inner = self.inner.write();
48
-
49
- let evictjob = RemoveFromCache {
50
- message,
51
- reason: reason as i32,
52
- };
53
-
54
- if let Some(key) = inner.by_run_id.get(run_id).copied() {
55
- let act = inner
56
- .activations
57
- .get_mut(key)
58
- .expect("PA run id mapping is always in sync with slot map");
59
- act.needs_eviction = Some(evictjob);
60
- } else {
61
- let key = inner.activations.insert(PendingActInfo {
62
- needs_eviction: Some(evictjob),
63
- run_id: run_id.to_string(),
64
- });
65
- inner.by_run_id.insert(run_id.to_string(), key);
66
- inner.queue.push_back(key);
67
- };
68
- }
69
-
70
- pub fn pop_first_matching(&self, predicate: impl Fn(&str) -> bool) -> Option<PendingActInfo> {
71
- let mut inner = self.inner.write();
72
- let mut key_queue = inner.queue.iter().copied();
73
- let maybe_key = key_queue.position(|k| {
74
- inner
75
- .activations
76
- .get(k)
77
- .map_or(false, |activation| predicate(&activation.run_id))
78
- });
79
-
80
- let maybe_key = maybe_key.map(|pos| inner.queue.remove(pos).unwrap());
81
- maybe_key.and_then(|key| {
82
- if let Some(pa) = inner.activations.remove(key) {
83
- inner.by_run_id.remove(&pa.run_id);
84
- Some(pa)
85
- } else {
86
- // Keys no longer in the slot map are ignored, since they may have been removed
87
- // by run id or anything else. Try to pop the next thing from the queue. Recurse
88
- // to avoid double mutable borrow.
89
- drop(inner); // Will deadlock when we recurse w/o this
90
- self.pop_first_matching(predicate)
91
- }
92
- })
93
- }
94
-
95
- #[cfg(test)]
96
- pub fn pop(&self) -> Option<PendingActInfo> {
97
- self.pop_first_matching(|_| true)
98
- }
99
-
100
- pub fn has_pending(&self, run_id: &str) -> bool {
101
- self.inner.read().by_run_id.contains_key(run_id)
102
- }
103
-
104
- pub fn remove_all_with_run_id(&self, run_id: &str) {
105
- let mut inner = self.inner.write();
106
-
107
- if let Some(k) = inner.by_run_id.remove(run_id) {
108
- inner.activations.remove(k);
109
- }
110
- }
111
-
112
- /// Returns true if any pending activation contains an eviction
113
- pub fn is_some_eviction(&self) -> bool {
114
- self.inner
115
- .read()
116
- .activations
117
- .values()
118
- .any(|act| act.needs_eviction.is_some())
119
- }
120
- }
121
-
122
- #[cfg(test)]
123
- mod tests {
124
- use super::*;
125
-
126
- #[test]
127
- fn merges_same_ids_with_evictions() {
128
- let pas = PendingActivations::default();
129
- let rid1 = "1";
130
- let rid2 = "2";
131
- pas.notify_needs_activation(rid1);
132
- pas.notify_needs_eviction(rid1, "whatever".to_string(), EvictionReason::Unspecified);
133
- pas.notify_needs_eviction(rid2, "whatever".to_string(), EvictionReason::Unspecified);
134
- pas.notify_needs_activation(rid2);
135
- assert!(pas.has_pending(rid1));
136
- assert!(pas.has_pending(rid2));
137
- let last = pas.pop().unwrap();
138
- assert_eq!(&last.run_id, &rid1);
139
- assert!(!pas.has_pending(rid1));
140
- assert!(pas.has_pending(rid2));
141
- // Should only be one id 2, they are all merged
142
- let last = pas.pop().unwrap();
143
- assert_eq!(&last.run_id, &rid2);
144
- assert!(!pas.has_pending(rid2));
145
- assert!(pas.pop().is_none());
146
- }
147
-
148
- #[test]
149
- fn can_remove_all_with_id() {
150
- let pas = PendingActivations::default();
151
- let remove_me = "2";
152
- pas.notify_needs_activation("1");
153
- pas.notify_needs_activation(remove_me);
154
- pas.notify_needs_activation("3");
155
- pas.remove_all_with_run_id(remove_me);
156
- assert!(!pas.has_pending(remove_me));
157
- assert_eq!(&pas.pop().unwrap().run_id, "1");
158
- assert_eq!(&pas.pop().unwrap().run_id, "3");
159
- assert!(pas.pop().is_none());
160
- }
161
-
162
- #[test]
163
- fn can_ignore_specific_runs() {
164
- let pas = PendingActivations::default();
165
- pas.notify_needs_activation("1");
166
- pas.notify_needs_activation("2");
167
- assert_eq!(
168
- &pas.pop_first_matching(|rid| rid != "1").unwrap().run_id,
169
- "2"
170
- );
171
- assert_eq!(&pas.pop().unwrap().run_id, "1");
172
- }
173
- }
@@ -1,81 +0,0 @@
1
- use crate::{pollers, pollers::BoxedWFPoller};
2
- use crossbeam::queue::SegQueue;
3
- use temporal_sdk_core_protos::temporal::api::workflowservice::v1::PollWorkflowTaskQueueResponse;
4
- use tokio::sync::Notify;
5
-
6
- /// Workflow tasks typically come from polling, but may also come as a response to task completion.
7
- /// This struct allows fetching WFTs to be centralized while prioritizing tasks from completes.
8
- pub(crate) struct WFTSource {
9
- from_completions: SegQueue<PollWorkflowTaskQueueResponse>,
10
- poll_buffer: BoxedWFPoller,
11
- task_taken_notifier: Notify,
12
- }
13
-
14
- impl WFTSource {
15
- pub fn new(poller: BoxedWFPoller) -> Self {
16
- Self {
17
- from_completions: SegQueue::new(),
18
- poll_buffer: poller,
19
- task_taken_notifier: Notify::new(),
20
- }
21
- }
22
-
23
- /// Returns the next available WFT if one is already stored from a completion, otherwise
24
- /// forwards to the poller.
25
- pub async fn next_wft(&self) -> Option<pollers::Result<PollWorkflowTaskQueueResponse>> {
26
- if let Some(wft) = self.from_completions.pop() {
27
- self.task_taken_notifier.notify_one();
28
- return Some(Ok(wft));
29
- }
30
- self.poll_buffer.poll().await
31
- }
32
-
33
- /// Add a WFT received from the completion of another WFT
34
- pub fn add_wft_from_completion(&self, wft: PollWorkflowTaskQueueResponse) {
35
- self.from_completions.push(wft);
36
- }
37
-
38
- /// Notifies the pollers to stop polling
39
- pub fn stop_pollers(&self) {
40
- self.poll_buffer.notify_shutdown();
41
- }
42
-
43
- /// Returns true if there are tasks from completion buffered which need to be handled
44
- pub fn has_tasks_from_complete(&self) -> bool {
45
- !self.from_completions.is_empty()
46
- }
47
-
48
- /// Returns a future which resolves when all tasks from completions have been taken
49
- pub async fn wait_for_tasks_from_complete_to_drain(&self) {
50
- while !self.from_completions.is_empty() {
51
- self.task_taken_notifier.notified().await;
52
- }
53
- }
54
-
55
- /// Wait for poll shutdown to complete
56
- pub async fn shutdown(self) {
57
- self.poll_buffer.shutdown_box().await;
58
- }
59
- }
60
-
61
- #[cfg(test)]
62
- mod tests {
63
- use super::*;
64
- use crate::test_help::mock_poller;
65
-
66
- #[tokio::test]
67
- async fn drains_from_completes_on_shutdown() {
68
- let mp = mock_poller();
69
- let wftsrc = WFTSource::new(Box::new(mp));
70
- let fake_wft = PollWorkflowTaskQueueResponse {
71
- started_event_id: 1,
72
- ..Default::default()
73
- };
74
- wftsrc.add_wft_from_completion(fake_wft);
75
- let fake_wft = PollWorkflowTaskQueueResponse {
76
- started_event_id: 2,
77
- ..Default::default()
78
- };
79
- wftsrc.add_wft_from_completion(fake_wft);
80
- }
81
- }