@temporalio/core-bridge 1.12.0 → 1.12.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 +64 -119
- package/Cargo.toml +1 -1
- package/index.js +3 -2
- 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/.cargo/config.toml +1 -2
- package/sdk-core/.github/workflows/per-pr.yml +2 -0
- package/sdk-core/AGENTS.md +7 -0
- package/sdk-core/Cargo.toml +9 -5
- package/sdk-core/README.md +6 -5
- package/sdk-core/client/Cargo.toml +3 -2
- package/sdk-core/client/src/lib.rs +17 -8
- package/sdk-core/client/src/metrics.rs +57 -23
- package/sdk-core/client/src/raw.rs +33 -15
- package/sdk-core/core/Cargo.toml +11 -9
- package/sdk-core/core/benches/workflow_replay.rs +114 -15
- package/sdk-core/core/src/core_tests/activity_tasks.rs +18 -18
- package/sdk-core/core/src/core_tests/child_workflows.rs +4 -4
- package/sdk-core/core/src/core_tests/determinism.rs +6 -6
- package/sdk-core/core/src/core_tests/local_activities.rs +20 -20
- package/sdk-core/core/src/core_tests/mod.rs +40 -5
- package/sdk-core/core/src/core_tests/queries.rs +25 -16
- package/sdk-core/core/src/core_tests/replay_flag.rs +3 -3
- package/sdk-core/core/src/core_tests/updates.rs +3 -3
- package/sdk-core/core/src/core_tests/workers.rs +9 -7
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +40 -42
- package/sdk-core/core/src/ephemeral_server/mod.rs +1 -19
- package/sdk-core/core/src/lib.rs +10 -1
- package/sdk-core/core/src/pollers/poll_buffer.rs +2 -2
- package/sdk-core/core/src/replay/mod.rs +3 -3
- package/sdk-core/core/src/telemetry/metrics.rs +306 -152
- package/sdk-core/core/src/telemetry/mod.rs +11 -4
- package/sdk-core/core/src/telemetry/otel.rs +134 -131
- package/sdk-core/core/src/telemetry/prometheus_meter.rs +885 -0
- package/sdk-core/core/src/telemetry/prometheus_server.rs +48 -28
- package/sdk-core/core/src/test_help/mod.rs +27 -12
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +7 -7
- package/sdk-core/core/src/worker/activities.rs +4 -4
- package/sdk-core/core/src/worker/client/mocks.rs +10 -3
- package/sdk-core/core/src/worker/client.rs +68 -5
- package/sdk-core/core/src/worker/heartbeat.rs +229 -0
- package/sdk-core/core/src/worker/mod.rs +35 -14
- package/sdk-core/core/src/worker/tuner/resource_based.rs +4 -4
- package/sdk-core/core/src/worker/workflow/history_update.rs +71 -19
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -2
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -1
- package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +31 -48
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -2
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +3 -3
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +4 -1
- package/sdk-core/core/src/worker/workflow/managed_run.rs +1 -1
- package/sdk-core/core/src/worker/workflow/mod.rs +15 -15
- package/sdk-core/core-api/Cargo.toml +2 -2
- package/sdk-core/core-api/src/envconfig.rs +204 -99
- package/sdk-core/core-api/src/lib.rs +9 -0
- package/sdk-core/core-api/src/telemetry/metrics.rs +548 -100
- package/sdk-core/core-api/src/worker.rs +11 -5
- package/sdk-core/core-c-bridge/Cargo.toml +49 -0
- package/sdk-core/core-c-bridge/build.rs +26 -0
- package/sdk-core/core-c-bridge/include/temporal-sdk-core-c-bridge.h +817 -0
- package/sdk-core/core-c-bridge/src/client.rs +679 -0
- package/sdk-core/core-c-bridge/src/lib.rs +245 -0
- package/sdk-core/core-c-bridge/src/metric.rs +682 -0
- package/sdk-core/core-c-bridge/src/random.rs +61 -0
- package/sdk-core/core-c-bridge/src/runtime.rs +445 -0
- package/sdk-core/core-c-bridge/src/testing.rs +282 -0
- package/sdk-core/core-c-bridge/src/tests/context.rs +644 -0
- package/sdk-core/core-c-bridge/src/tests/mod.rs +178 -0
- package/sdk-core/core-c-bridge/src/tests/utils.rs +108 -0
- package/sdk-core/core-c-bridge/src/worker.rs +1069 -0
- package/sdk-core/etc/deps.svg +64 -64
- package/sdk-core/sdk/src/activity_context.rs +6 -4
- package/sdk-core/sdk/src/lib.rs +49 -27
- package/sdk-core/sdk/src/workflow_future.rs +18 -25
- package/sdk-core/sdk-core-protos/protos/api_upstream/README.md +4 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +0 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +630 -83
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +632 -78
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +6 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +32 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +10 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +26 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +47 -31
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +4 -4
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +7 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/worker/v1/message.proto +134 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +14 -11
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +148 -37
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +21 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -4
- package/sdk-core/sdk-core-protos/src/history_builder.rs +9 -5
- package/sdk-core/sdk-core-protos/src/lib.rs +96 -6
- package/sdk-core/test-utils/src/lib.rs +11 -3
- package/sdk-core/tests/cloud_tests.rs +3 -3
- package/sdk-core/tests/heavy_tests.rs +11 -3
- package/sdk-core/tests/integ_tests/client_tests.rs +12 -13
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +1 -1
- package/sdk-core/tests/integ_tests/metrics_tests.rs +188 -83
- package/sdk-core/tests/integ_tests/polling_tests.rs +1 -1
- package/sdk-core/tests/integ_tests/queries_tests.rs +56 -40
- package/sdk-core/tests/integ_tests/update_tests.rs +2 -7
- package/sdk-core/tests/integ_tests/worker_tests.rs +3 -4
- package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +3 -7
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +3 -5
- package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +24 -17
- package/src/client.rs +6 -0
- package/src/metrics.rs +6 -6
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#![allow(
|
|
2
|
+
// We choose to have narrow "unsafe" blocks instead of marking entire
|
|
3
|
+
// functions as unsafe. Even the example in clippy's docs at
|
|
4
|
+
// https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
|
|
5
|
+
// cause a rustc warning for unnecessary inner-unsafe when marked on fn.
|
|
6
|
+
// This check only applies to "pub" functions which are all exposed via C
|
|
7
|
+
// API.
|
|
8
|
+
clippy::not_unsafe_ptr_arg_deref,
|
|
9
|
+
)]
|
|
10
|
+
|
|
11
|
+
pub mod client;
|
|
12
|
+
pub mod metric;
|
|
13
|
+
pub mod random;
|
|
14
|
+
pub mod runtime;
|
|
15
|
+
pub mod testing;
|
|
16
|
+
pub mod worker;
|
|
17
|
+
|
|
18
|
+
#[cfg(test)]
|
|
19
|
+
mod tests;
|
|
20
|
+
|
|
21
|
+
use std::collections::HashMap;
|
|
22
|
+
|
|
23
|
+
#[repr(C)]
|
|
24
|
+
pub struct ByteArrayRef {
|
|
25
|
+
pub data: *const u8,
|
|
26
|
+
pub size: libc::size_t,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl ByteArrayRef {
|
|
30
|
+
pub fn empty() -> ByteArrayRef {
|
|
31
|
+
static EMPTY: &str = "";
|
|
32
|
+
EMPTY.into()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
pub fn to_slice(&self) -> &[u8] {
|
|
36
|
+
unsafe { std::slice::from_raw_parts(self.data, self.size) }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub fn to_slice_mut(&mut self) -> &mut [u8] {
|
|
40
|
+
unsafe { std::slice::from_raw_parts_mut(self.data as *mut u8, self.size) }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn to_vec(&self) -> Vec<u8> {
|
|
44
|
+
self.to_slice().to_vec()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn to_str(&self) -> &str {
|
|
48
|
+
// Trust caller to send UTF8. Even if we did do a checked call here with
|
|
49
|
+
// error, the caller can still have a bad pointer or something else
|
|
50
|
+
// wrong. Therefore we trust the caller implicitly.
|
|
51
|
+
unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(self.data, self.size)) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[allow(clippy::inherent_to_string)]
|
|
55
|
+
pub fn to_string(&self) -> String {
|
|
56
|
+
self.to_str().to_string()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
pub fn to_option_slice(&self) -> Option<&[u8]> {
|
|
60
|
+
if self.size == 0 {
|
|
61
|
+
None
|
|
62
|
+
} else {
|
|
63
|
+
Some(self.to_slice())
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub fn to_option_vec(&self) -> Option<Vec<u8>> {
|
|
68
|
+
if self.size == 0 {
|
|
69
|
+
None
|
|
70
|
+
} else {
|
|
71
|
+
Some(self.to_vec())
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
pub fn to_option_str(&self) -> Option<&str> {
|
|
76
|
+
if self.size == 0 {
|
|
77
|
+
None
|
|
78
|
+
} else {
|
|
79
|
+
Some(self.to_str())
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn to_option_string(&self) -> Option<String> {
|
|
84
|
+
self.to_option_str().map(str::to_string)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pub fn to_str_map_on_newlines(&self) -> HashMap<&str, &str> {
|
|
88
|
+
let strs: Vec<&str> = self.to_str().split('\n').collect();
|
|
89
|
+
strs.chunks_exact(2)
|
|
90
|
+
.map(|pair| (pair[0], pair[1]))
|
|
91
|
+
.collect()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pub fn to_string_map_on_newlines(&self) -> HashMap<String, String> {
|
|
95
|
+
self.to_str_map_on_newlines()
|
|
96
|
+
.iter()
|
|
97
|
+
.map(|(k, v)| (k.to_string(), v.to_string()))
|
|
98
|
+
.collect()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
impl From<&str> for ByteArrayRef {
|
|
103
|
+
fn from(value: &str) -> ByteArrayRef {
|
|
104
|
+
ByteArrayRef {
|
|
105
|
+
data: value.as_ptr(),
|
|
106
|
+
size: value.len(),
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
impl From<&[u8]> for ByteArrayRef {
|
|
112
|
+
fn from(value: &[u8]) -> ByteArrayRef {
|
|
113
|
+
ByteArrayRef {
|
|
114
|
+
data: value.as_ptr(),
|
|
115
|
+
size: value.len(),
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
impl<T> From<Option<T>> for ByteArrayRef
|
|
121
|
+
where
|
|
122
|
+
T: Into<ByteArrayRef>,
|
|
123
|
+
{
|
|
124
|
+
fn from(value: Option<T>) -> ByteArrayRef {
|
|
125
|
+
value.map(Into::into).unwrap_or(ByteArrayRef::empty())
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[repr(C)]
|
|
130
|
+
pub struct ByteArrayRefArray {
|
|
131
|
+
pub data: *const ByteArrayRef,
|
|
132
|
+
pub size: libc::size_t,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
impl ByteArrayRefArray {
|
|
136
|
+
pub fn to_str_vec(&self) -> Vec<&str> {
|
|
137
|
+
if self.size == 0 {
|
|
138
|
+
vec![]
|
|
139
|
+
} else {
|
|
140
|
+
let raw = unsafe { std::slice::from_raw_parts(self.data, self.size) };
|
|
141
|
+
raw.iter().map(ByteArrayRef::to_str).collect()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// Metadata is <key1>\n<value1>\n<key2>\n<value2>. Metadata keys or
|
|
147
|
+
/// values cannot contain a newline within.
|
|
148
|
+
pub type MetadataRef = ByteArrayRef;
|
|
149
|
+
|
|
150
|
+
#[repr(C)]
|
|
151
|
+
pub struct ByteArray {
|
|
152
|
+
pub data: *const u8,
|
|
153
|
+
pub size: libc::size_t,
|
|
154
|
+
/// For internal use only.
|
|
155
|
+
cap: libc::size_t,
|
|
156
|
+
/// For internal use only.
|
|
157
|
+
disable_free: bool,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
impl ByteArray {
|
|
161
|
+
pub fn from_utf8(str: String) -> ByteArray {
|
|
162
|
+
ByteArray::from_vec(str.into_bytes())
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
pub fn from_vec(vec: Vec<u8>) -> ByteArray {
|
|
166
|
+
// Mimics Vec::into_raw_parts that's only available in nightly
|
|
167
|
+
let mut vec = std::mem::ManuallyDrop::new(vec);
|
|
168
|
+
ByteArray {
|
|
169
|
+
data: vec.as_mut_ptr(),
|
|
170
|
+
size: vec.len(),
|
|
171
|
+
cap: vec.capacity(),
|
|
172
|
+
disable_free: false,
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
pub fn from_vec_disable_free(vec: Vec<u8>) -> ByteArray {
|
|
177
|
+
let mut b = ByteArray::from_vec(vec);
|
|
178
|
+
b.disable_free = true;
|
|
179
|
+
b
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pub fn into_raw(self) -> *mut ByteArray {
|
|
183
|
+
Box::into_raw(Box::new(self))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
pub fn as_ref(&self) -> ByteArrayRef {
|
|
187
|
+
ByteArrayRef {
|
|
188
|
+
data: self.data,
|
|
189
|
+
size: self.size,
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Required because these instances are used by lazy_static and raw pointers are
|
|
195
|
+
// not usually safe for send/sync.
|
|
196
|
+
unsafe impl Send for ByteArray {}
|
|
197
|
+
unsafe impl Sync for ByteArray {}
|
|
198
|
+
|
|
199
|
+
impl Drop for ByteArray {
|
|
200
|
+
fn drop(&mut self) {
|
|
201
|
+
// In cases where freeing is disabled (or technically some other
|
|
202
|
+
// drop-but-not-freed situation though we don't expect any), the bytes
|
|
203
|
+
// remain non-null so we re-own them here. See "byte_array_free" in
|
|
204
|
+
// runtime.rs.
|
|
205
|
+
if !self.data.is_null() {
|
|
206
|
+
unsafe { Vec::from_raw_parts(self.data as *mut u8, self.size, self.cap) };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// Used for maintaining pointer to user data across threads. See
|
|
212
|
+
/// https://doc.rust-lang.org/nomicon/send-and-sync.html.
|
|
213
|
+
struct UserDataHandle(*mut libc::c_void);
|
|
214
|
+
unsafe impl Send for UserDataHandle {}
|
|
215
|
+
unsafe impl Sync for UserDataHandle {}
|
|
216
|
+
|
|
217
|
+
impl From<UserDataHandle> for *mut libc::c_void {
|
|
218
|
+
fn from(v: UserDataHandle) -> Self {
|
|
219
|
+
v.0
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
pub struct CancellationToken {
|
|
224
|
+
token: tokio_util::sync::CancellationToken,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#[unsafe(no_mangle)]
|
|
228
|
+
pub extern "C" fn temporal_core_cancellation_token_new() -> *mut CancellationToken {
|
|
229
|
+
Box::into_raw(Box::new(CancellationToken {
|
|
230
|
+
token: tokio_util::sync::CancellationToken::new(),
|
|
231
|
+
}))
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#[unsafe(no_mangle)]
|
|
235
|
+
pub extern "C" fn temporal_core_cancellation_token_cancel(token: *mut CancellationToken) {
|
|
236
|
+
let token = unsafe { &*token };
|
|
237
|
+
token.token.cancel();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#[unsafe(no_mangle)]
|
|
241
|
+
pub extern "C" fn temporal_core_cancellation_token_free(token: *mut CancellationToken) {
|
|
242
|
+
unsafe {
|
|
243
|
+
let _ = Box::from_raw(token);
|
|
244
|
+
}
|
|
245
|
+
}
|