@temporalio/core-bridge 0.19.2 → 0.20.2
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 +90 -157
- package/Cargo.toml +1 -0
- package/index.d.ts +11 -27
- 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/.buildkite/docker/Dockerfile +1 -1
- package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
- package/sdk-core/.cargo/config.toml +1 -0
- package/sdk-core/CODEOWNERS +1 -1
- package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +119 -86
- package/sdk-core/bridge-ffi/src/lib.rs +311 -315
- package/sdk-core/bridge-ffi/src/wrappers.rs +108 -113
- package/sdk-core/client/Cargo.toml +13 -9
- package/sdk-core/client/LICENSE.txt +23 -0
- package/sdk-core/client/src/lib.rs +286 -174
- package/sdk-core/client/src/metrics.rs +86 -12
- package/sdk-core/client/src/raw.rs +566 -0
- package/sdk-core/client/src/retry.rs +137 -99
- package/sdk-core/core/Cargo.toml +15 -10
- package/sdk-core/core/LICENSE.txt +23 -0
- package/sdk-core/core/benches/workflow_replay.rs +79 -0
- package/sdk-core/core/src/abstractions.rs +38 -0
- package/sdk-core/core/src/core_tests/activity_tasks.rs +108 -182
- package/sdk-core/core/src/core_tests/child_workflows.rs +16 -11
- package/sdk-core/core/src/core_tests/determinism.rs +24 -12
- package/sdk-core/core/src/core_tests/local_activities.rs +53 -27
- package/sdk-core/core/src/core_tests/mod.rs +30 -43
- package/sdk-core/core/src/core_tests/queries.rs +82 -81
- package/sdk-core/core/src/core_tests/workers.rs +111 -296
- package/sdk-core/core/src/core_tests/workflow_cancels.rs +4 -4
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +257 -242
- package/sdk-core/core/src/lib.rs +73 -318
- package/sdk-core/core/src/pollers/mod.rs +4 -6
- package/sdk-core/core/src/pollers/poll_buffer.rs +20 -14
- package/sdk-core/core/src/protosext/mod.rs +7 -10
- package/sdk-core/core/src/replay/mod.rs +11 -150
- package/sdk-core/core/src/telemetry/metrics.rs +35 -2
- package/sdk-core/core/src/telemetry/mod.rs +49 -16
- package/sdk-core/core/src/telemetry/prometheus_server.rs +14 -35
- package/sdk-core/core/src/test_help/mod.rs +104 -170
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +57 -34
- package/sdk-core/core/src/worker/activities/local_activities.rs +95 -23
- package/sdk-core/core/src/worker/activities.rs +23 -16
- package/sdk-core/core/src/worker/client/mocks.rs +86 -0
- package/sdk-core/core/src/worker/client.rs +209 -0
- package/sdk-core/core/src/worker/mod.rs +207 -108
- package/sdk-core/core/src/workflow/driven_workflow.rs +21 -6
- package/sdk-core/core/src/workflow/history_update.rs +107 -24
- package/sdk-core/core/src/workflow/machines/activity_state_machine.rs +2 -3
- package/sdk-core/core/src/workflow/machines/child_workflow_state_machine.rs +2 -3
- package/sdk-core/core/src/workflow/machines/mod.rs +20 -17
- package/sdk-core/core/src/workflow/machines/signal_external_state_machine.rs +56 -19
- package/sdk-core/core/src/workflow/machines/transition_coverage.rs +5 -0
- package/sdk-core/core/src/workflow/machines/upsert_search_attributes_state_machine.rs +230 -22
- package/sdk-core/core/src/workflow/machines/workflow_machines.rs +81 -115
- package/sdk-core/core/src/workflow/machines/workflow_task_state_machine.rs +4 -4
- package/sdk-core/core/src/workflow/mod.rs +13 -1
- package/sdk-core/core/src/workflow/workflow_tasks/concurrency_manager.rs +70 -11
- package/sdk-core/core/src/workflow/workflow_tasks/mod.rs +65 -41
- package/sdk-core/core-api/Cargo.toml +9 -1
- package/sdk-core/core-api/LICENSE.txt +23 -0
- package/sdk-core/core-api/src/errors.rs +7 -38
- package/sdk-core/core-api/src/lib.rs +44 -52
- package/sdk-core/core-api/src/worker.rs +10 -2
- package/sdk-core/etc/deps.svg +127 -96
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +11 -7
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +10 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +6 -1
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +6 -0
- package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +6 -0
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +2 -1
- package/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +12 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +25 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +4 -0
- package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +19 -35
- package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +2 -6
- package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +53 -11
- package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +14 -7
- package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +3 -5
- package/sdk-core/sdk/Cargo.toml +16 -2
- package/sdk-core/sdk/LICENSE.txt +23 -0
- package/sdk-core/sdk/src/interceptors.rs +11 -0
- package/sdk-core/sdk/src/lib.rs +139 -151
- package/sdk-core/sdk/src/workflow_context/options.rs +86 -1
- package/sdk-core/sdk/src/workflow_context.rs +36 -17
- package/sdk-core/sdk/src/workflow_future.rs +19 -25
- package/sdk-core/sdk-core-protos/Cargo.toml +1 -1
- package/sdk-core/sdk-core-protos/build.rs +1 -0
- package/sdk-core/sdk-core-protos/src/history_info.rs +17 -4
- package/sdk-core/sdk-core-protos/src/lib.rs +251 -47
- package/sdk-core/test-utils/Cargo.toml +3 -1
- package/sdk-core/test-utils/src/canned_histories.rs +27 -0
- package/sdk-core/test-utils/src/histfetch.rs +3 -3
- package/sdk-core/test-utils/src/lib.rs +223 -68
- package/sdk-core/tests/integ_tests/client_tests.rs +27 -4
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +93 -14
- package/sdk-core/tests/integ_tests/polling_tests.rs +18 -12
- package/sdk-core/tests/integ_tests/queries_tests.rs +50 -53
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +117 -103
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +8 -1
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +10 -5
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +7 -1
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +32 -9
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +7 -1
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +76 -15
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +19 -3
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +39 -42
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +84 -0
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +30 -8
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +21 -6
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +26 -16
- package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +66 -0
- package/sdk-core/tests/integ_tests/workflow_tests.rs +78 -74
- package/sdk-core/tests/load_tests.rs +9 -6
- package/sdk-core/tests/main.rs +43 -10
- package/src/conversions.rs +7 -12
- package/src/lib.rs +322 -357
- package/sdk-core/client/src/mocks.rs +0 -167
- package/sdk-core/core/src/worker/dispatcher.rs +0 -171
- package/sdk-core/protos/local/temporal/sdk/core/bridge/service.proto +0 -61
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
//! Helpers for mocking
|
|
2
|
-
|
|
3
|
-
use super::*;
|
|
4
|
-
use crate::{MockServerGatewayApis, ServerGatewayOptions, ServerGatewayOptionsBuilder};
|
|
5
|
-
use std::str::FromStr;
|
|
6
|
-
use url::Url;
|
|
7
|
-
|
|
8
|
-
/// Create a mock client primed with basic necessary expectations
|
|
9
|
-
pub fn mock_gateway() -> MockServerGatewayApis {
|
|
10
|
-
let mut mg = MockServerGatewayApis::new();
|
|
11
|
-
mg.expect_get_options().return_const(fake_sg_opts());
|
|
12
|
-
mg
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/// Create a mock manual client primed with basic necessary expectations
|
|
16
|
-
pub fn mock_manual_gateway() -> MockManualGateway {
|
|
17
|
-
let mut mg = MockManualGateway::new();
|
|
18
|
-
mg.expect_get_options().return_const(fake_sg_opts());
|
|
19
|
-
mg
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// Returns some totally fake client options for use with mock clients
|
|
23
|
-
pub fn fake_sg_opts() -> ServerGatewayOptions {
|
|
24
|
-
ServerGatewayOptionsBuilder::default()
|
|
25
|
-
.target_url(Url::from_str("https://fake").unwrap())
|
|
26
|
-
.namespace("test_namespace".to_string())
|
|
27
|
-
.client_name("fake_client".to_string())
|
|
28
|
-
.client_version("fake_version".to_string())
|
|
29
|
-
.worker_binary_id("fake_binid".to_string())
|
|
30
|
-
.build()
|
|
31
|
-
.unwrap()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Need a version of the mock that can return futures so we can return potentially pending
|
|
35
|
-
// results. This is really annoying b/c of the async trait stuff. Need
|
|
36
|
-
// https://github.com/asomers/mockall/issues/189 to be fixed for it to go away.
|
|
37
|
-
mockall::mock! {
|
|
38
|
-
pub ManualGateway {}
|
|
39
|
-
impl ServerGatewayApis for ManualGateway {
|
|
40
|
-
fn start_workflow<'a, 'b>(
|
|
41
|
-
&self,
|
|
42
|
-
input: Vec<Payload>,
|
|
43
|
-
task_queue: String,
|
|
44
|
-
workflow_id: String,
|
|
45
|
-
workflow_type: String,
|
|
46
|
-
task_timeout: Option<Duration>,
|
|
47
|
-
) -> impl Future<Output = Result<StartWorkflowExecutionResponse>> + Send + 'b
|
|
48
|
-
where 'a: 'b, Self: 'b;
|
|
49
|
-
|
|
50
|
-
fn poll_workflow_task<'a, 'b>(&'a self, task_queue: String, is_sticky: bool)
|
|
51
|
-
-> impl Future<Output = Result<PollWorkflowTaskQueueResponse>> + Send + 'b
|
|
52
|
-
where 'a: 'b, Self: 'b;
|
|
53
|
-
|
|
54
|
-
fn poll_activity_task<'a, 'b>(&self, task_queue: String)
|
|
55
|
-
-> impl Future<Output = Result<PollActivityTaskQueueResponse>> + Send + 'b
|
|
56
|
-
where 'a: 'b, Self: 'b;
|
|
57
|
-
|
|
58
|
-
fn reset_sticky_task_queue<'a, 'b>(
|
|
59
|
-
&self,
|
|
60
|
-
workflow_id: String,
|
|
61
|
-
run_id: String,
|
|
62
|
-
) -> impl Future<Output = Result<ResetStickyTaskQueueResponse>> + Send + 'b
|
|
63
|
-
where 'a: 'b, Self: 'b;
|
|
64
|
-
|
|
65
|
-
fn complete_workflow_task<'a, 'b>(
|
|
66
|
-
&self,
|
|
67
|
-
request: WorkflowTaskCompletion,
|
|
68
|
-
) -> impl Future<Output = Result<RespondWorkflowTaskCompletedResponse>> + Send + 'b
|
|
69
|
-
where 'a: 'b, Self: 'b;
|
|
70
|
-
|
|
71
|
-
fn complete_activity_task<'a, 'b>(
|
|
72
|
-
&self,
|
|
73
|
-
task_token: TaskToken,
|
|
74
|
-
result: Option<Payloads>,
|
|
75
|
-
) -> impl Future<Output = Result<RespondActivityTaskCompletedResponse>> + Send + 'b
|
|
76
|
-
where 'a: 'b, Self: 'b;
|
|
77
|
-
|
|
78
|
-
fn cancel_activity_task<'a, 'b>(
|
|
79
|
-
&self,
|
|
80
|
-
task_token: TaskToken,
|
|
81
|
-
details: Option<Payloads>,
|
|
82
|
-
) -> impl Future<Output = Result<RespondActivityTaskCanceledResponse>> + Send + 'b
|
|
83
|
-
where 'a: 'b, Self: 'b;
|
|
84
|
-
|
|
85
|
-
fn fail_activity_task<'a, 'b>(
|
|
86
|
-
&self,
|
|
87
|
-
task_token: TaskToken,
|
|
88
|
-
failure: Option<Failure>,
|
|
89
|
-
) -> impl Future<Output = Result<RespondActivityTaskFailedResponse>> + Send + 'b
|
|
90
|
-
where 'a: 'b, Self: 'b;
|
|
91
|
-
|
|
92
|
-
fn fail_workflow_task<'a, 'b>(
|
|
93
|
-
&self,
|
|
94
|
-
task_token: TaskToken,
|
|
95
|
-
cause: WorkflowTaskFailedCause,
|
|
96
|
-
failure: Option<Failure>,
|
|
97
|
-
) -> impl Future<Output = Result<RespondWorkflowTaskFailedResponse>> + Send + 'b
|
|
98
|
-
where 'a: 'b, Self: 'b;
|
|
99
|
-
|
|
100
|
-
fn signal_workflow_execution<'a, 'b>(
|
|
101
|
-
&self,
|
|
102
|
-
workflow_id: String,
|
|
103
|
-
run_id: String,
|
|
104
|
-
signal_name: String,
|
|
105
|
-
payloads: Option<Payloads>,
|
|
106
|
-
) -> impl Future<Output = Result<SignalWorkflowExecutionResponse>> + Send + 'b
|
|
107
|
-
where 'a: 'b, Self: 'b;
|
|
108
|
-
|
|
109
|
-
fn record_activity_heartbeat<'a, 'b>(
|
|
110
|
-
&self,
|
|
111
|
-
task_token: TaskToken,
|
|
112
|
-
details: Option<Payloads>,
|
|
113
|
-
) -> impl Future<Output = Result<RecordActivityTaskHeartbeatResponse>> + Send + 'b
|
|
114
|
-
where 'a: 'b, Self: 'b;
|
|
115
|
-
|
|
116
|
-
fn query_workflow_execution<'a, 'b>(
|
|
117
|
-
&self,
|
|
118
|
-
workflow_id: String,
|
|
119
|
-
run_id: String,
|
|
120
|
-
query: WorkflowQuery,
|
|
121
|
-
) -> impl Future<Output = Result<QueryWorkflowResponse>> + Send + 'b
|
|
122
|
-
where 'a: 'b, Self: 'b;
|
|
123
|
-
|
|
124
|
-
fn describe_workflow_execution<'a, 'b>(
|
|
125
|
-
&self,
|
|
126
|
-
workflow_id: String,
|
|
127
|
-
run_id: Option<String>,
|
|
128
|
-
) -> impl Future<Output = Result<DescribeWorkflowExecutionResponse>> + Send + 'b
|
|
129
|
-
where 'a: 'b, Self: 'b;
|
|
130
|
-
|
|
131
|
-
fn get_workflow_execution_history<'a, 'b>(
|
|
132
|
-
&self,
|
|
133
|
-
workflow_id: String,
|
|
134
|
-
run_id: Option<String>,
|
|
135
|
-
page_token: Vec<u8>
|
|
136
|
-
) -> impl Future<Output = Result<GetWorkflowExecutionHistoryResponse>> + Send + 'b
|
|
137
|
-
where 'a: 'b, Self: 'b;
|
|
138
|
-
|
|
139
|
-
fn respond_legacy_query<'a, 'b>(
|
|
140
|
-
&self,
|
|
141
|
-
task_token: TaskToken,
|
|
142
|
-
query_result: QueryResult,
|
|
143
|
-
) -> impl Future<Output = Result<RespondQueryTaskCompletedResponse>> + Send + 'b
|
|
144
|
-
where 'a: 'b, Self: 'b;
|
|
145
|
-
|
|
146
|
-
fn cancel_workflow_execution<'a, 'b>(
|
|
147
|
-
&self,
|
|
148
|
-
workflow_id: String,
|
|
149
|
-
run_id: Option<String>,
|
|
150
|
-
) -> impl Future<Output = Result<RequestCancelWorkflowExecutionResponse>> + Send + 'b
|
|
151
|
-
where 'a: 'b, Self: 'b;
|
|
152
|
-
|
|
153
|
-
fn terminate_workflow_execution<'a, 'b>(
|
|
154
|
-
&self,
|
|
155
|
-
workflow_id: String,
|
|
156
|
-
run_id: Option<String>,
|
|
157
|
-
) -> impl Future<Output = Result<TerminateWorkflowExecutionResponse>> + Send + 'b
|
|
158
|
-
where 'a: 'b, Self: 'b;
|
|
159
|
-
|
|
160
|
-
fn list_namespaces<'a, 'b>(
|
|
161
|
-
&self,
|
|
162
|
-
) -> impl Future<Output = Result<ListNamespacesResponse>> + Send + 'b
|
|
163
|
-
where 'a: 'b, Self: 'b;
|
|
164
|
-
|
|
165
|
-
fn get_options(&self) -> &ServerGatewayOptions;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
telemetry::metrics::{task_queue, MetricsContext},
|
|
3
|
-
worker::Worker,
|
|
4
|
-
WorkerConfig, WorkerLookupErr, WorkerRegistrationError,
|
|
5
|
-
};
|
|
6
|
-
use arc_swap::ArcSwap;
|
|
7
|
-
use futures::future::join_all;
|
|
8
|
-
use std::{collections::HashMap, ops::Deref, option::Option, sync::Arc};
|
|
9
|
-
use temporal_client::ServerGatewayApis;
|
|
10
|
-
use tokio::sync::Notify;
|
|
11
|
-
|
|
12
|
-
/// Allows access to workers by task queue name
|
|
13
|
-
#[derive(Default)]
|
|
14
|
-
pub(crate) struct WorkerDispatcher {
|
|
15
|
-
/// Maps task queue names to workers. If the value is `None` then the worker existed at one
|
|
16
|
-
/// point and was shut down.
|
|
17
|
-
workers: ArcSwap<HashMap<String, Option<WorkerRefCt>>>,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
impl WorkerDispatcher {
|
|
21
|
-
pub fn new_worker(
|
|
22
|
-
&self,
|
|
23
|
-
config: WorkerConfig,
|
|
24
|
-
sticky_queue: Option<String>,
|
|
25
|
-
gateway: Arc<dyn ServerGatewayApis + Send + Sync>,
|
|
26
|
-
parent_metrics: MetricsContext,
|
|
27
|
-
) -> Result<(), WorkerRegistrationError> {
|
|
28
|
-
let tq = config.task_queue.clone();
|
|
29
|
-
let metrics = parent_metrics.with_new_attrs([task_queue(config.task_queue.clone())]);
|
|
30
|
-
let worker = Worker::new(config, sticky_queue, gateway, metrics);
|
|
31
|
-
self.set_worker_for_task_queue(tq, worker)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pub fn set_worker_for_task_queue(
|
|
35
|
-
&self,
|
|
36
|
-
tq: String,
|
|
37
|
-
worker: Worker,
|
|
38
|
-
) -> Result<(), WorkerRegistrationError> {
|
|
39
|
-
if self
|
|
40
|
-
.workers
|
|
41
|
-
.load()
|
|
42
|
-
.get(&tq)
|
|
43
|
-
.map(Option::is_some)
|
|
44
|
-
.unwrap_or_default()
|
|
45
|
-
{
|
|
46
|
-
return Err(WorkerRegistrationError::WorkerAlreadyRegisteredForQueue(tq));
|
|
47
|
-
}
|
|
48
|
-
let tq = &tq;
|
|
49
|
-
let worker = WorkerRefCt::new(worker);
|
|
50
|
-
self.workers.rcu(|map| {
|
|
51
|
-
let mut map = HashMap::clone(map);
|
|
52
|
-
map.insert(tq.clone(), Some(worker.clone()));
|
|
53
|
-
map
|
|
54
|
-
});
|
|
55
|
-
Ok(())
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
pub fn get(&self, task_queue: &str) -> Result<impl Deref<Target = Worker>, WorkerLookupErr> {
|
|
59
|
-
if let Some(w) = self.workers.load().get(task_queue) {
|
|
60
|
-
if let Some(w) = w {
|
|
61
|
-
Ok(w.clone())
|
|
62
|
-
} else {
|
|
63
|
-
Err(WorkerLookupErr::Shutdown(task_queue.to_string()))
|
|
64
|
-
}
|
|
65
|
-
} else {
|
|
66
|
-
Err(WorkerLookupErr::NoWorker(task_queue.to_string()))
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
pub async fn shutdown_one(&self, task_queue: &str) {
|
|
71
|
-
info!("Shutting down worker on queue {}", task_queue);
|
|
72
|
-
let mut maybe_worker = None;
|
|
73
|
-
if let Some(stored_worker) = self.workers.load().get(task_queue) {
|
|
74
|
-
if let Some(w) = stored_worker {
|
|
75
|
-
w.shutdown().await;
|
|
76
|
-
}
|
|
77
|
-
self.workers.rcu(|map| {
|
|
78
|
-
let mut map = HashMap::clone(map);
|
|
79
|
-
if maybe_worker.is_none() {
|
|
80
|
-
maybe_worker = map.get_mut(task_queue).and_then(Option::take);
|
|
81
|
-
}
|
|
82
|
-
map
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if let Some(w) = maybe_worker {
|
|
86
|
-
w.destroy().await;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
pub async fn shutdown_all(&self) {
|
|
91
|
-
// First notify all workers and allow tasks to drain
|
|
92
|
-
join_all(self.workers.load().values().map(|w| async move {
|
|
93
|
-
if let Some(w) = w {
|
|
94
|
-
w.shutdown().await;
|
|
95
|
-
}
|
|
96
|
-
}))
|
|
97
|
-
.await;
|
|
98
|
-
|
|
99
|
-
let mut all_workers = vec![];
|
|
100
|
-
self.workers.rcu(|map| {
|
|
101
|
-
let mut map = HashMap::clone(map);
|
|
102
|
-
for worker in map.values_mut() {
|
|
103
|
-
all_workers.push(worker.take());
|
|
104
|
-
}
|
|
105
|
-
map
|
|
106
|
-
});
|
|
107
|
-
join_all(all_workers.into_iter().map(|w| async move {
|
|
108
|
-
if let Some(w) = w {
|
|
109
|
-
w.destroy().await;
|
|
110
|
-
}
|
|
111
|
-
}))
|
|
112
|
-
.await;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/// Fun little struct that allows us to efficiently `await` for outstanding references to workers
|
|
117
|
-
/// to reach 0 before we consume it forever.
|
|
118
|
-
#[derive(Clone)]
|
|
119
|
-
struct WorkerRefCt {
|
|
120
|
-
inner: Option<Arc<Worker>>,
|
|
121
|
-
notify: Arc<Notify>,
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
impl WorkerRefCt {
|
|
125
|
-
fn new(worker: Worker) -> Self {
|
|
126
|
-
Self {
|
|
127
|
-
inner: Some(Arc::new(worker)),
|
|
128
|
-
notify: Arc::new(Notify::new()),
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async fn destroy(mut self) {
|
|
133
|
-
let mut arc = self.inner.take().unwrap();
|
|
134
|
-
loop {
|
|
135
|
-
self.notify.notified().await;
|
|
136
|
-
match Arc::try_unwrap(arc) {
|
|
137
|
-
Ok(w) => {
|
|
138
|
-
w.finalize_shutdown().await;
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
Err(a) => {
|
|
142
|
-
arc = a;
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
impl Deref for WorkerRefCt {
|
|
151
|
-
type Target = Worker;
|
|
152
|
-
|
|
153
|
-
fn deref(&self) -> &Self::Target {
|
|
154
|
-
self.inner.as_deref().expect("Must exist")
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
impl Drop for WorkerRefCt {
|
|
159
|
-
fn drop(&mut self) {
|
|
160
|
-
match &self.inner {
|
|
161
|
-
// Notify once destroy has been requested
|
|
162
|
-
None => self.notify.notify_one(),
|
|
163
|
-
Some(arc) => {
|
|
164
|
-
// We wait until 2 rather than 1 because we ourselves still have an Arc
|
|
165
|
-
if Arc::strong_count(arc) == 2 {
|
|
166
|
-
self.notify.notify_one();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
syntax = "proto3";
|
|
2
|
-
|
|
3
|
-
package coresdk.bridge;
|
|
4
|
-
|
|
5
|
-
import "temporal/sdk/core/bridge/bridge.proto";
|
|
6
|
-
|
|
7
|
-
service Bridge {
|
|
8
|
-
// Starts an isolated core instance unique to this stream that will
|
|
9
|
-
// automatically be shutdown on completion of the stream. The caller must
|
|
10
|
-
// provide the first message and it must be an "init". No other calls can be
|
|
11
|
-
// made until the init response has been received by the client.
|
|
12
|
-
//
|
|
13
|
-
// Every request message will have a single correlated response message,
|
|
14
|
-
// though not necessarily in a particular order or timeframe.
|
|
15
|
-
//
|
|
16
|
-
// There is no requst for "shutdown", because it is implied on stream
|
|
17
|
-
// completion.
|
|
18
|
-
//
|
|
19
|
-
// The stream approach is chosen because core is inherently stateful while
|
|
20
|
-
// gRPC unary RPCs are not. Upon abnormal stream close, the caller should
|
|
21
|
-
// reattempt, performing the init again.
|
|
22
|
-
rpc Stream(stream StreamRequest) returns (stream StreamResponse);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
message StreamRequest {
|
|
26
|
-
// The ID sent in the response. This is not technically required nor must it
|
|
27
|
-
// be unique if the caller, say, knows they only have one message outstanding
|
|
28
|
-
// of a certain type. However, it is recommended that this always be present
|
|
29
|
-
// and unique to avoid confusion.
|
|
30
|
-
string id = 1;
|
|
31
|
-
|
|
32
|
-
oneof request {
|
|
33
|
-
InitRequest init = 2;
|
|
34
|
-
RegisterWorkerRequest register_worker = 3;
|
|
35
|
-
PollWorkflowActivationRequest poll_workflow_activation = 4;
|
|
36
|
-
PollActivityTaskRequest poll_activity_task = 5;
|
|
37
|
-
CompleteWorkflowActivationRequest complete_workflow_activation = 6;
|
|
38
|
-
CompleteActivityTaskRequest complete_activity_task = 7;
|
|
39
|
-
RecordActivityHeartbeatRequest record_activity_heartbeat = 8;
|
|
40
|
-
RequestWorkflowEvictionRequest request_workflow_eviction = 9;
|
|
41
|
-
ShutdownWorkerRequest shutdown_worker = 10;
|
|
42
|
-
FetchBufferedLogsRequest fetch_buffered_logs = 11;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
message StreamResponse {
|
|
47
|
-
string request_id = 1;
|
|
48
|
-
|
|
49
|
-
oneof response {
|
|
50
|
-
InitResponse init = 2;
|
|
51
|
-
RegisterWorkerResponse register_worker = 3;
|
|
52
|
-
PollWorkflowActivationResponse poll_workflow_activation = 4;
|
|
53
|
-
PollActivityTaskResponse poll_activity_task = 5;
|
|
54
|
-
CompleteWorkflowActivationResponse complete_workflow_activation = 6;
|
|
55
|
-
CompleteActivityTaskResponse complete_activity_task = 7;
|
|
56
|
-
RecordActivityHeartbeatResponse record_activity_heartbeat = 8;
|
|
57
|
-
RequestWorkflowEvictionResponse request_workflow_eviction = 9;
|
|
58
|
-
ShutdownWorkerResponse shutdown_worker = 10;
|
|
59
|
-
FetchBufferedLogsResponse fetch_buffered_logs = 11;
|
|
60
|
-
}
|
|
61
|
-
}
|