@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
@@ -0,0 +1,936 @@
1
+ use crate::{
2
+ abstractions::{dbg_panic, stream_when_allowed, MeteredSemaphore},
3
+ protosext::ValidPollWFTQResponse,
4
+ telemetry::metrics::workflow_worker_type,
5
+ worker::{
6
+ workflow::{history_update::NextPageToken, run_cache::RunCache, *},
7
+ LocalActRequest, LocalActivityResolution, LEGACY_QUERY_ID,
8
+ },
9
+ MetricsContext, WorkerClientBag,
10
+ };
11
+ use futures::{stream, stream::PollNext, Stream, StreamExt};
12
+ use std::{collections::VecDeque, fmt::Debug, future, sync::Arc, time::Instant};
13
+ use temporal_sdk_core_api::errors::{PollWfError, WFMachinesError};
14
+ use temporal_sdk_core_protos::{
15
+ coresdk::{
16
+ workflow_activation::{
17
+ create_evict_activation, query_to_job, remove_from_cache::EvictionReason,
18
+ workflow_activation_job,
19
+ },
20
+ workflow_completion::Failure,
21
+ },
22
+ temporal::api::{enums::v1::WorkflowTaskFailedCause, failure::v1::Failure as TFailure},
23
+ };
24
+ use tokio::sync::{mpsc::unbounded_channel, oneshot};
25
+ use tokio_stream::wrappers::UnboundedReceiverStream;
26
+ use tokio_util::sync::CancellationToken;
27
+ use tracing::{Level, Span};
28
+
29
+ /// This struct holds all the state needed for tracking what workflow runs are currently cached
30
+ /// and how WFTs should be dispatched to them, etc.
31
+ ///
32
+ /// See [WFStream::build] for more
33
+ pub(crate) struct WFStream {
34
+ runs: RunCache,
35
+ /// Buffered polls for new runs which need a cache slot to open up before we can handle them
36
+ buffered_polls_need_cache_slot: VecDeque<PermittedWFT>,
37
+
38
+ /// Client for accessing server for history pagination etc.
39
+ client: Arc<WorkerClientBag>,
40
+
41
+ /// Ensures we stay at or below this worker's maximum concurrent workflow task limit
42
+ wft_semaphore: MeteredSemaphore,
43
+ shutdown_token: CancellationToken,
44
+
45
+ metrics: MetricsContext,
46
+ }
47
+ /// All possible inputs to the [WFStream]
48
+ #[derive(derive_more::From)]
49
+ enum WFStreamInput {
50
+ NewWft(PermittedWFT),
51
+ Local(LocalInput),
52
+ /// The stream given to us which represents the poller (or a mock) terminated.
53
+ PollerDead,
54
+ /// The stream given to us which represents the poller (or a mock) encountered a non-retryable
55
+ /// error while polling
56
+ PollerError(tonic::Status),
57
+ }
58
+ impl From<RunUpdateResponse> for WFStreamInput {
59
+ fn from(r: RunUpdateResponse) -> Self {
60
+ WFStreamInput::Local(LocalInput {
61
+ input: LocalInputs::RunUpdateResponse(r.kind),
62
+ span: r.span,
63
+ })
64
+ }
65
+ }
66
+ /// A non-poller-received input to the [WFStream]
67
+ pub(super) struct LocalInput {
68
+ pub input: LocalInputs,
69
+ pub span: Span,
70
+ }
71
+ /// Everything that _isn't_ a poll which may affect workflow state. Always higher priority than
72
+ /// new polls.
73
+ #[derive(Debug, derive_more::From)]
74
+ pub(super) enum LocalInputs {
75
+ Completion(WFActCompleteMsg),
76
+ LocalResolution(LocalResolutionMsg),
77
+ PostActivation(PostActivationMsg),
78
+ RunUpdateResponse(RunUpdateResponseKind),
79
+ RequestEviction(RequestEvictMsg),
80
+ GetStateInfo(GetStateInfoMsg),
81
+ }
82
+ #[derive(Debug, derive_more::From)]
83
+ #[allow(clippy::large_enum_variant)] // PollerDead only ever gets used once, so not important.
84
+ enum ExternalPollerInputs {
85
+ NewWft(PermittedWFT),
86
+ PollerDead,
87
+ PollerError(tonic::Status),
88
+ }
89
+ impl From<ExternalPollerInputs> for WFStreamInput {
90
+ fn from(l: ExternalPollerInputs) -> Self {
91
+ match l {
92
+ ExternalPollerInputs::NewWft(v) => WFStreamInput::NewWft(v),
93
+ ExternalPollerInputs::PollerDead => WFStreamInput::PollerDead,
94
+ ExternalPollerInputs::PollerError(e) => WFStreamInput::PollerError(e),
95
+ }
96
+ }
97
+ }
98
+
99
+ impl WFStream {
100
+ /// Constructs workflow state management and returns a stream which outputs activations.
101
+ ///
102
+ /// * `external_wfts` is a stream of validated poll responses as returned by a poller (or mock)
103
+ /// * `wfts_from_complete` is the recv side of a channel that new WFTs from completions should
104
+ /// come down.
105
+ /// * `local_rx` is a stream of actions that workflow state needs to see. Things like
106
+ /// completions, local activities finishing, etc. See [LocalInputs].
107
+ ///
108
+ /// These inputs are combined, along with an internal feedback channel for run-specific updates,
109
+ /// to form the inputs to a stream of [WFActStreamInput]s. The stream processor then takes
110
+ /// action on those inputs, and then may yield activations.
111
+ ///
112
+ /// Updating runs may need to do async work like fetching additional history. In order to
113
+ /// facilitate this, each run lives in its own task which is communicated with by sending
114
+ /// [RunAction]s and receiving [RunUpdateResponse]s via its [ManagedRunHandle].
115
+ pub(super) fn build(
116
+ basics: WorkflowBasics,
117
+ external_wfts: impl Stream<Item = Result<ValidPollWFTQResponse, tonic::Status>> + Send + 'static,
118
+ local_rx: impl Stream<Item = LocalInput> + Send + 'static,
119
+ client: Arc<WorkerClientBag>,
120
+ local_activity_request_sink: impl Fn(Vec<LocalActRequest>) -> Vec<LocalActivityResolution>
121
+ + Send
122
+ + Sync
123
+ + 'static,
124
+ ) -> impl Stream<Item = Result<ActivationOrAuto, PollWfError>> {
125
+ let wft_semaphore = MeteredSemaphore::new(
126
+ basics.max_outstanding_wfts,
127
+ basics.metrics.with_new_attrs([workflow_worker_type()]),
128
+ MetricsContext::available_task_slots,
129
+ );
130
+ let wft_sem_clone = wft_semaphore.clone();
131
+ let proceeder = move || {
132
+ let wft_sem_clone = wft_sem_clone.clone();
133
+ async move { wft_sem_clone.acquire_owned().await.unwrap() }
134
+ };
135
+ let poller_wfts = stream_when_allowed(external_wfts, proceeder);
136
+ let (run_update_tx, run_update_rx) = unbounded_channel();
137
+ let local_rx = stream::select(
138
+ local_rx.map(Into::into),
139
+ UnboundedReceiverStream::new(run_update_rx).map(Into::into),
140
+ );
141
+ let all_inputs = stream::select_with_strategy(
142
+ local_rx,
143
+ poller_wfts
144
+ .map(|(wft, permit)| match wft {
145
+ Ok(wft) => ExternalPollerInputs::NewWft(PermittedWFT { wft, permit }),
146
+ Err(e) => ExternalPollerInputs::PollerError(e),
147
+ })
148
+ .chain(stream::once(async { ExternalPollerInputs::PollerDead }))
149
+ .map(Into::into)
150
+ .boxed(),
151
+ // Priority always goes to the local stream
152
+ |_: &mut ()| PollNext::Left,
153
+ );
154
+ let mut state = WFStream {
155
+ buffered_polls_need_cache_slot: Default::default(),
156
+ runs: RunCache::new(
157
+ basics.max_cached_workflows,
158
+ client.namespace().to_string(),
159
+ run_update_tx,
160
+ Arc::new(local_activity_request_sink),
161
+ basics.metrics.clone(),
162
+ ),
163
+ client,
164
+ wft_semaphore,
165
+ shutdown_token: basics.shutdown_token,
166
+ metrics: basics.metrics,
167
+ };
168
+ all_inputs
169
+ .map(move |action| {
170
+ let span = span!(Level::DEBUG, "new_stream_input");
171
+ let _span_g = span.enter();
172
+
173
+ let maybe_activation = match action {
174
+ WFStreamInput::NewWft(pwft) => {
175
+ debug!(run_id=%pwft.wft.workflow_execution.run_id, "New WFT");
176
+ state.instantiate_or_update(pwft);
177
+ None
178
+ }
179
+ WFStreamInput::Local(local_input) => {
180
+ let _span_g = local_input.span.enter();
181
+ match local_input.input {
182
+ LocalInputs::RunUpdateResponse(resp) => {
183
+ state.process_run_update_response(resp)
184
+ }
185
+ LocalInputs::Completion(completion) => {
186
+ state.process_completion(completion);
187
+ None
188
+ }
189
+ LocalInputs::PostActivation(report) => {
190
+ state.process_post_activation(report);
191
+ None
192
+ }
193
+ LocalInputs::LocalResolution(res) => {
194
+ state.local_resolution(res);
195
+ None
196
+ }
197
+ LocalInputs::RequestEviction(evict) => {
198
+ state.request_eviction(evict);
199
+ None
200
+ }
201
+ LocalInputs::GetStateInfo(gsi) => {
202
+ let _ = gsi.response_tx.send(WorkflowStateInfo {
203
+ cached_workflows: state.runs.len(),
204
+ outstanding_wft: state.outstanding_wfts(),
205
+ available_wft_permits: state.wft_semaphore.available_permits(),
206
+ });
207
+ None
208
+ }
209
+ }
210
+ }
211
+ WFStreamInput::PollerDead => {
212
+ warn!("WFT poller died, shutting down");
213
+ state.shutdown_token.cancel();
214
+ None
215
+ }
216
+ WFStreamInput::PollerError(e) => {
217
+ warn!("WFT poller errored, shutting down");
218
+ return Err(PollWfError::TonicError(e));
219
+ }
220
+ };
221
+
222
+ if let Some(ref act) = maybe_activation {
223
+ if let Some(run_handle) = state.runs.get_mut(act.run_id()) {
224
+ run_handle.insert_outstanding_activation(act);
225
+ } else {
226
+ dbg_panic!("Tried to insert activation for missing run!");
227
+ }
228
+ }
229
+ state.reconcile_buffered();
230
+ if state.shutdown_done() {
231
+ return Err(PollWfError::ShutDown);
232
+ }
233
+
234
+ Ok(maybe_activation)
235
+ })
236
+ .filter_map(|o| {
237
+ future::ready(match o {
238
+ Ok(None) => None,
239
+ Ok(Some(v)) => Some(Ok(v)),
240
+ Err(e) => {
241
+ if !matches!(e, PollWfError::ShutDown) {
242
+ error!(
243
+ "Workflow processing encountered fatal error and must shut down {:?}",
244
+ e
245
+ );
246
+ }
247
+ Some(Err(e))
248
+ }
249
+ })
250
+ })
251
+ // Stop the stream once we have shut down
252
+ .take_while(|o| future::ready(!matches!(o, Err(PollWfError::ShutDown))))
253
+ }
254
+
255
+ fn process_run_update_response(
256
+ &mut self,
257
+ resp: RunUpdateResponseKind,
258
+ ) -> Option<ActivationOrAuto> {
259
+ debug!(resp=%resp, "Processing run update response from machines");
260
+ match resp {
261
+ RunUpdateResponseKind::Good(mut resp) => {
262
+ if let Some(r) = self.runs.get_mut(&resp.run_id) {
263
+ r.have_seen_terminal_event = resp.have_seen_terminal_event;
264
+ r.more_pending_work = resp.more_pending_work;
265
+ r.last_action_acked = true;
266
+ r.most_recently_processed_event_number =
267
+ resp.most_recently_processed_event_number;
268
+ }
269
+ let run_handle = self
270
+ .runs
271
+ .get_mut(&resp.run_id)
272
+ .expect("Workflow must exist, it just sent us an update response");
273
+
274
+ let r = match resp.outgoing_activation {
275
+ Some(ActivationOrAuto::LangActivation(mut activation)) => {
276
+ if resp.in_response_to_wft {
277
+ let wft = run_handle
278
+ .wft
279
+ .as_mut()
280
+ .expect("WFT must exist for run just updated with one");
281
+ // If there are in-poll queries, insert jobs for those queries into the
282
+ // activation, but only if we hit the cache. If we didn't, those queries
283
+ // will need to be dealt with once replay is over
284
+ if !wft.pending_queries.is_empty() && wft.hit_cache {
285
+ put_queries_in_act(&mut activation, wft);
286
+ }
287
+ }
288
+
289
+ if activation.jobs.is_empty() {
290
+ dbg_panic!("Should not send lang activation with no jobs");
291
+ }
292
+ Some(ActivationOrAuto::LangActivation(activation))
293
+ }
294
+ Some(ActivationOrAuto::ReadyForQueries(mut act)) => {
295
+ if let Some(wft) = run_handle.wft.as_mut() {
296
+ put_queries_in_act(&mut act, wft);
297
+ Some(ActivationOrAuto::LangActivation(act))
298
+ } else {
299
+ dbg_panic!("Ready for queries but no WFT!");
300
+ None
301
+ }
302
+ }
303
+ a @ Some(ActivationOrAuto::Autocomplete { .. }) => a,
304
+ None => {
305
+ // If the response indicates there is no activation to send yet but there
306
+ // is more pending work, we should check again.
307
+ if resp.more_pending_work {
308
+ run_handle.check_more_activations();
309
+ None
310
+ } else if let Some(reason) = run_handle.trying_to_evict.as_ref() {
311
+ // If a run update came back and had nothing to do, but we're trying to
312
+ // evict, just do that now as long as there's no other outstanding work.
313
+ if run_handle.activation.is_none() && !run_handle.more_pending_work {
314
+ let evict_act = create_evict_activation(
315
+ resp.run_id,
316
+ reason.message.clone(),
317
+ reason.reason,
318
+ );
319
+ Some(ActivationOrAuto::LangActivation(evict_act))
320
+ } else {
321
+ None
322
+ }
323
+ } else {
324
+ None
325
+ }
326
+ }
327
+ };
328
+ if let Some(f) = resp.fulfillable_complete.take() {
329
+ f.fulfill();
330
+ }
331
+
332
+ // After each run update, check if it's ready to handle any buffered poll
333
+ if matches!(&r, Some(ActivationOrAuto::Autocomplete { .. }) | None)
334
+ && !run_handle.has_any_pending_work(false, true)
335
+ {
336
+ if let Some(bufft) = run_handle.buffered_resp.take() {
337
+ self.instantiate_or_update(bufft);
338
+ }
339
+ }
340
+ r
341
+ }
342
+ RunUpdateResponseKind::Fail(fail) => {
343
+ if let Some(r) = self.runs.get_mut(&fail.run_id) {
344
+ r.last_action_acked = true;
345
+ }
346
+
347
+ if let Some(resp_chan) = fail.completion_resp {
348
+ // Automatically fail the workflow task in the event we couldn't update machines
349
+ let fail_cause = if matches!(&fail.err, WFMachinesError::Nondeterminism(_)) {
350
+ WorkflowTaskFailedCause::NonDeterministicError
351
+ } else {
352
+ WorkflowTaskFailedCause::Unspecified
353
+ };
354
+ let wft_fail_str = format!("{:?}", fail.err);
355
+ self.failed_completion(
356
+ fail.run_id,
357
+ fail_cause,
358
+ fail.err.evict_reason(),
359
+ TFailure::application_failure(wft_fail_str, false).into(),
360
+ resp_chan,
361
+ );
362
+ } else {
363
+ // TODO: This should probably also fail workflow tasks, but that wasn't
364
+ // implemented pre-refactor either.
365
+ warn!(error=?fail.err, run_id=%fail.run_id, "Error while updating workflow");
366
+ self.request_eviction(RequestEvictMsg {
367
+ run_id: fail.run_id,
368
+ message: format!("Error while updating workflow: {:?}", fail.err),
369
+ reason: fail.err.evict_reason(),
370
+ });
371
+ }
372
+ None
373
+ }
374
+ }
375
+ }
376
+
377
+ #[instrument(level = "debug", skip(self, pwft),
378
+ fields(run_id=%pwft.wft.workflow_execution.run_id))]
379
+ fn instantiate_or_update(&mut self, pwft: PermittedWFT) {
380
+ let (mut work, permit) = if let Some(w) = self.buffer_resp_if_outstanding_work(pwft) {
381
+ (w.wft, w.permit)
382
+ } else {
383
+ return;
384
+ };
385
+
386
+ let run_id = work.workflow_execution.run_id.clone();
387
+ // If our cache is full and this WFT is for an unseen run we must first evict a run before
388
+ // we can deal with this task. So, buffer the task in that case.
389
+ if !self.runs.has_run(&run_id) && self.runs.is_full() {
390
+ self.buffer_resp_on_full_cache(PermittedWFT { wft: work, permit });
391
+ return;
392
+ }
393
+
394
+ let start_event_id = work.history.events.first().map(|e| e.event_id);
395
+ debug!(
396
+ run_id = %run_id,
397
+ task_token = %&work.task_token,
398
+ history_length = %work.history.events.len(),
399
+ start_event_id = ?start_event_id,
400
+ has_legacy_query = %work.legacy_query.is_some(),
401
+ attempt = %work.attempt,
402
+ "Applying new workflow task from server"
403
+ );
404
+
405
+ let wft_info = WorkflowTaskInfo {
406
+ attempt: work.attempt,
407
+ task_token: work.task_token,
408
+ };
409
+ let poll_resp_is_incremental = work
410
+ .history
411
+ .events
412
+ .get(0)
413
+ .map(|ev| ev.event_id > 1)
414
+ .unwrap_or_default();
415
+ let poll_resp_is_incremental = poll_resp_is_incremental || work.history.events.is_empty();
416
+
417
+ let mut did_miss_cache = !poll_resp_is_incremental;
418
+
419
+ let page_token = if !self.runs.has_run(&run_id) && poll_resp_is_incremental {
420
+ debug!(run_id=?run_id, "Workflow task has partial history, but workflow is not in \
421
+ cache. Will fetch history");
422
+ self.metrics.sticky_cache_miss();
423
+ did_miss_cache = true;
424
+ NextPageToken::FetchFromStart
425
+ } else {
426
+ work.next_page_token.into()
427
+ };
428
+ let history_update = HistoryUpdate::new(
429
+ HistoryPaginator::new(
430
+ work.history,
431
+ work.workflow_execution.workflow_id.clone(),
432
+ run_id.clone(),
433
+ page_token,
434
+ self.client.clone(),
435
+ ),
436
+ work.previous_started_event_id,
437
+ );
438
+ let legacy_query_from_poll = work
439
+ .legacy_query
440
+ .take()
441
+ .map(|q| query_to_job(LEGACY_QUERY_ID.to_string(), q));
442
+
443
+ let mut pending_queries = work.query_requests.into_iter().collect::<Vec<_>>();
444
+ if !pending_queries.is_empty() && legacy_query_from_poll.is_some() {
445
+ error!(
446
+ "Server issued both normal and legacy queries. This should not happen. Please \
447
+ file a bug report."
448
+ );
449
+ self.request_eviction(RequestEvictMsg {
450
+ run_id,
451
+ message: "Server issued both normal and legacy query".to_string(),
452
+ reason: EvictionReason::Fatal,
453
+ });
454
+ return;
455
+ }
456
+ if let Some(lq) = legacy_query_from_poll {
457
+ pending_queries.push(lq);
458
+ }
459
+
460
+ let start_time = Instant::now();
461
+ let run_handle = self.runs.instantiate_or_update(
462
+ &run_id,
463
+ &work.workflow_execution.workflow_id,
464
+ &work.workflow_type,
465
+ history_update,
466
+ start_time,
467
+ );
468
+ run_handle.wft = Some(OutstandingTask {
469
+ info: wft_info,
470
+ hit_cache: !did_miss_cache,
471
+ pending_queries,
472
+ start_time,
473
+ permit,
474
+ })
475
+ }
476
+
477
+ #[instrument(level = "debug", skip(self, complete),
478
+ fields(run_id=%complete.completion.run_id()))]
479
+ fn process_completion(&mut self, complete: WFActCompleteMsg) {
480
+ match complete.completion {
481
+ ValidatedCompletion::Success { run_id, commands } => {
482
+ self.successful_completion(run_id, commands, complete.response_tx);
483
+ }
484
+ ValidatedCompletion::Fail { run_id, failure } => {
485
+ self.failed_completion(
486
+ run_id,
487
+ WorkflowTaskFailedCause::Unspecified,
488
+ EvictionReason::LangFail,
489
+ failure,
490
+ complete.response_tx,
491
+ );
492
+ }
493
+ }
494
+ // Always queue evictions after completion when we have a zero-size cache
495
+ if self.runs.cache_capacity() == 0 {
496
+ self.request_eviction_of_lru_run();
497
+ }
498
+ }
499
+
500
+ fn successful_completion(
501
+ &mut self,
502
+ run_id: String,
503
+ mut commands: Vec<WFCommand>,
504
+ resp_chan: oneshot::Sender<ActivationCompleteResult>,
505
+ ) {
506
+ let activation_was_only_eviction = self.activation_has_only_eviction(&run_id);
507
+ let (task_token, has_pending_query, start_time) =
508
+ if let Some(entry) = self.get_task(&run_id) {
509
+ (
510
+ entry.info.task_token.clone(),
511
+ !entry.pending_queries.is_empty(),
512
+ entry.start_time,
513
+ )
514
+ } else {
515
+ if !activation_was_only_eviction {
516
+ // Not an error if this was an eviction, since it's normal to issue eviction
517
+ // activations without an associated workflow task in that case.
518
+ dbg_panic!(
519
+ "Attempted to complete activation for run {} without associated workflow task",
520
+ run_id
521
+ );
522
+ }
523
+ self.reply_to_complete(&run_id, ActivationCompleteOutcome::DoNothing, resp_chan);
524
+ return;
525
+ };
526
+
527
+ // If the only command from the activation is a legacy query response, that means we need
528
+ // to respond differently than a typical activation.
529
+ if matches!(&commands.as_slice(),
530
+ &[WFCommand::QueryResponse(qr)] if qr.query_id == LEGACY_QUERY_ID)
531
+ {
532
+ let qr = match commands.remove(0) {
533
+ WFCommand::QueryResponse(qr) => qr,
534
+ _ => unreachable!("We just verified this is the only command"),
535
+ };
536
+ self.reply_to_complete(
537
+ &run_id,
538
+ ActivationCompleteOutcome::ReportWFTSuccess(ServerCommandsWithWorkflowInfo {
539
+ task_token,
540
+ action: ActivationAction::RespondLegacyQuery { result: qr },
541
+ }),
542
+ resp_chan,
543
+ );
544
+ } else {
545
+ // First strip out query responses from other commands that actually affect machines
546
+ // Would be prettier with `drain_filter`
547
+ let mut i = 0;
548
+ let mut query_responses = vec![];
549
+ while i < commands.len() {
550
+ if matches!(commands[i], WFCommand::QueryResponse(_)) {
551
+ if let WFCommand::QueryResponse(qr) = commands.remove(i) {
552
+ query_responses.push(qr);
553
+ }
554
+ } else {
555
+ i += 1;
556
+ }
557
+ }
558
+
559
+ let activation_was_eviction = self.activation_has_eviction(&run_id);
560
+ if let Some(rh) = self.runs.get_mut(&run_id) {
561
+ rh.send_completion(RunActivationCompletion {
562
+ task_token,
563
+ start_time,
564
+ commands,
565
+ activation_was_eviction,
566
+ activation_was_only_eviction,
567
+ has_pending_query,
568
+ query_responses,
569
+ resp_chan: Some(resp_chan),
570
+ });
571
+ } else {
572
+ dbg_panic!("Run {} missing during completion", run_id);
573
+ }
574
+ };
575
+ }
576
+
577
+ fn failed_completion(
578
+ &mut self,
579
+ run_id: String,
580
+ cause: WorkflowTaskFailedCause,
581
+ reason: EvictionReason,
582
+ failure: Failure,
583
+ resp_chan: oneshot::Sender<ActivationCompleteResult>,
584
+ ) {
585
+ let tt = if let Some(tt) = self.get_task(&run_id).map(|t| t.info.task_token.clone()) {
586
+ tt
587
+ } else {
588
+ dbg_panic!(
589
+ "No workflow task for run id {} found when trying to fail activation",
590
+ run_id
591
+ );
592
+ self.reply_to_complete(&run_id, ActivationCompleteOutcome::DoNothing, resp_chan);
593
+ return;
594
+ };
595
+
596
+ if let Some(m) = self.run_metrics(&run_id) {
597
+ m.wf_task_failed();
598
+ }
599
+ let message = format!("Workflow activation completion failed: {:?}", &failure);
600
+ // Blow up any cached data associated with the workflow
601
+ let should_report = match self.request_eviction(RequestEvictMsg {
602
+ run_id: run_id.clone(),
603
+ message,
604
+ reason,
605
+ }) {
606
+ EvictionRequestResult::EvictionRequested(Some(attempt))
607
+ | EvictionRequestResult::EvictionAlreadyRequested(Some(attempt)) => attempt <= 1,
608
+ _ => false,
609
+ };
610
+ // If the outstanding WFT is a legacy query task, report that we need to fail it
611
+ let outcome = if self
612
+ .runs
613
+ .get(&run_id)
614
+ .map(|rh| rh.pending_work_is_legacy_query())
615
+ .unwrap_or_default()
616
+ {
617
+ ActivationCompleteOutcome::ReportWFTFail(
618
+ FailedActivationWFTReport::ReportLegacyQueryFailure(tt, failure),
619
+ )
620
+ } else if should_report {
621
+ ActivationCompleteOutcome::ReportWFTFail(FailedActivationWFTReport::Report(
622
+ tt, cause, failure,
623
+ ))
624
+ } else {
625
+ ActivationCompleteOutcome::DoNothing
626
+ };
627
+ self.reply_to_complete(&run_id, outcome, resp_chan);
628
+ }
629
+
630
+ fn process_post_activation(&mut self, report: PostActivationMsg) {
631
+ let run_id = &report.run_id;
632
+
633
+ // If we reported to server, we always want to mark it complete.
634
+ let maybe_t = self.complete_wft(run_id, report.reported_wft_to_server);
635
+
636
+ if self
637
+ .get_activation(run_id)
638
+ .map(|a| a.has_eviction())
639
+ .unwrap_or_default()
640
+ {
641
+ self.evict_run(run_id);
642
+ };
643
+
644
+ if let Some(wft) = report.wft_from_complete {
645
+ debug!(run_id=%wft.workflow_execution.run_id, "New WFT from completion");
646
+ if let Some(t) = maybe_t {
647
+ self.instantiate_or_update(PermittedWFT {
648
+ wft,
649
+ permit: t.permit,
650
+ })
651
+ }
652
+ }
653
+
654
+ if let Some(rh) = self.runs.get_mut(run_id) {
655
+ // Delete the activation
656
+ rh.activation.take();
657
+ // Attempt to produce the next activation if needed
658
+ rh.check_more_activations();
659
+ }
660
+ }
661
+
662
+ fn local_resolution(&mut self, msg: LocalResolutionMsg) {
663
+ let run_id = msg.run_id;
664
+ if let Some(rh) = self.runs.get_mut(&run_id) {
665
+ rh.send_local_resolution(msg.res)
666
+ } else {
667
+ // It isn't an explicit error if the machine is missing when a local activity resolves.
668
+ // This can happen if an activity reports a timeout after we stopped caring about it.
669
+ debug!(run_id = %run_id,
670
+ "Tried to resolve a local activity for a run we are no longer tracking");
671
+ }
672
+ }
673
+
674
+ /// Request a workflow eviction. This will (eventually, after replay is done) queue up an
675
+ /// activation to evict the workflow from the lang side. Workflow will not *actually* be evicted
676
+ /// until lang replies to that activation
677
+ fn request_eviction(&mut self, info: RequestEvictMsg) -> EvictionRequestResult {
678
+ let activation_has_eviction = self.activation_has_eviction(&info.run_id);
679
+ if let Some(rh) = self.runs.get_mut(&info.run_id) {
680
+ let attempts = rh.wft.as_ref().map(|wt| wt.info.attempt);
681
+ if !activation_has_eviction && rh.trying_to_evict.is_none() {
682
+ debug!(run_id=%info.run_id, reason=%info.message, "Eviction requested");
683
+ rh.trying_to_evict = Some(info);
684
+ rh.check_more_activations();
685
+ EvictionRequestResult::EvictionRequested(attempts)
686
+ } else {
687
+ EvictionRequestResult::EvictionAlreadyRequested(attempts)
688
+ }
689
+ } else {
690
+ warn!(run_id=%info.run_id, "Eviction requested for unknown run");
691
+ EvictionRequestResult::NotFound
692
+ }
693
+ }
694
+
695
+ fn request_eviction_of_lru_run(&mut self) -> EvictionRequestResult {
696
+ if let Some(lru_run_id) = self.runs.current_lru_run() {
697
+ let run_id = lru_run_id.to_string();
698
+ self.request_eviction(RequestEvictMsg {
699
+ run_id,
700
+ message: "Workflow cache full".to_string(),
701
+ reason: EvictionReason::CacheFull,
702
+ })
703
+ } else {
704
+ // This branch shouldn't really be possible
705
+ EvictionRequestResult::NotFound
706
+ }
707
+ }
708
+
709
+ /// Evict a workflow from the cache by its run id. Any existing pending activations will be
710
+ /// destroyed, and any outstanding activations invalidated.
711
+ fn evict_run(&mut self, run_id: &str) {
712
+ debug!(run_id=%run_id, "Evicting run");
713
+
714
+ let mut did_take_buff = false;
715
+ // Now it can safely be deleted, it'll get recreated once the un-buffered poll is handled if
716
+ // there was one.
717
+ if let Some(mut rh) = self.runs.remove(run_id) {
718
+ rh.handle.abort();
719
+
720
+ if let Some(buff) = rh.buffered_resp.take() {
721
+ self.instantiate_or_update(buff);
722
+ did_take_buff = true;
723
+ }
724
+ }
725
+
726
+ if !did_take_buff {
727
+ // If there wasn't a buffered poll, there might be one for a different run which needs
728
+ // a free cache slot, and now there is.
729
+ if let Some(buff) = self.buffered_polls_need_cache_slot.pop_front() {
730
+ self.instantiate_or_update(buff);
731
+ }
732
+ }
733
+ }
734
+
735
+ fn complete_wft(
736
+ &mut self,
737
+ run_id: &str,
738
+ reported_wft_to_server: bool,
739
+ ) -> Option<OutstandingTask> {
740
+ // If the WFT completion wasn't sent to the server, but we did see the final event, we still
741
+ // want to clear the workflow task. This can really only happen in replay testing, where we
742
+ // will generate poll responses with complete history but no attached query, and such a WFT
743
+ // would never really exist. The server wouldn't send a workflow task with nothing to do,
744
+ // but they are very useful for testing complete replay.
745
+ let saw_final = self
746
+ .runs
747
+ .get(run_id)
748
+ .map(|r| r.have_seen_terminal_event)
749
+ .unwrap_or_default();
750
+ if !saw_final && !reported_wft_to_server {
751
+ return None;
752
+ }
753
+
754
+ if let Some(rh) = self.runs.get_mut(run_id) {
755
+ // Can't mark the WFT complete if there are pending queries, as doing so would destroy
756
+ // them.
757
+ if rh
758
+ .wft
759
+ .as_ref()
760
+ .map(|wft| !wft.pending_queries.is_empty())
761
+ .unwrap_or_default()
762
+ {
763
+ return None;
764
+ }
765
+
766
+ debug!("Marking WFT completed");
767
+ let retme = rh.wft.take();
768
+ if let Some(ot) = &retme {
769
+ if let Some(m) = self.run_metrics(run_id) {
770
+ m.wf_task_latency(ot.start_time.elapsed());
771
+ }
772
+ }
773
+ retme
774
+ } else {
775
+ None
776
+ }
777
+ }
778
+
779
+ /// Stores some work if there is any outstanding WFT or activation for the run. If there was
780
+ /// not, returns the work back out inside the option.
781
+ fn buffer_resp_if_outstanding_work(&mut self, work: PermittedWFT) -> Option<PermittedWFT> {
782
+ let run_id = &work.wft.workflow_execution.run_id;
783
+ if let Some(mut run) = self.runs.get_mut(run_id) {
784
+ let about_to_issue_evict = run.trying_to_evict.is_some() && !run.last_action_acked;
785
+ let has_wft = run.wft.is_some();
786
+ let has_activation = run.activation.is_some();
787
+ if has_wft
788
+ || has_activation
789
+ || about_to_issue_evict
790
+ || run.more_pending_work
791
+ || !run.last_action_acked
792
+ {
793
+ debug!(run_id = %run_id, run = ?run,
794
+ "Got new WFT for a run with outstanding work, buffering it");
795
+ run.buffered_resp = Some(work);
796
+ None
797
+ } else {
798
+ Some(work)
799
+ }
800
+ } else {
801
+ Some(work)
802
+ }
803
+ }
804
+
805
+ fn buffer_resp_on_full_cache(&mut self, work: PermittedWFT) {
806
+ debug!(run_id=%work.wft.workflow_execution.run_id, "Buffering WFT because cache is full");
807
+ // If there's already a buffered poll for the run, replace it.
808
+ if let Some(rh) = self
809
+ .buffered_polls_need_cache_slot
810
+ .iter_mut()
811
+ .find(|w| w.wft.workflow_execution.run_id == work.wft.workflow_execution.run_id)
812
+ {
813
+ *rh = work;
814
+ } else {
815
+ // Otherwise push it to the back
816
+ self.buffered_polls_need_cache_slot.push_back(work);
817
+ }
818
+ }
819
+
820
+ /// Makes sure we have enough pending evictions to fulfill the needs of buffered WFTs who are
821
+ /// waiting on a cache slot
822
+ fn reconcile_buffered(&mut self) {
823
+ // We must ensure that there are at least as many pending evictions as there are tasks
824
+ // that we might need to un-buffer (skipping runs which already have buffered tasks for
825
+ // themselves)
826
+ let num_in_buff = self.buffered_polls_need_cache_slot.len();
827
+ let mut evict_these = vec![];
828
+ let num_existing_evictions = self
829
+ .runs
830
+ .runs_lru_order()
831
+ .filter(|(_, h)| h.trying_to_evict.is_some())
832
+ .count();
833
+ let mut num_evicts_needed = num_in_buff.saturating_sub(num_existing_evictions);
834
+ for (rid, handle) in self.runs.runs_lru_order() {
835
+ if num_evicts_needed == 0 {
836
+ break;
837
+ }
838
+ if handle.buffered_resp.is_none() {
839
+ num_evicts_needed -= 1;
840
+ evict_these.push(rid.to_string());
841
+ }
842
+ }
843
+ for run_id in evict_these {
844
+ self.request_eviction(RequestEvictMsg {
845
+ run_id,
846
+ message: "Workflow cache full".to_string(),
847
+ reason: EvictionReason::CacheFull,
848
+ });
849
+ }
850
+ }
851
+
852
+ fn reply_to_complete(
853
+ &self,
854
+ run_id: &str,
855
+ outcome: ActivationCompleteOutcome,
856
+ chan: oneshot::Sender<ActivationCompleteResult>,
857
+ ) {
858
+ let most_recently_processed_event = self
859
+ .runs
860
+ .peek(run_id)
861
+ .map(|rh| rh.most_recently_processed_event_number)
862
+ .unwrap_or_default();
863
+ chan.send(ActivationCompleteResult {
864
+ most_recently_processed_event,
865
+ outcome,
866
+ })
867
+ .expect("Rcv half of activation reply not dropped");
868
+ }
869
+
870
+ fn shutdown_done(&self) -> bool {
871
+ let all_runs_ready = self
872
+ .runs
873
+ .handles()
874
+ .all(|r| !r.has_any_pending_work(true, false));
875
+ if self.shutdown_token.is_cancelled() && all_runs_ready {
876
+ info!("Workflow shutdown is done");
877
+ true
878
+ } else {
879
+ false
880
+ }
881
+ }
882
+
883
+ fn get_task(&mut self, run_id: &str) -> Option<&OutstandingTask> {
884
+ self.runs.get(run_id).and_then(|rh| rh.wft.as_ref())
885
+ }
886
+
887
+ fn get_activation(&mut self, run_id: &str) -> Option<&OutstandingActivation> {
888
+ self.runs.get(run_id).and_then(|rh| rh.activation.as_ref())
889
+ }
890
+
891
+ fn run_metrics(&mut self, run_id: &str) -> Option<&MetricsContext> {
892
+ self.runs.get(run_id).map(|r| &r.metrics)
893
+ }
894
+
895
+ fn activation_has_only_eviction(&mut self, run_id: &str) -> bool {
896
+ self.runs
897
+ .get(run_id)
898
+ .and_then(|rh| rh.activation)
899
+ .map(OutstandingActivation::has_only_eviction)
900
+ .unwrap_or_default()
901
+ }
902
+
903
+ fn activation_has_eviction(&mut self, run_id: &str) -> bool {
904
+ self.runs
905
+ .get(run_id)
906
+ .and_then(|rh| rh.activation)
907
+ .map(OutstandingActivation::has_eviction)
908
+ .unwrap_or_default()
909
+ }
910
+
911
+ fn outstanding_wfts(&self) -> usize {
912
+ self.runs.handles().filter(|r| r.wft.is_some()).count()
913
+ }
914
+
915
+ // Useful when debugging
916
+ #[allow(dead_code)]
917
+ fn info_dump(&self, run_id: &str) {
918
+ if let Some(r) = self.runs.peek(run_id) {
919
+ info!(run_id, wft=?r.wft, activation=?r.activation, buffered=r.buffered_resp.is_some(),
920
+ trying_to_evict=r.trying_to_evict.is_some(), more_work=r.more_pending_work,
921
+ last_action_acked=r.last_action_acked);
922
+ } else {
923
+ info!(run_id, "Run not found");
924
+ }
925
+ }
926
+ }
927
+
928
+ /// Drains pending queries from the workflow task and appends them to the activation's jobs
929
+ fn put_queries_in_act(act: &mut WorkflowActivation, wft: &mut OutstandingTask) {
930
+ debug!(queries=?wft.pending_queries, "Dispatching queries");
931
+ let query_jobs = wft
932
+ .pending_queries
933
+ .drain(..)
934
+ .map(|q| workflow_activation_job::Variant::QueryWorkflow(q).into());
935
+ act.jobs.extend(query_jobs);
936
+ }