@temporalio/core-bridge 1.11.8 → 1.12.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 +219 -193
- package/Cargo.toml +27 -8
- package/README.md +5 -0
- package/index.js +72 -12
- package/lib/errors.d.ts +25 -0
- package/lib/errors.js +76 -1
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +11 -478
- package/lib/index.js +28 -5
- package/lib/index.js.map +1 -1
- package/lib/native.d.ts +330 -0
- package/lib/{worker-tuner.js → native.js} +1 -1
- package/lib/native.js.map +1 -0
- package/package.json +7 -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 +8 -2
- package/sdk-core/.cargo/multi-worker-manual-test +15 -0
- package/sdk-core/.github/workflows/per-pr.yml +40 -11
- package/sdk-core/AGENTS.md +73 -0
- package/sdk-core/ARCHITECTURE.md +71 -23
- package/sdk-core/Cargo.toml +1 -1
- package/sdk-core/README.md +4 -4
- package/sdk-core/arch_docs/workflow_task_chunking.md +51 -0
- package/sdk-core/client/Cargo.toml +1 -1
- package/sdk-core/client/src/lib.rs +49 -13
- package/sdk-core/client/src/metrics.rs +15 -16
- package/sdk-core/client/src/proxy.rs +2 -2
- package/sdk-core/client/src/raw.rs +54 -8
- package/sdk-core/client/src/retry.rs +109 -13
- package/sdk-core/client/src/worker_registry/mod.rs +4 -4
- package/sdk-core/client/src/workflow_handle/mod.rs +1 -1
- package/sdk-core/core/Cargo.toml +28 -8
- package/sdk-core/core/src/abstractions.rs +62 -10
- package/sdk-core/core/src/core_tests/activity_tasks.rs +180 -8
- package/sdk-core/core/src/core_tests/mod.rs +4 -4
- package/sdk-core/core/src/core_tests/queries.rs +18 -4
- package/sdk-core/core/src/core_tests/workers.rs +3 -3
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +191 -25
- package/sdk-core/core/src/ephemeral_server/mod.rs +10 -3
- package/sdk-core/core/src/internal_flags.rs +14 -14
- package/sdk-core/core/src/lib.rs +5 -2
- package/sdk-core/core/src/pollers/mod.rs +1 -1
- package/sdk-core/core/src/pollers/poll_buffer.rs +495 -164
- package/sdk-core/core/src/protosext/mod.rs +3 -3
- package/sdk-core/core/src/replay/mod.rs +3 -3
- package/sdk-core/core/src/telemetry/metrics.rs +13 -4
- package/sdk-core/core/src/telemetry/mod.rs +72 -70
- package/sdk-core/core/src/telemetry/otel.rs +51 -54
- package/sdk-core/core/src/test_help/mod.rs +9 -3
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +31 -11
- package/sdk-core/core/src/worker/activities/local_activities.rs +35 -28
- package/sdk-core/core/src/worker/activities.rs +58 -30
- package/sdk-core/core/src/worker/client/mocks.rs +3 -3
- package/sdk-core/core/src/worker/client.rs +155 -53
- package/sdk-core/core/src/worker/mod.rs +103 -95
- package/sdk-core/core/src/worker/nexus.rs +100 -73
- package/sdk-core/core/src/worker/tuner/resource_based.rs +14 -6
- package/sdk-core/core/src/worker/tuner.rs +4 -13
- package/sdk-core/core/src/worker/workflow/history_update.rs +47 -51
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -4
- package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +127 -32
- package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +1 -2
- package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +1 -1
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +55 -42
- package/sdk-core/core/src/worker/workflow/managed_run.rs +45 -35
- package/sdk-core/core/src/worker/workflow/mod.rs +200 -97
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +175 -4
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +38 -36
- package/sdk-core/core-api/Cargo.toml +8 -0
- package/sdk-core/core-api/src/envconfig.rs +1544 -0
- package/sdk-core/core-api/src/lib.rs +2 -0
- package/sdk-core/core-api/src/telemetry/metrics.rs +8 -0
- package/sdk-core/core-api/src/telemetry.rs +36 -3
- package/sdk-core/core-api/src/worker.rs +301 -75
- package/sdk-core/docker/docker-compose-telem.yaml +1 -0
- package/sdk-core/etc/prometheus.yaml +6 -2
- package/sdk-core/histories/long_local_activity_with_update-0_history.bin +0 -0
- package/sdk-core/histories/long_local_activity_with_update-1_history.bin +0 -0
- package/sdk-core/histories/long_local_activity_with_update-2_history.bin +0 -0
- package/sdk-core/histories/long_local_activity_with_update-3_history.bin +0 -0
- package/sdk-core/sdk/src/activity_context.rs +5 -0
- package/sdk-core/sdk/src/interceptors.rs +73 -3
- package/sdk-core/sdk/src/lib.rs +15 -16
- package/sdk-core/sdk/src/workflow_context/options.rs +10 -0
- package/sdk-core/sdk/src/workflow_context.rs +48 -29
- package/sdk-core/sdk/src/workflow_future.rs +5 -6
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/.github/workflows/push-to-buf.yml +20 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/CODEOWNERS +6 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/README.md +17 -6
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +1 -1
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.lock +7 -2
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/buf.yaml +2 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +78 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +29 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +74 -32
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +45 -15
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +7 -1
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +3 -3
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +3 -3
- package/sdk-core/sdk-core-protos/protos/api_upstream/LICENSE +1 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +1103 -88
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +1233 -151
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/activity/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +19 -24
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +12 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +45 -45
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/command_type.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +15 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/namespace.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/nexus.proto +0 -20
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/query.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/schedule.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/update.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/export/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/filter/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +75 -49
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +0 -20
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/protocol/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/query/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/replication/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/rules/v1/message.proto +90 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/schedule/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/enhanced_stack_trace.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/user_metadata.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +17 -38
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/update/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/version/v1/message.proto +0 -22
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +151 -44
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +172 -65
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +69 -28
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/activity_task/activity_task.proto +18 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/common/common.proto +5 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto +16 -1
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +21 -15
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +3 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +3 -0
- package/sdk-core/sdk-core-protos/src/lib.rs +60 -16
- package/sdk-core/test-utils/src/lib.rs +157 -39
- package/sdk-core/tests/cloud_tests.rs +86 -0
- package/sdk-core/tests/fuzzy_workflow.rs +23 -26
- package/sdk-core/tests/global_metric_tests.rs +116 -0
- package/sdk-core/tests/heavy_tests.rs +127 -7
- package/sdk-core/tests/integ_tests/client_tests.rs +2 -8
- package/sdk-core/tests/integ_tests/metrics_tests.rs +100 -106
- package/sdk-core/tests/integ_tests/polling_tests.rs +94 -8
- package/sdk-core/tests/integ_tests/update_tests.rs +75 -6
- package/sdk-core/tests/integ_tests/worker_tests.rs +54 -5
- package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +240 -0
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +41 -3
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +168 -8
- package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +285 -15
- package/sdk-core/tests/integ_tests/workflow_tests/priority.rs +12 -4
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -2
- package/sdk-core/tests/integ_tests/workflow_tests.rs +124 -74
- package/sdk-core/tests/main.rs +3 -51
- package/sdk-core/tests/manual_tests.rs +430 -0
- package/sdk-core/tests/runner.rs +28 -2
- package/src/client.rs +565 -0
- package/src/helpers/abort_controller.rs +204 -0
- package/src/helpers/callbacks.rs +299 -0
- package/src/helpers/errors.rs +302 -0
- package/src/helpers/future.rs +44 -0
- package/src/helpers/handles.rs +191 -0
- package/src/helpers/inspect.rs +18 -0
- package/src/helpers/json_string.rs +58 -0
- package/src/helpers/mod.rs +20 -0
- package/src/helpers/properties.rs +71 -0
- package/src/helpers/try_from_js.rs +213 -0
- package/src/helpers/try_into_js.rs +129 -0
- package/src/lib.rs +28 -40
- package/src/logs.rs +111 -0
- package/src/metrics.rs +325 -0
- package/src/runtime.rs +409 -498
- package/src/testing.rs +315 -57
- package/src/worker.rs +907 -378
- package/ts/errors.ts +57 -0
- package/ts/index.ts +10 -596
- package/ts/native.ts +496 -0
- package/lib/worker-tuner.d.ts +0 -167
- package/lib/worker-tuner.js.map +0 -1
- package/src/conversions/slot_supplier_bridge.rs +0 -291
- package/src/conversions.rs +0 -618
- package/src/errors.rs +0 -38
- package/src/helpers.rs +0 -297
- package/ts/worker-tuner.ts +0 -193
package/src/helpers.rs
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
use crate::errors::*;
|
|
2
|
-
use neon::{prelude::*, types::buffer::TypedArray};
|
|
3
|
-
use std::{fmt::Display, future::Future, sync::Arc};
|
|
4
|
-
|
|
5
|
-
/// Send a result to JS via callback using a [Channel]
|
|
6
|
-
pub fn send_result<F, T>(channel: Arc<Channel>, callback: Root<JsFunction>, res_fn: F)
|
|
7
|
-
where
|
|
8
|
-
F: for<'a> FnOnce(&mut TaskContext<'a>) -> NeonResult<Handle<'a, T>> + Send + 'static,
|
|
9
|
-
T: Value,
|
|
10
|
-
{
|
|
11
|
-
channel.send(move |mut cx| {
|
|
12
|
-
let callback = callback.into_inner(&mut cx);
|
|
13
|
-
let this = cx.undefined();
|
|
14
|
-
let error = cx.undefined();
|
|
15
|
-
let result = res_fn(&mut cx)?;
|
|
16
|
-
let args: Vec<Handle<JsValue>> = vec![error.upcast(), result.upcast()];
|
|
17
|
-
callback.call(&mut cx, this, args)?;
|
|
18
|
-
Ok(())
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// Send an error to JS via callback using a [Channel]
|
|
23
|
-
pub fn send_error<E, F>(channel: Arc<Channel>, callback: Root<JsFunction>, error_ctor: F)
|
|
24
|
-
where
|
|
25
|
-
E: Object,
|
|
26
|
-
F: for<'a> FnOnce(&mut TaskContext<'a>) -> JsResult<'a, E> + Send + 'static,
|
|
27
|
-
{
|
|
28
|
-
channel.send(move |mut cx| {
|
|
29
|
-
let callback = callback.into_inner(&mut cx);
|
|
30
|
-
callback_with_error(&mut cx, callback, error_ctor)
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/// Call `callback` with given error
|
|
35
|
-
pub fn callback_with_error<'a, C, E, F>(
|
|
36
|
-
cx: &mut C,
|
|
37
|
-
callback: Handle<JsFunction>,
|
|
38
|
-
error_ctor: F,
|
|
39
|
-
) -> NeonResult<()>
|
|
40
|
-
where
|
|
41
|
-
C: Context<'a>,
|
|
42
|
-
E: Object,
|
|
43
|
-
F: FnOnce(&mut C) -> JsResult<'a, E> + Send + 'static,
|
|
44
|
-
{
|
|
45
|
-
let this = cx.undefined();
|
|
46
|
-
let error = error_ctor(cx)?;
|
|
47
|
-
let result = cx.undefined();
|
|
48
|
-
let args: Vec<Handle<JsValue>> = vec![error.upcast(), result.upcast()];
|
|
49
|
-
callback.call(cx, this, args)?;
|
|
50
|
-
Ok(())
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/// Call `callback` with an UnexpectedError created from `err`
|
|
54
|
-
pub fn callback_with_unexpected_error<'a, C, E>(
|
|
55
|
-
cx: &mut C,
|
|
56
|
-
callback: Handle<JsFunction>,
|
|
57
|
-
err: E,
|
|
58
|
-
) -> NeonResult<()>
|
|
59
|
-
where
|
|
60
|
-
C: Context<'a>,
|
|
61
|
-
E: Display,
|
|
62
|
-
{
|
|
63
|
-
let err_str = format!("{}", err);
|
|
64
|
-
callback_with_error(cx, callback, move |cx| {
|
|
65
|
-
make_named_error_from_string(cx, UNEXPECTED_ERROR, err_str)
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// When Future completes, call given JS callback using a neon::Channel with either error or
|
|
70
|
-
/// undefined
|
|
71
|
-
pub async fn void_future_to_js<E, F, ER, EF>(
|
|
72
|
-
channel: Arc<Channel>,
|
|
73
|
-
callback: Root<JsFunction>,
|
|
74
|
-
f: F,
|
|
75
|
-
error_function: EF,
|
|
76
|
-
) where
|
|
77
|
-
E: Display + Send + 'static,
|
|
78
|
-
F: Future<Output = Result<(), E>> + Send,
|
|
79
|
-
ER: Object,
|
|
80
|
-
EF: for<'a> FnOnce(&mut TaskContext<'a>, E) -> JsResult<'a, ER> + Send + 'static,
|
|
81
|
-
{
|
|
82
|
-
match f.await {
|
|
83
|
-
Ok(()) => {
|
|
84
|
-
send_result(channel, callback, |cx| Ok(cx.undefined()));
|
|
85
|
-
}
|
|
86
|
-
Err(err) => {
|
|
87
|
-
send_error(channel, callback, |cx| error_function(cx, err));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
macro_rules! js_optional_getter {
|
|
93
|
-
($js_cx:expr, $js_obj:expr, $prop_name:expr, $js_type:ty) => {
|
|
94
|
-
match get_optional($js_cx, $js_obj, $prop_name) {
|
|
95
|
-
None => None,
|
|
96
|
-
Some(val) => {
|
|
97
|
-
if val.is_a::<$js_type, _>($js_cx) {
|
|
98
|
-
Some(val.downcast_or_throw::<$js_type, _>($js_cx)?)
|
|
99
|
-
} else {
|
|
100
|
-
Some($js_cx.throw_type_error(format!("Invalid {}", $prop_name))?)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
pub(crate) use js_optional_getter;
|
|
108
|
-
|
|
109
|
-
macro_rules! js_getter {
|
|
110
|
-
($js_cx:expr, $js_obj:expr, $prop_name:expr, $js_type:ty) => {
|
|
111
|
-
match get_optional($js_cx, $js_obj, $prop_name) {
|
|
112
|
-
None => $js_cx.throw_type_error(format!("{} must be defined", $prop_name))?,
|
|
113
|
-
Some(val) => {
|
|
114
|
-
if val.is_a::<$js_type, _>($js_cx) {
|
|
115
|
-
val.downcast_or_throw::<$js_type, _>($js_cx)?
|
|
116
|
-
} else {
|
|
117
|
-
$js_cx.throw_type_error(format!("Invalid {}", $prop_name))?
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
pub(crate) use js_getter;
|
|
125
|
-
|
|
126
|
-
macro_rules! js_optional_value_getter {
|
|
127
|
-
($js_cx:expr, $js_obj:expr, $prop_name:expr, $js_type:ty) => {
|
|
128
|
-
js_optional_getter!($js_cx, $js_obj, $prop_name, $js_type).map(|v| v.value($js_cx))
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
pub(crate) use js_optional_value_getter;
|
|
133
|
-
|
|
134
|
-
macro_rules! js_value_getter {
|
|
135
|
-
($js_cx:expr, $js_obj:expr, $prop_name:expr, $js_type:ty) => {
|
|
136
|
-
match js_optional_getter!($js_cx, $js_obj, $prop_name, $js_type) {
|
|
137
|
-
Some(val) => val.value($js_cx),
|
|
138
|
-
None => $js_cx.throw_type_error(format!("{} must be defined", $prop_name))?,
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
pub(crate) use js_value_getter;
|
|
144
|
-
|
|
145
|
-
/// Helper for extracting an optional attribute from [obj].
|
|
146
|
-
/// If [obj].[attr] is undefined or not present, None is returned
|
|
147
|
-
pub fn get_optional<'a, C, K>(
|
|
148
|
-
cx: &mut C,
|
|
149
|
-
obj: &Handle<JsObject>,
|
|
150
|
-
attr: K,
|
|
151
|
-
) -> Option<Handle<'a, JsValue>>
|
|
152
|
-
where
|
|
153
|
-
K: neon::object::PropertyKey,
|
|
154
|
-
C: Context<'a>,
|
|
155
|
-
{
|
|
156
|
-
match obj.get_value(cx, attr) {
|
|
157
|
-
Err(_) => None,
|
|
158
|
-
Ok(val) => match val.is_a::<JsUndefined, _>(cx) {
|
|
159
|
-
true => None,
|
|
160
|
-
false => Some(val),
|
|
161
|
-
},
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/// Helper for extracting a Vec<u8> from optional Buffer at [obj].[attr]
|
|
166
|
-
pub fn get_optional_vec<'a, C, K>(
|
|
167
|
-
cx: &mut C,
|
|
168
|
-
obj: &Handle<JsObject>,
|
|
169
|
-
attr: K,
|
|
170
|
-
) -> Result<Option<Vec<u8>>, neon::result::Throw>
|
|
171
|
-
where
|
|
172
|
-
K: neon::object::PropertyKey + Display + Clone,
|
|
173
|
-
C: Context<'a>,
|
|
174
|
-
{
|
|
175
|
-
if let Some(val) = get_optional(cx, obj, attr.clone()) {
|
|
176
|
-
let buf = val.downcast::<JsBuffer, C>(cx).map_err(|_| {
|
|
177
|
-
cx.throw_type_error::<_, Option<Vec<u8>>>(format!("Invalid {}", attr))
|
|
178
|
-
.unwrap_err()
|
|
179
|
-
})?;
|
|
180
|
-
Ok(Some(buf.as_slice(cx).to_vec()))
|
|
181
|
-
} else {
|
|
182
|
-
Ok(None)
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/// Helper for extracting a Vec<u8> from optional Buffer at [obj].[attr]
|
|
187
|
-
pub fn get_vec<'a, C, K>(
|
|
188
|
-
cx: &mut C,
|
|
189
|
-
obj: &Handle<JsObject>,
|
|
190
|
-
attr: K,
|
|
191
|
-
full_attr_path: &str,
|
|
192
|
-
) -> Result<Vec<u8>, neon::result::Throw>
|
|
193
|
-
where
|
|
194
|
-
K: neon::object::PropertyKey + Display + Clone,
|
|
195
|
-
C: Context<'a>,
|
|
196
|
-
{
|
|
197
|
-
if let Some(val) = get_optional(cx, obj, attr.clone()) {
|
|
198
|
-
let buf = val.downcast::<JsBuffer, C>(cx).map_err(|_| {
|
|
199
|
-
cx.throw_type_error::<_, Option<Vec<u8>>>(format!("Invalid {}", attr))
|
|
200
|
-
.unwrap_err()
|
|
201
|
-
})?;
|
|
202
|
-
Ok(buf.as_slice(cx).to_vec())
|
|
203
|
-
} else {
|
|
204
|
-
cx.throw_type_error::<_, Vec<u8>>(format!("Invalid or missing {}", full_attr_path))
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Recursively convert a Serde value to a JS value
|
|
209
|
-
pub fn serde_value_to_js_value<'a>(
|
|
210
|
-
cx: &mut impl Context<'a>,
|
|
211
|
-
val: serde_json::Value,
|
|
212
|
-
) -> JsResult<'a, JsValue> {
|
|
213
|
-
match val {
|
|
214
|
-
serde_json::Value::String(s) => Ok(cx.string(s).upcast()),
|
|
215
|
-
serde_json::Value::Number(n) => Ok(cx.number(n.as_f64().unwrap()).upcast()),
|
|
216
|
-
serde_json::Value::Bool(b) => Ok(cx.boolean(b).upcast()),
|
|
217
|
-
serde_json::Value::Null => Ok(cx.null().upcast()),
|
|
218
|
-
serde_json::Value::Array(vec) => {
|
|
219
|
-
let arr: Handle<'a, JsArray> = JsArray::new(cx, vec.len());
|
|
220
|
-
for (i, v) in vec.into_iter().enumerate() {
|
|
221
|
-
let v = serde_value_to_js_value(cx, v)?;
|
|
222
|
-
arr.set(cx, i as u32, v)?;
|
|
223
|
-
}
|
|
224
|
-
Ok(arr.upcast())
|
|
225
|
-
}
|
|
226
|
-
serde_json::Value::Object(map) => hashmap_to_js_value(cx, map).map(|v| v.upcast()),
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
pub fn hashmap_to_js_value<'a>(
|
|
231
|
-
cx: &mut impl Context<'a>,
|
|
232
|
-
map: impl IntoIterator<Item = (String, serde_json::Value)>,
|
|
233
|
-
) -> JsResult<'a, JsObject> {
|
|
234
|
-
let obj: Handle<'a, JsObject> = cx.empty_object();
|
|
235
|
-
for (k, v) in map {
|
|
236
|
-
let k = cx.string(snake_to_camel(k));
|
|
237
|
-
let v = serde_value_to_js_value(cx, v)?;
|
|
238
|
-
obj.set(cx, k, v)?;
|
|
239
|
-
}
|
|
240
|
-
Ok(obj)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
fn snake_to_camel(input: String) -> String {
|
|
244
|
-
match input.find('_') {
|
|
245
|
-
None => input,
|
|
246
|
-
Some(first) => {
|
|
247
|
-
let mut result = String::with_capacity(input.len());
|
|
248
|
-
if first > 0 {
|
|
249
|
-
result.push_str(&input[..first]);
|
|
250
|
-
}
|
|
251
|
-
let mut capitalize = true;
|
|
252
|
-
for c in input[first + 1..].chars() {
|
|
253
|
-
if c == '_' {
|
|
254
|
-
capitalize = true;
|
|
255
|
-
} else if capitalize {
|
|
256
|
-
result.push(c.to_ascii_uppercase());
|
|
257
|
-
capitalize = false;
|
|
258
|
-
} else {
|
|
259
|
-
result.push(c.to_ascii_lowercase());
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
result
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
#[allow(dead_code)]
|
|
268
|
-
// Useful to help debug JSObject contents
|
|
269
|
-
pub fn log_js_object<'a, 'b, C: Context<'b>>(cx: &mut C, js_object: &Handle<'a, JsObject>) {
|
|
270
|
-
let global = cx.global_object();
|
|
271
|
-
let console = global
|
|
272
|
-
.get::<JsObject, _, _>(cx, "console")
|
|
273
|
-
.expect("Failed to get console object");
|
|
274
|
-
|
|
275
|
-
let log = console
|
|
276
|
-
.get::<JsFunction, _, _>(cx, "log")
|
|
277
|
-
.expect("Failed to get log function");
|
|
278
|
-
|
|
279
|
-
let args = vec![js_object.upcast()]; // Upcast js_object to JsValue
|
|
280
|
-
log.call(cx, console, args)
|
|
281
|
-
.expect("Failed to call console.log");
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
#[cfg(test)]
|
|
285
|
-
mod tests {
|
|
286
|
-
use super::*;
|
|
287
|
-
|
|
288
|
-
#[test]
|
|
289
|
-
fn snake_to_camel_works() {
|
|
290
|
-
assert_eq!(snake_to_camel("this_is_a_test".into()), "thisIsATest");
|
|
291
|
-
assert_eq!(snake_to_camel("this___IS_a_TEST".into()), "thisIsATest");
|
|
292
|
-
assert_eq!(
|
|
293
|
-
snake_to_camel("éàç_this_is_a_test".into()),
|
|
294
|
-
"éàçThisIsATest"
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
}
|
package/ts/worker-tuner.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A worker tuner allows the customization of the performance characteristics of workers by
|
|
3
|
-
* controlling how "slots" are handed out for different task types. In order to poll for and then
|
|
4
|
-
* run tasks, a slot must first be reserved by the {@link SlotSupplier} returned by the tuner.
|
|
5
|
-
*
|
|
6
|
-
* @experimental
|
|
7
|
-
*/
|
|
8
|
-
export interface WorkerTuner {
|
|
9
|
-
workflowTaskSlotSupplier: SlotSupplier;
|
|
10
|
-
activityTaskSlotSupplier: SlotSupplier;
|
|
11
|
-
localActivityTaskSlotSupplier: SlotSupplier;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type SlotInfo = WorkflowSlotInfo | ActivitySlotInfo | LocalActivitySlotInfo;
|
|
15
|
-
|
|
16
|
-
export interface WorkflowSlotInfo {
|
|
17
|
-
type: 'workflow';
|
|
18
|
-
workflowId: string;
|
|
19
|
-
runId: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ActivitySlotInfo {
|
|
23
|
-
type: 'activity';
|
|
24
|
-
activityId: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface LocalActivitySlotInfo {
|
|
28
|
-
type: 'local-activity';
|
|
29
|
-
activityId: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Controls how slots are handed out for a specific task type.
|
|
34
|
-
*
|
|
35
|
-
* For now, only {@link ResourceBasedSlotOptions} and {@link FixedSizeSlotSupplier} are supported,
|
|
36
|
-
* but we may add support for custom tuners in the future.
|
|
37
|
-
*
|
|
38
|
-
* @experimental
|
|
39
|
-
*/
|
|
40
|
-
export type SlotSupplier = ResourceBasedSlotsForType | FixedSizeSlotSupplier | CustomSlotSupplier<any>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Options for a specific slot type within a {@link ResourceBasedSlotsForType}
|
|
44
|
-
*
|
|
45
|
-
* @experimental
|
|
46
|
-
*/
|
|
47
|
-
export interface ResourceBasedSlotOptions {
|
|
48
|
-
// Amount of slots that will be issued regardless of any other checks
|
|
49
|
-
minimumSlots: number;
|
|
50
|
-
// Maximum amount of slots permitted
|
|
51
|
-
maximumSlots: number;
|
|
52
|
-
// Minimum time we will wait (after passing the minimum slots number) between handing out new
|
|
53
|
-
// slots in milliseconds.
|
|
54
|
-
rampThrottleMs: number;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @experimental
|
|
59
|
-
*/
|
|
60
|
-
type ResourceBasedSlotsForType = ResourceBasedSlotOptions & {
|
|
61
|
-
type: 'resource-based';
|
|
62
|
-
tunerOptions: ResourceBasedTunerOptions;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Options for a {@link ResourceBasedTuner} to control target resource usage
|
|
67
|
-
*
|
|
68
|
-
* @experimental
|
|
69
|
-
*/
|
|
70
|
-
export interface ResourceBasedTunerOptions {
|
|
71
|
-
// A value between 0 and 1 that represents the target (system) memory usage. It's not recommended
|
|
72
|
-
// to set this higher than 0.8, since how much memory a workflow may use is not predictable, and
|
|
73
|
-
// you don't want to encounter OOM errors.
|
|
74
|
-
targetMemoryUsage: number;
|
|
75
|
-
// A value between 0 and 1 that represents the target (system) CPU usage. This can be set to 1.0
|
|
76
|
-
// if desired, but it's recommended to leave some headroom for other processes.
|
|
77
|
-
targetCpuUsage: number;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* A fixed-size slot supplier that will never issue more than a fixed number of slots.
|
|
82
|
-
*
|
|
83
|
-
* @experimental
|
|
84
|
-
*/
|
|
85
|
-
export interface FixedSizeSlotSupplier {
|
|
86
|
-
type: 'fixed-size';
|
|
87
|
-
// The maximum number of slots that can be issued
|
|
88
|
-
numSlots: number;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The interface can be implemented to provide custom slot supplier behavior.
|
|
93
|
-
*/
|
|
94
|
-
export interface CustomSlotSupplier<SI extends SlotInfo> {
|
|
95
|
-
type: 'custom';
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* This function is called before polling for new tasks. Your implementation should block until a
|
|
99
|
-
* slot is available then return a permit to use that slot.
|
|
100
|
-
*
|
|
101
|
-
* The only acceptable exception to throw is AbortError, any other exceptions thrown will be
|
|
102
|
-
* logged and ignored.
|
|
103
|
-
*
|
|
104
|
-
* The value inside the returned promise should be an object, however other types will still count
|
|
105
|
-
* as having issued a permit. Including undefined or null. Returning undefined or null does *not*
|
|
106
|
-
* mean you have not issued a permit. Implementations are expected to block until a meaningful
|
|
107
|
-
* permit can be issued.
|
|
108
|
-
*
|
|
109
|
-
* @param ctx The context for slot reservation.
|
|
110
|
-
* @param abortSignal The SDK may decide to abort the reservation request if it's no longer
|
|
111
|
-
* needed. Implementations may clean up and then must reject the promise with AbortError.
|
|
112
|
-
* @returns A permit to use the slot which may be populated with your own data.
|
|
113
|
-
*/
|
|
114
|
-
reserveSlot(ctx: SlotReserveContext, abortSignal: AbortSignal): Promise<SlotPermit>;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* This function is called when trying to reserve slots for "eager" workflow and activity tasks.
|
|
118
|
-
* Eager tasks are those which are returned as a result of completing a workflow task, rather than
|
|
119
|
-
* from polling. Your implementation must not block, and if a slot is available, return a permit
|
|
120
|
-
* to use that slot.
|
|
121
|
-
*
|
|
122
|
-
* @param ctx The context for slot reservation.
|
|
123
|
-
* @returns Maybe a permit to use the slot which may be populated with your own data.
|
|
124
|
-
*/
|
|
125
|
-
tryReserveSlot(ctx: SlotReserveContext): SlotPermit | null;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* This function is called once a slot is actually being used to process some task, which may be
|
|
129
|
-
* some time after the slot was reserved originally. For example, if there is no work for a
|
|
130
|
-
* worker, a number of slots equal to the number of active pollers may already be reserved, but
|
|
131
|
-
* none of them are being used yet. This call should be non-blocking.
|
|
132
|
-
*
|
|
133
|
-
* @param ctx The context for marking a slot as used.
|
|
134
|
-
*/
|
|
135
|
-
markSlotUsed(slot: SlotMarkUsedContext<SI>): void;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* This function is called once a permit is no longer needed. This could be because the task has
|
|
139
|
-
* finished, whether successfully or not, or because the slot was no longer needed (ex: the number
|
|
140
|
-
* of active pollers decreased). This call should be non-blocking.
|
|
141
|
-
*
|
|
142
|
-
* @param ctx The context for releasing a slot.
|
|
143
|
-
*/
|
|
144
|
-
releaseSlot(slot: SlotReleaseContext<SI>): void;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface SlotPermit {}
|
|
148
|
-
|
|
149
|
-
export interface SlotReserveContext {
|
|
150
|
-
/**
|
|
151
|
-
* The type of slot trying to be reserved
|
|
152
|
-
*/
|
|
153
|
-
slotType: SlotInfo['type'];
|
|
154
|
-
/**
|
|
155
|
-
* The name of the task queue for which this reservation request is associated
|
|
156
|
-
*/
|
|
157
|
-
taskQueue: string;
|
|
158
|
-
/**
|
|
159
|
-
* The identity of the worker that is requesting the reservation
|
|
160
|
-
*/
|
|
161
|
-
workerIdentity: string;
|
|
162
|
-
/**
|
|
163
|
-
* The build id of the worker that is requesting the reservation
|
|
164
|
-
*/
|
|
165
|
-
workerBuildId: string;
|
|
166
|
-
/**
|
|
167
|
-
* True iff this is a reservation for a sticky poll for a workflow task
|
|
168
|
-
*/
|
|
169
|
-
isSticky: boolean;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export interface SlotMarkUsedContext<SI extends SlotInfo> {
|
|
173
|
-
/**
|
|
174
|
-
* Info about the task that will be using the slot
|
|
175
|
-
*/
|
|
176
|
-
slotInfo: SI;
|
|
177
|
-
/**
|
|
178
|
-
* The permit that was issued when the slot was reserved
|
|
179
|
-
*/
|
|
180
|
-
permit: SlotPermit;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface SlotReleaseContext<SI extends SlotInfo> {
|
|
184
|
-
/**
|
|
185
|
-
* Info about the task that used this slot, if any. A slot may be released without being used in
|
|
186
|
-
* the event a poll times out.
|
|
187
|
-
*/
|
|
188
|
-
slotInfo?: SI;
|
|
189
|
-
/**
|
|
190
|
-
* The permit that was issued when the slot was reserved
|
|
191
|
-
*/
|
|
192
|
-
permit: SlotPermit;
|
|
193
|
-
}
|