@temporalio/core-bridge 0.20.2 → 0.22.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.
- package/Cargo.lock +137 -127
- package/index.d.ts +7 -2
- package/package.json +3 -3
- package/releases/aarch64-apple-darwin/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/docker-compose.yaml +5 -4
- package/sdk-core/client/Cargo.toml +1 -0
- package/sdk-core/client/src/lib.rs +52 -9
- package/sdk-core/client/src/raw.rs +9 -1
- package/sdk-core/client/src/retry.rs +12 -1
- package/sdk-core/client/src/workflow_handle/mod.rs +183 -0
- package/sdk-core/core/src/abstractions.rs +10 -3
- package/sdk-core/core/src/core_tests/child_workflows.rs +7 -9
- package/sdk-core/core/src/core_tests/determinism.rs +8 -19
- package/sdk-core/core/src/core_tests/local_activities.rs +22 -32
- package/sdk-core/core/src/core_tests/queries.rs +272 -5
- package/sdk-core/core/src/core_tests/workers.rs +4 -34
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +197 -41
- package/sdk-core/core/src/pending_activations.rs +11 -0
- package/sdk-core/core/src/telemetry/mod.rs +1 -1
- package/sdk-core/core/src/test_help/mod.rs +57 -7
- package/sdk-core/core/src/worker/mod.rs +64 -15
- package/sdk-core/core/src/workflow/machines/mod.rs +1 -1
- package/sdk-core/core/src/workflow/machines/timer_state_machine.rs +2 -2
- package/sdk-core/core/src/workflow/machines/workflow_machines.rs +14 -3
- package/sdk-core/core/src/workflow/mod.rs +5 -2
- package/sdk-core/core/src/workflow/workflow_tasks/cache_manager.rs +47 -2
- package/sdk-core/core/src/workflow/workflow_tasks/concurrency_manager.rs +16 -2
- package/sdk-core/core/src/workflow/workflow_tasks/mod.rs +252 -125
- package/sdk-core/core-api/src/worker.rs +9 -0
- package/sdk-core/sdk/Cargo.toml +1 -0
- package/sdk-core/sdk/src/activity_context.rs +223 -0
- package/sdk-core/sdk/src/interceptors.rs +8 -2
- package/sdk-core/sdk/src/lib.rs +167 -122
- package/sdk-core/sdk-core-protos/src/history_info.rs +3 -7
- package/sdk-core/test-utils/Cargo.toml +1 -0
- package/sdk-core/test-utils/src/lib.rs +78 -37
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +11 -4
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +0 -1
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +0 -3
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +33 -17
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +10 -1
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +0 -1
- package/sdk-core/tests/integ_tests/workflow_tests.rs +71 -3
- package/sdk-core/tests/load_tests.rs +80 -6
- package/src/errors.rs +9 -2
- package/src/lib.rs +39 -16
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
package/src/errors.rs
CHANGED
|
@@ -10,6 +10,8 @@ pub static SHUTDOWN_ERROR: OnceCell<Root<JsFunction>> = OnceCell::new();
|
|
|
10
10
|
pub static NO_WORKER_ERROR: OnceCell<Root<JsFunction>> = OnceCell::new();
|
|
11
11
|
/// Something unexpected happened, considered fatal
|
|
12
12
|
pub static UNEXPECTED_ERROR: OnceCell<Root<JsFunction>> = OnceCell::new();
|
|
13
|
+
/// Used in different parts of the project to signal that something unexpected has happened
|
|
14
|
+
pub static ILLEGAL_STATE_ERROR: OnceCell<Root<JsFunction>> = OnceCell::new();
|
|
13
15
|
|
|
14
16
|
static ALREADY_REGISTERED_ERRORS: OnceCell<bool> = OnceCell::new();
|
|
15
17
|
|
|
@@ -70,9 +72,9 @@ pub fn register_errors(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
|
70
72
|
let res = ALREADY_REGISTERED_ERRORS.set(true);
|
|
71
73
|
if res.is_err() {
|
|
72
74
|
// Don't do anything if errors are already registered
|
|
73
|
-
return Ok(cx.undefined())
|
|
75
|
+
return Ok(cx.undefined());
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
|
|
76
78
|
let mapping = cx.argument::<JsObject>(0)?;
|
|
77
79
|
let shutdown_error = mapping
|
|
78
80
|
.get(&mut cx, "ShutdownError")?
|
|
@@ -90,11 +92,16 @@ pub fn register_errors(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
|
90
92
|
.get(&mut cx, "UnexpectedError")?
|
|
91
93
|
.downcast_or_throw::<JsFunction, FunctionContext>(&mut cx)?
|
|
92
94
|
.root(&mut cx);
|
|
95
|
+
let illegal_state_error = mapping
|
|
96
|
+
.get(&mut cx, "IllegalStateError")?
|
|
97
|
+
.downcast_or_throw::<JsFunction, FunctionContext>(&mut cx)?
|
|
98
|
+
.root(&mut cx);
|
|
93
99
|
|
|
94
100
|
TRANSPORT_ERROR.get_or_try_init(|| Ok(transport_error))?;
|
|
95
101
|
SHUTDOWN_ERROR.get_or_try_init(|| Ok(shutdown_error))?;
|
|
96
102
|
NO_WORKER_ERROR.get_or_try_init(|| Ok(no_worker_error))?;
|
|
97
103
|
UNEXPECTED_ERROR.get_or_try_init(|| Ok(unexpected_error))?;
|
|
104
|
+
ILLEGAL_STATE_ERROR.get_or_try_init(|| Ok(illegal_state_error))?;
|
|
98
105
|
|
|
99
106
|
Ok(cx.undefined())
|
|
100
107
|
}
|
package/src/lib.rs
CHANGED
|
@@ -8,6 +8,7 @@ use once_cell::sync::OnceCell;
|
|
|
8
8
|
use opentelemetry::trace::{FutureExt, SpanContext, TraceContextExt};
|
|
9
9
|
use prost::Message;
|
|
10
10
|
use std::{
|
|
11
|
+
cell::RefCell,
|
|
11
12
|
fmt::Display,
|
|
12
13
|
future::Future,
|
|
13
14
|
sync::Arc,
|
|
@@ -135,7 +136,7 @@ struct Client {
|
|
|
135
136
|
core_client: Arc<RawClient>,
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
type BoxedClient = JsBox<Client
|
|
139
|
+
type BoxedClient = JsBox<RefCell<Option<Client>>>;
|
|
139
140
|
impl Finalize for Client {}
|
|
140
141
|
|
|
141
142
|
/// Worker struct, hold a reference for the channel sender responsible for sending requests from
|
|
@@ -291,10 +292,10 @@ fn start_bridge_loop(event_queue: Arc<EventQueue>, receiver: &mut UnboundedRecei
|
|
|
291
292
|
}
|
|
292
293
|
Ok(client) => {
|
|
293
294
|
send_result(event_queue.clone(), callback, |cx| {
|
|
294
|
-
Ok(cx.boxed(Client {
|
|
295
|
+
Ok(cx.boxed(RefCell::new(Some(Client {
|
|
295
296
|
runtime,
|
|
296
297
|
core_client: Arc::new(client),
|
|
297
|
-
}))
|
|
298
|
+
}))))
|
|
298
299
|
});
|
|
299
300
|
}
|
|
300
301
|
}
|
|
@@ -590,15 +591,23 @@ fn worker_new(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
|
590
591
|
let callback = cx.argument::<JsFunction>(2)?;
|
|
591
592
|
|
|
592
593
|
let config = worker_options.as_worker_config(&mut cx)?;
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
594
|
+
match &*client.borrow() {
|
|
595
|
+
None => {
|
|
596
|
+
callback_with_error(&mut cx, callback, move |cx| {
|
|
597
|
+
UNEXPECTED_ERROR.from_string(cx, "Tried to use closed Client".to_string())
|
|
598
|
+
})?;
|
|
599
|
+
}
|
|
600
|
+
Some(client) => {
|
|
601
|
+
let request = Request::InitWorker {
|
|
602
|
+
client: client.core_client.clone(),
|
|
603
|
+
runtime: client.runtime.clone(),
|
|
604
|
+
config,
|
|
605
|
+
callback: callback.root(&mut cx),
|
|
606
|
+
};
|
|
607
|
+
if let Err(err) = client.runtime.sender.send(request) {
|
|
608
|
+
callback_with_unexpected_error(&mut cx, callback, err)?;
|
|
609
|
+
};
|
|
610
|
+
}
|
|
602
611
|
};
|
|
603
612
|
|
|
604
613
|
Ok(cx.undefined())
|
|
@@ -783,13 +792,26 @@ fn worker_record_activity_heartbeat(mut cx: FunctionContext) -> JsResult<JsUndef
|
|
|
783
792
|
fn worker_shutdown(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
784
793
|
let worker = cx.argument::<BoxedWorker>(0)?;
|
|
785
794
|
let callback = cx.argument::<JsFunction>(1)?;
|
|
786
|
-
|
|
795
|
+
if let Err(err) = worker.runtime.sender.send(Request::ShutdownWorker {
|
|
787
796
|
worker: worker.core_worker.clone(),
|
|
788
797
|
callback: callback.root(&mut cx),
|
|
789
798
|
}) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
799
|
+
UNEXPECTED_ERROR
|
|
800
|
+
.from_error(&mut cx, err)
|
|
801
|
+
.and_then(|err| cx.throw(err))?;
|
|
802
|
+
};
|
|
803
|
+
Ok(cx.undefined())
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/// Drop a reference to a Client, once all references are dropped, the Client will be closed.
|
|
807
|
+
fn client_close(mut cx: FunctionContext) -> JsResult<JsUndefined> {
|
|
808
|
+
let client = cx.argument::<BoxedClient>(0)?;
|
|
809
|
+
if client.replace(None).is_none() {
|
|
810
|
+
ILLEGAL_STATE_ERROR
|
|
811
|
+
.from_error(&mut cx, "Client already closed")
|
|
812
|
+
.and_then(|err| cx.throw(err))?;
|
|
813
|
+
};
|
|
814
|
+
Ok(cx.undefined())
|
|
793
815
|
}
|
|
794
816
|
|
|
795
817
|
/// Convert Rust SystemTime into a JS array with 2 numbers (seconds, nanos)
|
|
@@ -824,6 +846,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
|
|
824
846
|
cx.export_function("newWorker", worker_new)?;
|
|
825
847
|
cx.export_function("newReplayWorker", replay_worker_new)?;
|
|
826
848
|
cx.export_function("workerShutdown", worker_shutdown)?;
|
|
849
|
+
cx.export_function("clientClose", client_close)?;
|
|
827
850
|
cx.export_function("runtimeShutdown", runtime_shutdown)?;
|
|
828
851
|
cx.export_function("pollLogs", poll_logs)?;
|
|
829
852
|
cx.export_function(
|
|
Binary file
|