@temporalio/core-bridge 1.7.4 → 1.8.1
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.
- package/Cargo.lock +245 -247
- package/Cargo.toml +1 -1
- package/lib/errors.d.ts +9 -0
- package/lib/errors.js +13 -0
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +19 -3
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
- package/releases/x86_64-apple-darwin/index.node +0 -0
- package/releases/x86_64-pc-windows-msvc/index.node +0 -0
- package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
- package/sdk-core/.github/workflows/heavy.yml +1 -1
- package/sdk-core/.github/workflows/semgrep.yml +25 -0
- package/sdk-core/README.md +2 -0
- package/sdk-core/cargo-tokio-console.sh +5 -0
- package/sdk-core/client/src/lib.rs +6 -41
- package/sdk-core/client/src/raw.rs +9 -0
- package/sdk-core/client/src/retry.rs +0 -16
- package/sdk-core/core/Cargo.toml +9 -5
- package/sdk-core/core/src/abstractions.rs +7 -75
- package/sdk-core/core/src/core_tests/activity_tasks.rs +16 -8
- package/sdk-core/core/src/core_tests/local_activities.rs +97 -5
- package/sdk-core/core/src/core_tests/mod.rs +1 -1
- package/sdk-core/core/src/core_tests/workers.rs +16 -16
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +247 -28
- package/sdk-core/core/src/lib.rs +2 -3
- package/sdk-core/core/src/pollers/mod.rs +30 -3
- package/sdk-core/core/src/pollers/poll_buffer.rs +166 -77
- package/sdk-core/core/src/protosext/mod.rs +4 -8
- package/sdk-core/core/src/replay/mod.rs +1 -1
- package/sdk-core/core/src/telemetry/metrics.rs +9 -0
- package/sdk-core/core/src/telemetry/mod.rs +3 -0
- package/sdk-core/core/src/test_help/mod.rs +9 -16
- package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +6 -31
- package/sdk-core/core/src/worker/activities/local_activities.rs +214 -110
- package/sdk-core/core/src/worker/activities.rs +72 -47
- package/sdk-core/core/src/worker/client/mocks.rs +1 -1
- package/sdk-core/core/src/worker/client.rs +45 -32
- package/sdk-core/core/src/worker/mod.rs +170 -122
- package/sdk-core/core/src/worker/workflow/driven_workflow.rs +0 -4
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +9 -2
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +9 -2
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +6 -3
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +74 -22
- package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +3 -2
- package/sdk-core/core/src/worker/workflow/managed_run.rs +16 -3
- package/sdk-core/core/src/worker/workflow/mod.rs +13 -22
- package/sdk-core/core/src/worker/workflow/run_cache.rs +5 -0
- package/sdk-core/core/src/worker/workflow/wft_extraction.rs +4 -7
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +38 -8
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +1 -0
- package/sdk-core/core-api/src/worker.rs +43 -2
- package/sdk-core/protos/api_upstream/Makefile +1 -1
- package/sdk-core/protos/api_upstream/buf.yaml +1 -6
- package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -0
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +11 -0
- package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +1 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +9 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +19 -0
- package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +5 -0
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +36 -4
- package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +24 -7
- package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +4 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +76 -44
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +23 -1
- package/sdk-core/protos/google/rpc/status.proto +52 -0
- package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +16 -0
- package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -0
- package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +6 -0
- package/sdk-core/sdk/src/lib.rs +31 -10
- package/sdk-core/sdk/src/workflow_future.rs +7 -5
- package/sdk-core/sdk-core-protos/src/history_builder.rs +2 -0
- package/sdk-core/sdk-core-protos/src/history_info.rs +1 -0
- package/sdk-core/sdk-core-protos/src/lib.rs +82 -73
- package/sdk-core/test-utils/Cargo.toml +1 -1
- package/sdk-core/test-utils/src/lib.rs +50 -37
- package/sdk-core/tests/integ_tests/metrics_tests.rs +143 -10
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +26 -15
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +2 -2
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +5 -1
- package/sdk-core/tests/integ_tests/workflow_tests.rs +1 -0
- package/src/conversions.rs +9 -2
- package/src/runtime.rs +5 -7
- package/ts/errors.ts +15 -0
- package/ts/index.ts +22 -4
|
@@ -10,33 +10,31 @@ pub(crate) use activities::{
|
|
|
10
10
|
ExecutingLAId, LocalActRequest, LocalActivityExecutionResult, LocalActivityResolution,
|
|
11
11
|
NewLocalAct,
|
|
12
12
|
};
|
|
13
|
+
pub(crate) use workflow::{wft_poller::new_wft_poller, LEGACY_QUERY_ID};
|
|
14
|
+
|
|
13
15
|
#[cfg(test)]
|
|
14
16
|
pub(crate) use workflow::ManagedWFFunc;
|
|
15
|
-
pub(crate) use workflow::{wft_poller::new_wft_poller, LEGACY_QUERY_ID};
|
|
16
17
|
|
|
17
18
|
use crate::{
|
|
19
|
+
abstractions::MeteredSemaphore,
|
|
18
20
|
errors::CompleteWfError,
|
|
19
|
-
pollers::{
|
|
20
|
-
|
|
21
|
-
WorkflowTaskPoller,
|
|
22
|
-
},
|
|
23
|
-
protosext::{validate_activity_completion, ValidPollWFTQResponse},
|
|
21
|
+
pollers::{new_activity_task_buffer, new_workflow_task_buffer, WorkflowTaskPoller},
|
|
22
|
+
protosext::validate_activity_completion,
|
|
24
23
|
telemetry::{
|
|
25
24
|
metrics::{
|
|
26
|
-
activity_poller, local_activity_worker_type, workflow_poller,
|
|
27
|
-
MetricsContext,
|
|
25
|
+
activity_poller, activity_worker_type, local_activity_worker_type, workflow_poller,
|
|
26
|
+
workflow_sticky_poller, workflow_worker_type, MetricsContext,
|
|
28
27
|
},
|
|
29
28
|
TelemetryInstance,
|
|
30
29
|
},
|
|
31
30
|
worker::{
|
|
32
|
-
activities::{
|
|
31
|
+
activities::{LACompleteAction, LocalActivityManager, NextPendingLAAction},
|
|
33
32
|
client::WorkerClient,
|
|
34
33
|
workflow::{LAReqSink, LocalResolution, WorkflowBasics, Workflows},
|
|
35
34
|
},
|
|
36
35
|
ActivityHeartbeat, CompleteActivityError, PollActivityError, PollWfError, WorkerTrait,
|
|
37
36
|
};
|
|
38
|
-
use activities::
|
|
39
|
-
use futures::Stream;
|
|
37
|
+
use activities::WorkerActivityTasks;
|
|
40
38
|
use std::{
|
|
41
39
|
convert::TryInto,
|
|
42
40
|
future,
|
|
@@ -56,13 +54,25 @@ use temporal_sdk_core_protos::{
|
|
|
56
54
|
temporal::api::{
|
|
57
55
|
enums::v1::TaskQueueKind,
|
|
58
56
|
taskqueue::v1::{StickyExecutionAttributes, TaskQueue},
|
|
59
|
-
workflowservice::v1::
|
|
57
|
+
workflowservice::v1::get_system_info_response,
|
|
60
58
|
},
|
|
61
59
|
TaskToken,
|
|
62
60
|
};
|
|
63
61
|
use tokio::sync::mpsc::unbounded_channel;
|
|
64
62
|
use tokio_util::sync::CancellationToken;
|
|
65
63
|
|
|
64
|
+
use crate::{abstractions::dbg_panic, pollers::BoxedActPoller};
|
|
65
|
+
#[cfg(test)]
|
|
66
|
+
use {
|
|
67
|
+
crate::{
|
|
68
|
+
pollers::{BoxedPoller, MockPermittedPollBuffer},
|
|
69
|
+
protosext::ValidPollWFTQResponse,
|
|
70
|
+
},
|
|
71
|
+
futures::stream::BoxStream,
|
|
72
|
+
futures_util::StreamExt,
|
|
73
|
+
temporal_sdk_core_protos::temporal::api::workflowservice::v1::PollActivityTaskQueueResponse,
|
|
74
|
+
};
|
|
75
|
+
|
|
66
76
|
/// A worker polls on a certain task queue
|
|
67
77
|
pub struct Worker {
|
|
68
78
|
config: WorkerConfig,
|
|
@@ -183,9 +193,7 @@ impl Worker {
|
|
|
183
193
|
client: Arc<dyn WorkerClient>,
|
|
184
194
|
telem_instance: Option<&TelemetryInstance>,
|
|
185
195
|
) -> Self {
|
|
186
|
-
info!(task_queue=%config.task_queue,
|
|
187
|
-
namespace=%config.namespace,
|
|
188
|
-
"Initializing worker");
|
|
196
|
+
info!(task_queue=%config.task_queue, namespace=%config.namespace, "Initializing worker");
|
|
189
197
|
let metrics = if let Some(ti) = telem_instance {
|
|
190
198
|
MetricsContext::top_level(config.namespace.clone(), ti)
|
|
191
199
|
.with_task_q(config.task_queue.clone())
|
|
@@ -194,68 +202,13 @@ impl Worker {
|
|
|
194
202
|
};
|
|
195
203
|
metrics.worker_registered();
|
|
196
204
|
|
|
197
|
-
let shutdown_token = CancellationToken::new();
|
|
198
|
-
let max_nonsticky_polls = if sticky_queue_name.is_some() {
|
|
199
|
-
config.max_nonsticky_polls()
|
|
200
|
-
} else {
|
|
201
|
-
config.max_concurrent_wft_polls
|
|
202
|
-
};
|
|
203
|
-
let max_sticky_polls = config.max_sticky_polls();
|
|
204
|
-
let wft_metrics = metrics.with_new_attrs([workflow_poller()]);
|
|
205
|
-
let mut wf_task_poll_buffer = new_workflow_task_buffer(
|
|
206
|
-
client.clone(),
|
|
207
|
-
config.task_queue.clone(),
|
|
208
|
-
false,
|
|
209
|
-
max_nonsticky_polls,
|
|
210
|
-
max_nonsticky_polls * 2,
|
|
211
|
-
shutdown_token.child_token(),
|
|
212
|
-
);
|
|
213
|
-
wf_task_poll_buffer.set_num_pollers_handler(move |np| wft_metrics.record_num_pollers(np));
|
|
214
|
-
let sticky_queue_poller = sticky_queue_name.as_ref().map(|sqn| {
|
|
215
|
-
let sticky_metrics = metrics.with_new_attrs([workflow_sticky_poller()]);
|
|
216
|
-
let mut sp = new_workflow_task_buffer(
|
|
217
|
-
client.clone(),
|
|
218
|
-
sqn.clone(),
|
|
219
|
-
true,
|
|
220
|
-
max_sticky_polls,
|
|
221
|
-
max_sticky_polls * 2,
|
|
222
|
-
shutdown_token.child_token(),
|
|
223
|
-
);
|
|
224
|
-
sp.set_num_pollers_handler(move |np| sticky_metrics.record_num_pollers(np));
|
|
225
|
-
sp
|
|
226
|
-
});
|
|
227
|
-
let act_poll_buffer = if config.no_remote_activities {
|
|
228
|
-
None
|
|
229
|
-
} else {
|
|
230
|
-
let mut ap = new_activity_task_buffer(
|
|
231
|
-
client.clone(),
|
|
232
|
-
config.task_queue.clone(),
|
|
233
|
-
config.max_concurrent_at_polls,
|
|
234
|
-
config.max_concurrent_at_polls * 2,
|
|
235
|
-
config.max_task_queue_activities_per_second,
|
|
236
|
-
shutdown_token.child_token(),
|
|
237
|
-
);
|
|
238
|
-
let act_metrics = metrics.with_new_attrs([activity_poller()]);
|
|
239
|
-
ap.set_num_pollers_handler(move |np| act_metrics.record_num_pollers(np));
|
|
240
|
-
Some(Box::from(ap)
|
|
241
|
-
as Box<
|
|
242
|
-
dyn Poller<PollActivityTaskQueueResponse> + Send + Sync,
|
|
243
|
-
>)
|
|
244
|
-
};
|
|
245
|
-
let wf_task_poll_buffer = Box::new(WorkflowTaskPoller::new(
|
|
246
|
-
wf_task_poll_buffer,
|
|
247
|
-
sticky_queue_poller,
|
|
248
|
-
));
|
|
249
|
-
let wft_stream = new_wft_poller(wf_task_poll_buffer, metrics.clone());
|
|
250
205
|
Self::new_with_pollers(
|
|
251
206
|
config,
|
|
252
207
|
sticky_queue_name,
|
|
253
208
|
client,
|
|
254
|
-
|
|
255
|
-
act_poll_buffer,
|
|
209
|
+
TaskPollers::Real,
|
|
256
210
|
metrics,
|
|
257
211
|
telem_instance,
|
|
258
|
-
shutdown_token,
|
|
259
212
|
)
|
|
260
213
|
}
|
|
261
214
|
|
|
@@ -269,12 +222,110 @@ impl Worker {
|
|
|
269
222
|
mut config: WorkerConfig,
|
|
270
223
|
sticky_queue_name: Option<String>,
|
|
271
224
|
client: Arc<dyn WorkerClient>,
|
|
272
|
-
|
|
273
|
-
act_poller: Option<BoxedActPoller>,
|
|
225
|
+
task_pollers: TaskPollers,
|
|
274
226
|
metrics: MetricsContext,
|
|
275
227
|
telem_instance: Option<&TelemetryInstance>,
|
|
276
|
-
shutdown_token: CancellationToken,
|
|
277
228
|
) -> Self {
|
|
229
|
+
let shutdown_token = CancellationToken::new();
|
|
230
|
+
let wft_semaphore = Arc::new(MeteredSemaphore::new(
|
|
231
|
+
config.max_outstanding_workflow_tasks,
|
|
232
|
+
metrics.with_new_attrs([workflow_worker_type()]),
|
|
233
|
+
MetricsContext::available_task_slots,
|
|
234
|
+
));
|
|
235
|
+
let act_semaphore = Arc::new(MeteredSemaphore::new(
|
|
236
|
+
config.max_outstanding_activities,
|
|
237
|
+
metrics.with_new_attrs([activity_worker_type()]),
|
|
238
|
+
MetricsContext::available_task_slots,
|
|
239
|
+
));
|
|
240
|
+
|
|
241
|
+
let (wft_stream, act_poller) = match task_pollers {
|
|
242
|
+
TaskPollers::Real => {
|
|
243
|
+
let max_nonsticky_polls = if sticky_queue_name.is_some() {
|
|
244
|
+
config.max_nonsticky_polls()
|
|
245
|
+
} else {
|
|
246
|
+
config.max_concurrent_wft_polls
|
|
247
|
+
};
|
|
248
|
+
let max_sticky_polls = config.max_sticky_polls();
|
|
249
|
+
let wft_metrics = metrics.with_new_attrs([workflow_poller()]);
|
|
250
|
+
let wf_task_poll_buffer = new_workflow_task_buffer(
|
|
251
|
+
client.clone(),
|
|
252
|
+
TaskQueue {
|
|
253
|
+
name: config.task_queue.clone(),
|
|
254
|
+
kind: TaskQueueKind::Normal as i32,
|
|
255
|
+
normal_name: "".to_string(),
|
|
256
|
+
},
|
|
257
|
+
max_nonsticky_polls,
|
|
258
|
+
wft_semaphore.clone(),
|
|
259
|
+
shutdown_token.child_token(),
|
|
260
|
+
Some(move |np| {
|
|
261
|
+
wft_metrics.record_num_pollers(np);
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
264
|
+
let sticky_queue_poller = sticky_queue_name.as_ref().map(|sqn| {
|
|
265
|
+
let sticky_metrics = metrics.with_new_attrs([workflow_sticky_poller()]);
|
|
266
|
+
new_workflow_task_buffer(
|
|
267
|
+
client.clone(),
|
|
268
|
+
TaskQueue {
|
|
269
|
+
name: sqn.clone(),
|
|
270
|
+
kind: TaskQueueKind::Sticky as i32,
|
|
271
|
+
normal_name: config.task_queue.clone(),
|
|
272
|
+
},
|
|
273
|
+
max_sticky_polls,
|
|
274
|
+
wft_semaphore.clone(),
|
|
275
|
+
shutdown_token.child_token(),
|
|
276
|
+
Some(move |np| {
|
|
277
|
+
sticky_metrics.record_num_pollers(np);
|
|
278
|
+
}),
|
|
279
|
+
)
|
|
280
|
+
});
|
|
281
|
+
let act_poll_buffer = if config.no_remote_activities {
|
|
282
|
+
None
|
|
283
|
+
} else {
|
|
284
|
+
let act_metrics = metrics.with_new_attrs([activity_poller()]);
|
|
285
|
+
let ap = new_activity_task_buffer(
|
|
286
|
+
client.clone(),
|
|
287
|
+
config.task_queue.clone(),
|
|
288
|
+
config.max_concurrent_at_polls,
|
|
289
|
+
act_semaphore.clone(),
|
|
290
|
+
config.max_task_queue_activities_per_second,
|
|
291
|
+
shutdown_token.child_token(),
|
|
292
|
+
Some(move |np| act_metrics.record_num_pollers(np)),
|
|
293
|
+
config.max_worker_activities_per_second,
|
|
294
|
+
);
|
|
295
|
+
Some(Box::from(ap) as BoxedActPoller)
|
|
296
|
+
};
|
|
297
|
+
let wf_task_poll_buffer = Box::new(WorkflowTaskPoller::new(
|
|
298
|
+
wf_task_poll_buffer,
|
|
299
|
+
sticky_queue_poller,
|
|
300
|
+
));
|
|
301
|
+
let wft_stream = new_wft_poller(wf_task_poll_buffer, metrics.clone());
|
|
302
|
+
#[cfg(test)]
|
|
303
|
+
let wft_stream = wft_stream.left_stream();
|
|
304
|
+
(wft_stream, act_poll_buffer)
|
|
305
|
+
}
|
|
306
|
+
#[cfg(test)]
|
|
307
|
+
TaskPollers::Mocked {
|
|
308
|
+
wft_stream,
|
|
309
|
+
act_poller,
|
|
310
|
+
} => {
|
|
311
|
+
let ap =
|
|
312
|
+
act_poller.map(|ap| MockPermittedPollBuffer::new(act_semaphore.clone(), ap));
|
|
313
|
+
let wft_semaphore = wft_semaphore.clone();
|
|
314
|
+
let wfs = wft_stream.then(move |s| {
|
|
315
|
+
let wft_semaphore = wft_semaphore.clone();
|
|
316
|
+
async move {
|
|
317
|
+
let permit = wft_semaphore
|
|
318
|
+
.acquire_owned()
|
|
319
|
+
.await
|
|
320
|
+
.expect("Mock WFT stream should not see closed semaphore");
|
|
321
|
+
s.map(|s| (s, permit))
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
let wfs = wfs.right_stream();
|
|
325
|
+
(wfs, ap.map(|ap| Box::new(ap) as BoxedActPoller))
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
278
329
|
let (hb_tx, hb_rx) = unbounded_channel();
|
|
279
330
|
let local_act_mgr = Arc::new(LocalActivityManager::new(
|
|
280
331
|
config.max_outstanding_local_activities,
|
|
@@ -284,8 +335,7 @@ impl Worker {
|
|
|
284
335
|
));
|
|
285
336
|
let at_task_mgr = act_poller.map(|ap| {
|
|
286
337
|
WorkerActivityTasks::new(
|
|
287
|
-
|
|
288
|
-
config.max_worker_activities_per_second,
|
|
338
|
+
act_semaphore,
|
|
289
339
|
ap,
|
|
290
340
|
client.clone(),
|
|
291
341
|
metrics.clone(),
|
|
@@ -312,6 +362,7 @@ impl Worker {
|
|
|
312
362
|
worker_task_queue: Some(TaskQueue {
|
|
313
363
|
name: sq,
|
|
314
364
|
kind: TaskQueueKind::Sticky as i32,
|
|
365
|
+
normal_name: config.task_queue.clone(),
|
|
315
366
|
}),
|
|
316
367
|
schedule_to_start_timeout: Some(
|
|
317
368
|
config
|
|
@@ -321,6 +372,7 @@ impl Worker {
|
|
|
321
372
|
),
|
|
322
373
|
}),
|
|
323
374
|
client,
|
|
375
|
+
wft_semaphore,
|
|
324
376
|
wft_stream,
|
|
325
377
|
la_sink,
|
|
326
378
|
local_act_mgr.clone(),
|
|
@@ -335,7 +387,7 @@ impl Worker {
|
|
|
335
387
|
config,
|
|
336
388
|
shutdown_token,
|
|
337
389
|
post_activate_hook: None,
|
|
338
|
-
//
|
|
390
|
+
// Non-local activities are already complete if configured not to poll for them.
|
|
339
391
|
non_local_activities_complete: Arc::new(AtomicBool::new(!poll_on_non_local_activities)),
|
|
340
392
|
local_activities_complete: Default::default(),
|
|
341
393
|
}
|
|
@@ -393,9 +445,13 @@ impl Worker {
|
|
|
393
445
|
}
|
|
394
446
|
|
|
395
447
|
#[allow(unused)]
|
|
396
|
-
pub(crate)
|
|
448
|
+
pub(crate) fn available_wft_permits(&self) -> usize {
|
|
397
449
|
self.workflows.available_wft_permits()
|
|
398
450
|
}
|
|
451
|
+
#[cfg(test)]
|
|
452
|
+
pub(crate) fn unused_wft_permits(&self) -> usize {
|
|
453
|
+
self.workflows.unused_wft_permits()
|
|
454
|
+
}
|
|
399
455
|
|
|
400
456
|
/// Get new activity tasks (may be local or nonlocal). Local activities are returned first
|
|
401
457
|
/// before polling the server if there are any.
|
|
@@ -437,14 +493,9 @@ impl Worker {
|
|
|
437
493
|
unreachable!()
|
|
438
494
|
}
|
|
439
495
|
match self.local_act_mgr.next_pending().await {
|
|
440
|
-
Some(
|
|
441
|
-
Some(
|
|
442
|
-
|
|
443
|
-
resolution,
|
|
444
|
-
task,
|
|
445
|
-
}) => {
|
|
446
|
-
self.notify_local_result(&run_id, LocalResolution::LocalActivity(resolution));
|
|
447
|
-
Ok(task)
|
|
496
|
+
Some(NextPendingLAAction::Dispatch(r)) => Ok(Some(r)),
|
|
497
|
+
Some(NextPendingLAAction::Autocomplete(action)) => {
|
|
498
|
+
Ok(self.handle_la_complete_action(action))
|
|
448
499
|
}
|
|
449
500
|
None => {
|
|
450
501
|
if self.shutdown_token.is_cancelled() {
|
|
@@ -485,23 +536,7 @@ impl Worker {
|
|
|
485
536
|
validate_activity_completion(&status)?;
|
|
486
537
|
if task_token.is_local_activity_task() {
|
|
487
538
|
let as_la_res: LocalActivityExecutionResult = status.try_into()?;
|
|
488
|
-
|
|
489
|
-
LACompleteAction::Report(info) => self.complete_local_act(as_la_res, info, None),
|
|
490
|
-
LACompleteAction::LangDoesTimerBackoff(backoff, info) => {
|
|
491
|
-
// This la needs to write a failure marker, and then we will tell lang how
|
|
492
|
-
// long of a timer to schedule to back off for. We do this because there are
|
|
493
|
-
// no other situations where core generates "internal" commands so it is much
|
|
494
|
-
// simpler for lang to reply with the timer / next LA command than to do it
|
|
495
|
-
// internally. Plus, this backoff hack we'd like to eliminate eventually.
|
|
496
|
-
self.complete_local_act(as_la_res, info, Some(backoff));
|
|
497
|
-
}
|
|
498
|
-
LACompleteAction::WillBeRetried => {
|
|
499
|
-
// Nothing to do here
|
|
500
|
-
}
|
|
501
|
-
LACompleteAction::Untracked => {
|
|
502
|
-
warn!("Tried to complete untracked local activity {}", task_token);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
539
|
+
self.complete_local_act(task_token, as_la_res);
|
|
505
540
|
return Ok(());
|
|
506
541
|
}
|
|
507
542
|
|
|
@@ -567,23 +602,28 @@ impl Worker {
|
|
|
567
602
|
self.post_activate_hook = Some(Box::new(callback))
|
|
568
603
|
}
|
|
569
604
|
|
|
570
|
-
fn complete_local_act(
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
605
|
+
fn complete_local_act(&self, task_token: TaskToken, la_res: LocalActivityExecutionResult) {
|
|
606
|
+
if self
|
|
607
|
+
.handle_la_complete_action(self.local_act_mgr.complete(&task_token, la_res))
|
|
608
|
+
.is_some()
|
|
609
|
+
{
|
|
610
|
+
dbg_panic!("Should never be a task from direct completion");
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
fn handle_la_complete_action(&self, action: LACompleteAction) -> Option<ActivityTask> {
|
|
615
|
+
match action {
|
|
616
|
+
LACompleteAction::Report {
|
|
617
|
+
run_id,
|
|
618
|
+
resolution,
|
|
619
|
+
task,
|
|
620
|
+
} => {
|
|
621
|
+
self.notify_local_result(&run_id, LocalResolution::LocalActivity(resolution));
|
|
622
|
+
task
|
|
623
|
+
}
|
|
624
|
+
LACompleteAction::WillBeRetried(task) => task,
|
|
625
|
+
LACompleteAction::Untracked => None,
|
|
626
|
+
}
|
|
587
627
|
}
|
|
588
628
|
|
|
589
629
|
fn notify_local_result(&self, run_id: &str, res: LocalResolution) {
|
|
@@ -605,7 +645,6 @@ fn build_wf_basics(
|
|
|
605
645
|
) -> WorkflowBasics {
|
|
606
646
|
WorkflowBasics {
|
|
607
647
|
max_cached_workflows: config.max_cached_workflows,
|
|
608
|
-
max_outstanding_wfts: config.max_outstanding_workflow_tasks,
|
|
609
648
|
shutdown_token,
|
|
610
649
|
metrics,
|
|
611
650
|
namespace: config.namespace.clone(),
|
|
@@ -618,6 +657,15 @@ fn build_wf_basics(
|
|
|
618
657
|
}
|
|
619
658
|
}
|
|
620
659
|
|
|
660
|
+
pub(crate) enum TaskPollers {
|
|
661
|
+
Real,
|
|
662
|
+
#[cfg(test)]
|
|
663
|
+
Mocked {
|
|
664
|
+
wft_stream: BoxStream<'static, Result<ValidPollWFTQResponse, tonic::Status>>,
|
|
665
|
+
act_poller: Option<BoxedPoller<PollActivityTaskQueueResponse>>,
|
|
666
|
+
},
|
|
667
|
+
}
|
|
668
|
+
|
|
621
669
|
#[cfg(test)]
|
|
622
670
|
mod tests {
|
|
623
671
|
use super::*;
|
|
@@ -648,7 +696,7 @@ mod tests {
|
|
|
648
696
|
.as_ref()
|
|
649
697
|
.unwrap()
|
|
650
698
|
.remaining_activity_capacity(),
|
|
651
|
-
|
|
699
|
+
5
|
|
652
700
|
);
|
|
653
701
|
}
|
|
654
702
|
|
|
@@ -40,10 +40,6 @@ impl DrivenWorkflow {
|
|
|
40
40
|
debug!(run_id = %attribs.original_execution_run_id, "Driven WF start");
|
|
41
41
|
let started_info = WorkflowStartedInfo {
|
|
42
42
|
workflow_task_timeout: attribs.workflow_task_timeout.clone().try_into_or_none(),
|
|
43
|
-
workflow_execution_timeout: attribs
|
|
44
|
-
.workflow_execution_timeout
|
|
45
|
-
.clone()
|
|
46
|
-
.try_into_or_none(),
|
|
47
43
|
memo: attribs.memo.clone(),
|
|
48
44
|
search_attrs: attribs.search_attributes.clone(),
|
|
49
45
|
retry_policy: attribs.retry_policy.clone(),
|
|
@@ -17,7 +17,10 @@ use temporal_sdk_core_protos::{
|
|
|
17
17
|
workflow_commands::{ActivityCancellationType, ScheduleActivity},
|
|
18
18
|
},
|
|
19
19
|
temporal::api::{
|
|
20
|
-
command::v1::{
|
|
20
|
+
command::v1::{
|
|
21
|
+
command, schedule_activity_cmd_to_api, Command,
|
|
22
|
+
RequestCancelActivityTaskCommandAttributes,
|
|
23
|
+
},
|
|
21
24
|
common::v1::{ActivityType, Payload, Payloads},
|
|
22
25
|
enums::v1::{CommandType, EventType, RetryState},
|
|
23
26
|
failure::v1::{failure::FailureInfo, ActivityFailureInfo, CanceledFailureInfo, Failure},
|
|
@@ -107,6 +110,7 @@ impl ActivityMachine {
|
|
|
107
110
|
pub(super) fn new_scheduled(
|
|
108
111
|
attrs: ScheduleActivity,
|
|
109
112
|
internal_flags: InternalFlagsRef,
|
|
113
|
+
use_compatible_version: bool,
|
|
110
114
|
) -> NewMachineWithCommand {
|
|
111
115
|
let mut s = Self::from_parts(
|
|
112
116
|
Created {}.into(),
|
|
@@ -124,7 +128,10 @@ impl ActivityMachine {
|
|
|
124
128
|
.expect("Scheduling activities doesn't fail");
|
|
125
129
|
let command = Command {
|
|
126
130
|
command_type: CommandType::ScheduleActivityTask as i32,
|
|
127
|
-
attributes: Some(
|
|
131
|
+
attributes: Some(schedule_activity_cmd_to_api(
|
|
132
|
+
s.shared_state().attrs.clone(),
|
|
133
|
+
use_compatible_version,
|
|
134
|
+
)),
|
|
128
135
|
};
|
|
129
136
|
NewMachineWithCommand {
|
|
130
137
|
command,
|
|
@@ -22,7 +22,10 @@ use temporal_sdk_core_protos::{
|
|
|
22
22
|
workflow_commands::StartChildWorkflowExecution,
|
|
23
23
|
},
|
|
24
24
|
temporal::api::{
|
|
25
|
-
command::v1::{
|
|
25
|
+
command::v1::{
|
|
26
|
+
start_child_workflow_cmd_to_api, Command,
|
|
27
|
+
RequestCancelExternalWorkflowExecutionCommandAttributes,
|
|
28
|
+
},
|
|
26
29
|
common::v1::{Payload, Payloads, WorkflowExecution, WorkflowType},
|
|
27
30
|
enums::v1::{
|
|
28
31
|
CommandType, EventType, RetryState, StartChildWorkflowExecutionFailedCause, TimeoutType,
|
|
@@ -359,6 +362,7 @@ impl ChildWorkflowMachine {
|
|
|
359
362
|
pub(super) fn new_scheduled(
|
|
360
363
|
attribs: StartChildWorkflowExecution,
|
|
361
364
|
internal_flags: InternalFlagsRef,
|
|
365
|
+
use_compatible_version: bool,
|
|
362
366
|
) -> NewMachineWithCommand {
|
|
363
367
|
let mut s = Self::from_parts(
|
|
364
368
|
Created {}.into(),
|
|
@@ -379,7 +383,10 @@ impl ChildWorkflowMachine {
|
|
|
379
383
|
.expect("Scheduling child workflows doesn't fail");
|
|
380
384
|
let cmd = Command {
|
|
381
385
|
command_type: CommandType::StartChildWorkflowExecution as i32,
|
|
382
|
-
attributes: Some(
|
|
386
|
+
attributes: Some(start_child_workflow_cmd_to_api(
|
|
387
|
+
attribs,
|
|
388
|
+
use_compatible_version,
|
|
389
|
+
)),
|
|
383
390
|
};
|
|
384
391
|
NewMachineWithCommand {
|
|
385
392
|
command: cmd,
|
package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs
CHANGED
|
@@ -8,7 +8,7 @@ use std::convert::TryFrom;
|
|
|
8
8
|
use temporal_sdk_core_protos::{
|
|
9
9
|
coresdk::workflow_commands::ContinueAsNewWorkflowExecution,
|
|
10
10
|
temporal::api::{
|
|
11
|
-
command::v1::Command,
|
|
11
|
+
command::v1::{continue_as_new_cmd_to_api, Command},
|
|
12
12
|
enums::v1::{CommandType, EventType},
|
|
13
13
|
},
|
|
14
14
|
};
|
|
@@ -30,13 +30,16 @@ fsm! {
|
|
|
30
30
|
#[derive(Debug, derive_more::Display)]
|
|
31
31
|
pub(super) enum ContinueAsNewWorkflowCommand {}
|
|
32
32
|
|
|
33
|
-
pub(super) fn continue_as_new(
|
|
33
|
+
pub(super) fn continue_as_new(
|
|
34
|
+
attribs: ContinueAsNewWorkflowExecution,
|
|
35
|
+
use_compatible_version: bool,
|
|
36
|
+
) -> NewMachineWithCommand {
|
|
34
37
|
let mut machine = ContinueAsNewWorkflowMachine::from_parts(Created {}.into(), ());
|
|
35
38
|
OnEventWrapper::on_event_mut(&mut machine, ContinueAsNewWorkflowMachineEvents::Schedule)
|
|
36
39
|
.expect("Scheduling continue as new machine doesn't fail");
|
|
37
40
|
let command = Command {
|
|
38
41
|
command_type: CommandType::ContinueAsNewWorkflowExecution as i32,
|
|
39
|
-
attributes: Some(attribs
|
|
42
|
+
attributes: Some(continue_as_new_cmd_to_api(attribs, use_compatible_version)),
|
|
40
43
|
};
|
|
41
44
|
NewMachineWithCommand {
|
|
42
45
|
command,
|