temporalio 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +175 -4
- data/bridge/Cargo.lock +44 -21
- data/bridge/Cargo.toml +1 -0
- data/bridge/sdk-core/Cargo.toml +1 -1
- data/bridge/sdk-core/README.md +1 -4
- data/bridge/sdk-core/client/Cargo.toml +1 -1
- data/bridge/sdk-core/client/src/lib.rs +12 -20
- data/bridge/sdk-core/client/src/raw.rs +9 -8
- data/bridge/sdk-core/client/src/retry.rs +100 -23
- data/bridge/sdk-core/core/Cargo.toml +7 -7
- data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
- data/bridge/sdk-core/core/src/abstractions.rs +22 -22
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +146 -43
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +419 -9
- data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -89
- data/bridge/sdk-core/core/src/core_tests/workers.rs +2 -2
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +47 -27
- data/bridge/sdk-core/core/src/lib.rs +139 -32
- data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
- data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
- data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +184 -139
- data/bridge/sdk-core/core/src/telemetry/mod.rs +310 -315
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
- data/bridge/sdk-core/core/src/test_help/mod.rs +23 -9
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +12 -6
- data/bridge/sdk-core/core/src/worker/activities.rs +40 -23
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +1 -1
- data/bridge/sdk-core/core/src/worker/client.rs +30 -4
- data/bridge/sdk-core/core/src/worker/mod.rs +23 -19
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +3 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +24 -22
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +233 -217
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +86 -29
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
- data/bridge/sdk-core/core-api/Cargo.toml +4 -3
- data/bridge/sdk-core/core-api/src/lib.rs +1 -43
- data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
- data/bridge/sdk-core/core-api/src/worker.rs +13 -0
- data/bridge/sdk-core/etc/deps.svg +115 -140
- data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
- data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
- data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
- data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
- data/bridge/sdk-core/protos/api_upstream/{temporal/api/update/v1/message.proto → build/tools.go} +6 -23
- data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +20 -19
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +5 -3
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +23 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/{cluster.proto → interaction_type.proto} +10 -11
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +2 -13
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +26 -19
- data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +21 -61
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
- data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -16
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +17 -3
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
- data/bridge/sdk-core/sdk/Cargo.toml +2 -2
- data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
- data/bridge/sdk-core/sdk/src/lib.rs +7 -5
- data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
- data/bridge/sdk-core/sdk/src/workflow_future.rs +3 -7
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +1 -1
- data/bridge/sdk-core/sdk-core-protos/build.rs +0 -1
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +65 -18
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +104 -44
- data/bridge/sdk-core/test-utils/Cargo.toml +2 -1
- data/bridge/sdk-core/test-utils/src/lib.rs +81 -29
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -2
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +167 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
- data/bridge/sdk-core/tests/main.rs +6 -4
- data/bridge/src/connection.rs +81 -62
- data/bridge/src/lib.rs +92 -33
- data/bridge/src/runtime.rs +9 -2
- data/bridge/src/worker.rs +53 -2
- data/lib/bridge.so +0 -0
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
- data/lib/gen/temporal/api/command/v1/message_pb.rb +17 -9
- data/lib/gen/temporal/api/common/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -1
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +3 -2
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +7 -1
- data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
- data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/update_pb.rb +1 -6
- data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
- data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/history/v1/message_pb.rb +19 -18
- data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +11 -51
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
- data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +27 -10
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +1 -0
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +5 -1
- data/lib/temporalio/activity/context.rb +97 -0
- data/lib/temporalio/activity/info.rb +67 -0
- data/lib/temporalio/activity.rb +85 -0
- data/lib/temporalio/bridge/error.rb +8 -0
- data/lib/temporalio/bridge.rb +14 -0
- data/lib/{temporal → temporalio}/client/implementation.rb +49 -48
- data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
- data/lib/{temporal → temporalio}/client.rb +19 -32
- data/lib/{temporal → temporalio}/connection.rb +238 -223
- data/lib/{temporal → temporalio}/data_converter.rb +76 -35
- data/lib/{temporal → temporalio}/error/failure.rb +6 -6
- data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
- data/lib/{temporal → temporalio}/errors.rb +19 -1
- data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
- data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
- data/lib/temporalio/failure_converter.rb +7 -0
- data/lib/{temporal → temporalio}/interceptor/chain.rb +2 -1
- data/lib/{temporal → temporalio}/interceptor/client.rb +22 -1
- data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
- data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
- data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
- data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
- data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
- data/lib/temporalio/payload_converter.rb +14 -0
- data/lib/{temporal → temporalio}/retry_policy.rb +4 -4
- data/lib/{temporal → temporalio}/retry_state.rb +1 -1
- data/lib/temporalio/runtime.rb +25 -0
- data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
- data/lib/temporalio/version.rb +3 -0
- data/lib/temporalio/worker/activity_runner.rb +92 -0
- data/lib/temporalio/worker/activity_worker.rb +138 -0
- data/lib/temporalio/worker/reactor.rb +46 -0
- data/lib/temporalio/worker/runner.rb +63 -0
- data/lib/temporalio/worker/sync_worker.rb +88 -0
- data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
- data/lib/temporalio/worker.rb +198 -0
- data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
- data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
- data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
- data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
- data/lib/temporalio.rb +12 -3
- data/temporalio.gemspec +7 -3
- metadata +79 -56
- data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
- data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
- data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
- data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
- data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
- data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
- data/bridge/sdk-core/core/src/log_export.rs +0 -62
- data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
- data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
- data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
- data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
- data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
- data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
- data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
- data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -26
- data/lib/temporal/bridge.rb +0 -14
- data/lib/temporal/failure_converter.rb +0 -8
- data/lib/temporal/payload_converter.rb +0 -14
- data/lib/temporal/runtime.rb +0 -22
- data/lib/temporal/version.rb +0 -3
- data/lib/temporal.rb +0 -8
@@ -1,825 +0,0 @@
|
|
1
|
-
#![allow(
|
2
|
-
// Non-camel-case types needed since this is exported as a C header and we
|
3
|
-
// want C-like underscores in our type names
|
4
|
-
non_camel_case_types,
|
5
|
-
|
6
|
-
// We choose to have narrow "unsafe" blocks instead of marking entire
|
7
|
-
// functions as unsafe. Even the example in clippy's docs at
|
8
|
-
// https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
|
9
|
-
// cause a rustc warning for unnecessary inner-unsafe when marked on fn.
|
10
|
-
// This check only applies to "pub" functions which are all exposed via C
|
11
|
-
// API.
|
12
|
-
clippy::not_unsafe_ptr_arg_deref,
|
13
|
-
)]
|
14
|
-
|
15
|
-
mod wrappers;
|
16
|
-
|
17
|
-
use bridge::{init_response, CreateWorkerRequest, InitResponse};
|
18
|
-
use prost::Message;
|
19
|
-
use std::sync::Arc;
|
20
|
-
use temporal_sdk_core::{
|
21
|
-
fetch_global_buffered_logs, telemetry_init, Client, ClientOptions, RetryClient,
|
22
|
-
};
|
23
|
-
use temporal_sdk_core_api::Worker;
|
24
|
-
use temporal_sdk_core_protos::coresdk::{
|
25
|
-
bridge,
|
26
|
-
bridge::{CreateClientRequest, InitTelemetryRequest},
|
27
|
-
};
|
28
|
-
|
29
|
-
/// A set of bytes owned by Core. No fields within nor any bytes references must
|
30
|
-
/// ever be mutated outside of Core. This must always be passed to
|
31
|
-
/// tmprl_bytes_free when no longer in use.
|
32
|
-
#[repr(C)]
|
33
|
-
pub struct tmprl_bytes_t {
|
34
|
-
bytes: *const u8,
|
35
|
-
len: libc::size_t,
|
36
|
-
/// For internal use only.
|
37
|
-
cap: libc::size_t,
|
38
|
-
/// For internal use only.
|
39
|
-
disable_free: bool,
|
40
|
-
}
|
41
|
-
|
42
|
-
impl tmprl_bytes_t {
|
43
|
-
fn from_vec(vec: Vec<u8>) -> tmprl_bytes_t {
|
44
|
-
// Mimics Vec::into_raw_parts that's only available in nightly
|
45
|
-
let mut vec = std::mem::ManuallyDrop::new(vec);
|
46
|
-
tmprl_bytes_t {
|
47
|
-
bytes: vec.as_mut_ptr(),
|
48
|
-
len: vec.len(),
|
49
|
-
cap: vec.capacity(),
|
50
|
-
disable_free: false,
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
fn from_vec_disable_free(vec: Vec<u8>) -> tmprl_bytes_t {
|
55
|
-
let mut b = tmprl_bytes_t::from_vec(vec);
|
56
|
-
b.disable_free = true;
|
57
|
-
b
|
58
|
-
}
|
59
|
-
|
60
|
-
fn into_raw(self) -> *mut tmprl_bytes_t {
|
61
|
-
Box::into_raw(Box::new(self))
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
/// Required because these instances are used by lazy_static and raw pointers
|
66
|
-
/// are not usually safe for send/sync.
|
67
|
-
unsafe impl Send for tmprl_bytes_t {}
|
68
|
-
unsafe impl Sync for tmprl_bytes_t {}
|
69
|
-
|
70
|
-
impl Drop for tmprl_bytes_t {
|
71
|
-
fn drop(&mut self) {
|
72
|
-
// In cases where freeing is disabled (or technically some other
|
73
|
-
// drop-but-not-freed situation though we don't expect any), the bytes
|
74
|
-
// remain non-null so we re-own them here
|
75
|
-
if !self.bytes.is_null() {
|
76
|
-
unsafe { Vec::from_raw_parts(self.bytes as *mut u8, self.len, self.cap) };
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
/// Free a set of bytes. The first parameter can be null in cases where a [tmprl_worker_t] instance
|
82
|
-
/// isn't available. If the second parameter is null, this is a no-op.
|
83
|
-
#[no_mangle]
|
84
|
-
pub extern "C" fn tmprl_bytes_free(worker: *mut tmprl_worker_t, bytes: *const tmprl_bytes_t) {
|
85
|
-
// Bail if freeing is disabled
|
86
|
-
unsafe {
|
87
|
-
if bytes.is_null() || (*bytes).disable_free {
|
88
|
-
return;
|
89
|
-
}
|
90
|
-
}
|
91
|
-
let bytes = bytes as *mut tmprl_bytes_t;
|
92
|
-
// Return vec back to core before dropping bytes
|
93
|
-
let vec = unsafe { Vec::from_raw_parts((*bytes).bytes as *mut u8, (*bytes).len, (*bytes).cap) };
|
94
|
-
// Set to null so the byte dropper doesn't try to free it
|
95
|
-
unsafe { (*bytes).bytes = std::ptr::null_mut() };
|
96
|
-
// Return only if worker is non-null
|
97
|
-
if !worker.is_null() {
|
98
|
-
let worker = unsafe { &mut *worker };
|
99
|
-
worker.return_buf(vec);
|
100
|
-
}
|
101
|
-
unsafe {
|
102
|
-
let _ = Box::from_raw(bytes);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
/// Used for maintaining pointer to user data across threads. See
|
107
|
-
/// https://doc.rust-lang.org/nomicon/send-and-sync.html.
|
108
|
-
struct UserDataHandle(*mut libc::c_void);
|
109
|
-
unsafe impl Send for UserDataHandle {}
|
110
|
-
unsafe impl Sync for UserDataHandle {}
|
111
|
-
|
112
|
-
impl From<UserDataHandle> for *mut libc::c_void {
|
113
|
-
fn from(v: UserDataHandle) -> Self {
|
114
|
-
v.0
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
lazy_static::lazy_static! {
|
119
|
-
static ref DEFAULT_INIT_RESPONSE_BYTES: tmprl_bytes_t = {
|
120
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::InitResponse::default().encode_to_vec())
|
121
|
-
};
|
122
|
-
|
123
|
-
static ref DEFAULT_REGISTER_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
|
124
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::RegisterWorkerResponse::default().encode_to_vec())
|
125
|
-
};
|
126
|
-
|
127
|
-
static ref DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
|
128
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::ShutdownWorkerResponse::default().encode_to_vec())
|
129
|
-
};
|
130
|
-
|
131
|
-
static ref DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES: tmprl_bytes_t = {
|
132
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::CompleteWorkflowActivationResponse::default().encode_to_vec())
|
133
|
-
};
|
134
|
-
|
135
|
-
static ref DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES: tmprl_bytes_t = {
|
136
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::CompleteActivityTaskResponse::default().encode_to_vec())
|
137
|
-
};
|
138
|
-
|
139
|
-
static ref DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES: tmprl_bytes_t = {
|
140
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::RecordActivityHeartbeatResponse::default().encode_to_vec())
|
141
|
-
};
|
142
|
-
|
143
|
-
static ref DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES: tmprl_bytes_t = {
|
144
|
-
tmprl_bytes_t::from_vec_disable_free(bridge::RequestWorkflowEvictionResponse::default().encode_to_vec())
|
145
|
-
};
|
146
|
-
}
|
147
|
-
|
148
|
-
/// A runtime owned by Core. This must be passed to [tmprl_runtime_free] when no longer in use. This
|
149
|
-
/// should not be freed until every call to every [tmprl_worker_t] instance created with this
|
150
|
-
/// runtime has been shutdown. In practice, since the actual runtime is behind an [Arc], it's
|
151
|
-
/// currently OK, but that's an implementation detail.
|
152
|
-
pub struct tmprl_runtime_t {
|
153
|
-
// This is the same runtime shared with worker instances
|
154
|
-
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
155
|
-
}
|
156
|
-
|
157
|
-
/// Create a new runtime. The result is never null and must be freed via
|
158
|
-
/// tmprl_runtime_free when no longer in use.
|
159
|
-
#[no_mangle]
|
160
|
-
pub extern "C" fn tmprl_runtime_new() -> *mut tmprl_runtime_t {
|
161
|
-
Box::into_raw(Box::new(tmprl_runtime_t {
|
162
|
-
// TODO(cretz): Options to configure thread pool?
|
163
|
-
tokio_runtime: Arc::new(
|
164
|
-
tokio::runtime::Builder::new_multi_thread()
|
165
|
-
.enable_all()
|
166
|
-
.build()
|
167
|
-
.unwrap(),
|
168
|
-
),
|
169
|
-
}))
|
170
|
-
}
|
171
|
-
|
172
|
-
/// Free a previously created runtime.
|
173
|
-
#[no_mangle]
|
174
|
-
pub extern "C" fn tmprl_runtime_free(runtime: *mut tmprl_runtime_t) {
|
175
|
-
if !runtime.is_null() {
|
176
|
-
unsafe {
|
177
|
-
let _ = Box::from_raw(runtime);
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
|
182
|
-
/// A worker instance owned by Core. This must be passed to [tmprl_worker_shutdown]
|
183
|
-
/// when no longer in use which will free the resources.
|
184
|
-
pub struct tmprl_worker_t {
|
185
|
-
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
186
|
-
// We are not concerned with the overhead of dynamic dispatch at this time
|
187
|
-
worker: Arc<dyn Worker>,
|
188
|
-
}
|
189
|
-
|
190
|
-
/// Callback called by [tmprl_worker_init] on completion. The first parameter of the
|
191
|
-
/// callback is user data passed into the original function. The second
|
192
|
-
/// parameter is a worker instance if the call is successful or null if not. If
|
193
|
-
/// present, the worker instance must be freed via [tmprl_worker_shutdown] when no
|
194
|
-
/// longer in use. The third parameter of the callback is a byte array for a
|
195
|
-
/// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
|
196
|
-
type tmprl_worker_init_callback = unsafe extern "C" fn(
|
197
|
-
user_data: *mut libc::c_void,
|
198
|
-
worker: *mut tmprl_worker_t,
|
199
|
-
resp: *const tmprl_bytes_t,
|
200
|
-
);
|
201
|
-
|
202
|
-
/// Callback called on function completion. The first parameter of the callback
|
203
|
-
/// is user data passed into the original function. The second parameter of the
|
204
|
-
/// callback is a never-null byte array for a response protobuf message which
|
205
|
-
/// must be freed via [tmprl_bytes_free].
|
206
|
-
type tmprl_callback =
|
207
|
-
unsafe extern "C" fn(user_data: *mut libc::c_void, core: *const tmprl_bytes_t);
|
208
|
-
|
209
|
-
/// Create a new worker instance.
|
210
|
-
///
|
211
|
-
/// `runtime` and `client` are both required and must outlive this instance.
|
212
|
-
/// `req_proto` and `req_proto_len` represent a byte array for a [CreateWorkerRequest] protobuf
|
213
|
-
/// message.
|
214
|
-
/// The callback is invoked on completion.
|
215
|
-
#[no_mangle]
|
216
|
-
pub extern "C" fn tmprl_worker_init(
|
217
|
-
runtime: *mut tmprl_runtime_t,
|
218
|
-
client: *mut tmprl_client_t,
|
219
|
-
req_proto: *const u8,
|
220
|
-
req_proto_len: libc::size_t,
|
221
|
-
user_data: *mut libc::c_void,
|
222
|
-
callback: tmprl_worker_init_callback,
|
223
|
-
) {
|
224
|
-
let (runtime, client) = unsafe { (&*runtime, &*client) };
|
225
|
-
let req = match tmprl_worker_t::decode_proto::<CreateWorkerRequest>(req_proto, req_proto_len) {
|
226
|
-
Ok(req) => req,
|
227
|
-
Err(message) => {
|
228
|
-
let resp = InitResponse {
|
229
|
-
error: Some(init_response::Error { message }),
|
230
|
-
};
|
231
|
-
unsafe {
|
232
|
-
callback(
|
233
|
-
user_data,
|
234
|
-
std::ptr::null_mut(),
|
235
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
236
|
-
);
|
237
|
-
}
|
238
|
-
return;
|
239
|
-
}
|
240
|
-
};
|
241
|
-
let user_data = UserDataHandle(user_data);
|
242
|
-
match tmprl_worker_t::new(
|
243
|
-
runtime.tokio_runtime.clone(),
|
244
|
-
client.client.clone(),
|
245
|
-
wrappers::WorkerConfig(req),
|
246
|
-
) {
|
247
|
-
Ok(worker) => unsafe {
|
248
|
-
callback(
|
249
|
-
user_data.into(),
|
250
|
-
Box::into_raw(Box::new(worker)),
|
251
|
-
&*DEFAULT_INIT_RESPONSE_BYTES,
|
252
|
-
);
|
253
|
-
},
|
254
|
-
Err(message) => {
|
255
|
-
let resp = InitResponse {
|
256
|
-
error: Some(init_response::Error { message }),
|
257
|
-
};
|
258
|
-
unsafe {
|
259
|
-
callback(
|
260
|
-
user_data.into(),
|
261
|
-
std::ptr::null_mut(),
|
262
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
263
|
-
);
|
264
|
-
}
|
265
|
-
}
|
266
|
-
};
|
267
|
-
}
|
268
|
-
|
269
|
-
/// Shutdown and free a previously created worker.
|
270
|
-
///
|
271
|
-
/// The req_proto and req_proto_len represent a byte array for a [bridge::ShutdownWorkerRequest]
|
272
|
-
/// protobuf message, which currently contains nothing and are unused, but the parameters are kept
|
273
|
-
/// for now.
|
274
|
-
///
|
275
|
-
/// The callback is invoked on completion with a ShutdownWorkerResponse protobuf message.
|
276
|
-
///
|
277
|
-
/// After the callback has been called, the worker struct will be freed and the pointer will no
|
278
|
-
/// longer be valid.
|
279
|
-
#[no_mangle]
|
280
|
-
pub extern "C" fn tmprl_worker_shutdown(
|
281
|
-
worker: *mut tmprl_worker_t,
|
282
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
283
|
-
req_proto: *const u8,
|
284
|
-
#[allow(unused_variables)] req_proto_len: libc::size_t,
|
285
|
-
user_data: *mut libc::c_void,
|
286
|
-
callback: tmprl_callback,
|
287
|
-
) {
|
288
|
-
let worker = unsafe { Box::from_raw(worker) };
|
289
|
-
let user_data = UserDataHandle(user_data);
|
290
|
-
worker.tokio_runtime.clone().spawn(async move {
|
291
|
-
worker.shutdown().await;
|
292
|
-
unsafe {
|
293
|
-
callback(user_data.into(), &*DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES);
|
294
|
-
}
|
295
|
-
drop(worker);
|
296
|
-
});
|
297
|
-
}
|
298
|
-
|
299
|
-
/// Initialize process-wide telemetry. Should only be called once, subsequent calls will be ignored
|
300
|
-
/// by core.
|
301
|
-
///
|
302
|
-
/// Unlike the other functions in this bridge, this blocks until initting is complete, as telemetry
|
303
|
-
/// should typically be initialized before doing other work.
|
304
|
-
///
|
305
|
-
/// Returns a byte array for a [InitResponse] protobuf message which must be freed via
|
306
|
-
/// tmprl_bytes_free.
|
307
|
-
#[no_mangle]
|
308
|
-
pub extern "C" fn tmprl_telemetry_init(
|
309
|
-
req_proto: *const u8,
|
310
|
-
req_proto_len: libc::size_t,
|
311
|
-
) -> *const tmprl_bytes_t {
|
312
|
-
let req = match tmprl_worker_t::decode_proto::<InitTelemetryRequest>(req_proto, req_proto_len) {
|
313
|
-
Ok(req) => req,
|
314
|
-
Err(message) => {
|
315
|
-
let resp = InitResponse {
|
316
|
-
error: Some(init_response::Error { message }),
|
317
|
-
};
|
318
|
-
return tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw();
|
319
|
-
}
|
320
|
-
};
|
321
|
-
|
322
|
-
match wrappers::InitTelemetryRequest(req)
|
323
|
-
.try_into()
|
324
|
-
.map(|opts| telemetry_init(&opts))
|
325
|
-
{
|
326
|
-
Ok(_) => &*DEFAULT_INIT_RESPONSE_BYTES,
|
327
|
-
Err(message) => {
|
328
|
-
let resp = InitResponse {
|
329
|
-
error: Some(init_response::Error { message }),
|
330
|
-
};
|
331
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw()
|
332
|
-
}
|
333
|
-
}
|
334
|
-
}
|
335
|
-
|
336
|
-
/// A client instance owned by Core. This must be passed to [tmprl_client_free]
|
337
|
-
/// when no longer in use which will free the resources.
|
338
|
-
pub struct tmprl_client_t {
|
339
|
-
client: Arc<RetryClient<Client>>,
|
340
|
-
}
|
341
|
-
|
342
|
-
impl tmprl_client_t {
|
343
|
-
pub fn new(client: Arc<RetryClient<Client>>) -> Self {
|
344
|
-
Self { client }
|
345
|
-
}
|
346
|
-
}
|
347
|
-
|
348
|
-
/// Callback called by [tmprl_client_init] on completion. The first parameter of the
|
349
|
-
/// callback is user data passed into the original function. The second
|
350
|
-
/// parameter is a client instance if the call is successful or null if not. If
|
351
|
-
/// present, the client instance must be freed via [tmprl_client_free] when no
|
352
|
-
/// longer in use. The third parameter of the callback is a byte array for a
|
353
|
-
/// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
|
354
|
-
type tmprl_client_init_callback = unsafe extern "C" fn(
|
355
|
-
user_data: *mut libc::c_void,
|
356
|
-
client: *mut tmprl_client_t,
|
357
|
-
resp: *const tmprl_bytes_t,
|
358
|
-
);
|
359
|
-
|
360
|
-
/// Initialize a client connection to the Temporal service.
|
361
|
-
///
|
362
|
-
/// The runtime is required and must outlive this instance. The `req_proto` and `req_proto_len`
|
363
|
-
/// represent a byte array for a [CreateClientRequest] protobuf message. The callback is invoked on
|
364
|
-
/// completion.
|
365
|
-
#[no_mangle]
|
366
|
-
pub extern "C" fn tmprl_client_init(
|
367
|
-
runtime: *mut tmprl_runtime_t,
|
368
|
-
req_proto: *const u8,
|
369
|
-
req_proto_len: libc::size_t,
|
370
|
-
user_data: *mut libc::c_void,
|
371
|
-
callback: tmprl_client_init_callback,
|
372
|
-
) {
|
373
|
-
let runtime = unsafe { &*runtime };
|
374
|
-
let (namespace, req) =
|
375
|
-
match tmprl_worker_t::decode_proto::<CreateClientRequest>(req_proto, req_proto_len)
|
376
|
-
.and_then(|cgr| {
|
377
|
-
let ns = cgr.namespace.clone();
|
378
|
-
wrappers::ClientOptions(cgr)
|
379
|
-
.try_into()
|
380
|
-
.map(|sgo: ClientOptions| (ns, sgo))
|
381
|
-
}) {
|
382
|
-
Ok(req) => req,
|
383
|
-
Err(message) => {
|
384
|
-
let resp = InitResponse {
|
385
|
-
error: Some(init_response::Error { message }),
|
386
|
-
};
|
387
|
-
unsafe {
|
388
|
-
callback(
|
389
|
-
user_data,
|
390
|
-
std::ptr::null_mut(),
|
391
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
392
|
-
);
|
393
|
-
}
|
394
|
-
return;
|
395
|
-
}
|
396
|
-
};
|
397
|
-
|
398
|
-
let user_data = UserDataHandle(user_data);
|
399
|
-
runtime.tokio_runtime.spawn(async move {
|
400
|
-
match req.connect(namespace, None, None).await {
|
401
|
-
Ok(client) => unsafe {
|
402
|
-
callback(
|
403
|
-
user_data.into(),
|
404
|
-
Box::into_raw(Box::new(tmprl_client_t::new(Arc::new(client)))),
|
405
|
-
&*DEFAULT_INIT_RESPONSE_BYTES,
|
406
|
-
);
|
407
|
-
},
|
408
|
-
Err(e) => {
|
409
|
-
let resp = InitResponse {
|
410
|
-
error: Some(init_response::Error {
|
411
|
-
message: e.to_string(),
|
412
|
-
}),
|
413
|
-
};
|
414
|
-
unsafe {
|
415
|
-
callback(
|
416
|
-
user_data.into(),
|
417
|
-
std::ptr::null_mut(),
|
418
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
419
|
-
);
|
420
|
-
}
|
421
|
-
}
|
422
|
-
}
|
423
|
-
});
|
424
|
-
}
|
425
|
-
|
426
|
-
/// Free a previously created client
|
427
|
-
#[no_mangle]
|
428
|
-
pub extern "C" fn tmprl_client_free(client: *mut tmprl_client_t) {
|
429
|
-
unsafe { drop(Box::from_raw(client)) };
|
430
|
-
}
|
431
|
-
|
432
|
-
/// Poll for a workflow activation.
|
433
|
-
///
|
434
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
435
|
-
/// [bridge::PollWorkflowActivationRequest] protobuf message, which currently contains nothing and
|
436
|
-
/// is unused, but the parameters are kept for now.
|
437
|
-
///
|
438
|
-
/// The callback is invoked on completion with a [bridge::PollWorkflowActivationResponse] protobuf
|
439
|
-
/// message.
|
440
|
-
#[no_mangle]
|
441
|
-
pub extern "C" fn tmprl_poll_workflow_activation(
|
442
|
-
worker: *mut tmprl_worker_t,
|
443
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
444
|
-
req_proto: *const u8,
|
445
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
446
|
-
req_proto_len: libc::size_t,
|
447
|
-
user_data: *mut libc::c_void,
|
448
|
-
callback: tmprl_callback,
|
449
|
-
) {
|
450
|
-
let worker = unsafe { &mut *worker };
|
451
|
-
let user_data = UserDataHandle(user_data);
|
452
|
-
worker.tokio_runtime.clone().spawn(async move {
|
453
|
-
let resp = bridge::PollWorkflowActivationResponse {
|
454
|
-
response: Some(match worker.poll_workflow_activation().await {
|
455
|
-
Ok(act) => bridge::poll_workflow_activation_response::Response::Activation(act),
|
456
|
-
Err(err) => bridge::poll_workflow_activation_response::Response::Error(err),
|
457
|
-
}),
|
458
|
-
};
|
459
|
-
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
460
|
-
});
|
461
|
-
}
|
462
|
-
|
463
|
-
/// Poll for an activity task.
|
464
|
-
///
|
465
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
466
|
-
/// [bridge::PollActivityTaskRequest] protobuf message, which currently contains nothing and is
|
467
|
-
/// unused, but the parameters are kept for now.
|
468
|
-
///
|
469
|
-
/// The callback is invoked on completion with a [bridge::PollActivityTaskResponse] protobuf
|
470
|
-
/// message.
|
471
|
-
#[no_mangle]
|
472
|
-
pub extern "C" fn tmprl_poll_activity_task(
|
473
|
-
worker: *mut tmprl_worker_t,
|
474
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
475
|
-
req_proto: *const u8,
|
476
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
477
|
-
req_proto_len: libc::size_t,
|
478
|
-
user_data: *mut libc::c_void,
|
479
|
-
callback: tmprl_callback,
|
480
|
-
) {
|
481
|
-
let worker = unsafe { &mut *worker };
|
482
|
-
let user_data = UserDataHandle(user_data);
|
483
|
-
worker.tokio_runtime.clone().spawn(async move {
|
484
|
-
let resp = bridge::PollActivityTaskResponse {
|
485
|
-
response: Some(match worker.poll_activity_task().await {
|
486
|
-
Ok(task) => bridge::poll_activity_task_response::Response::Task(task),
|
487
|
-
Err(err) => bridge::poll_activity_task_response::Response::Error(err),
|
488
|
-
}),
|
489
|
-
};
|
490
|
-
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
491
|
-
});
|
492
|
-
}
|
493
|
-
|
494
|
-
/// Complete a workflow activation.
|
495
|
-
///
|
496
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
497
|
-
/// [bridge::CompleteWorkflowActivationRequest] protobuf message. The callback is invoked on
|
498
|
-
/// completion with a [bridge::CompleteWorkflowActivationResponse] protobuf message.
|
499
|
-
#[no_mangle]
|
500
|
-
pub extern "C" fn tmprl_complete_workflow_activation(
|
501
|
-
worker: *mut tmprl_worker_t,
|
502
|
-
req_proto: *const u8,
|
503
|
-
req_proto_len: libc::size_t,
|
504
|
-
user_data: *mut libc::c_void,
|
505
|
-
callback: tmprl_callback,
|
506
|
-
) {
|
507
|
-
let worker = unsafe { &mut *worker };
|
508
|
-
let req = match tmprl_worker_t::decode_proto::<bridge::CompleteWorkflowActivationRequest>(
|
509
|
-
req_proto,
|
510
|
-
req_proto_len,
|
511
|
-
) {
|
512
|
-
Ok(req) => req,
|
513
|
-
Err(message) => {
|
514
|
-
let resp = bridge::CompleteWorkflowActivationResponse {
|
515
|
-
error: Some(bridge::complete_workflow_activation_response::Error { message }),
|
516
|
-
};
|
517
|
-
unsafe {
|
518
|
-
callback(user_data, worker.encode_proto(&resp).into_raw());
|
519
|
-
}
|
520
|
-
return;
|
521
|
-
}
|
522
|
-
};
|
523
|
-
let user_data = UserDataHandle(user_data);
|
524
|
-
worker.tokio_runtime.clone().spawn(async move {
|
525
|
-
match worker.complete_workflow_activation(req).await {
|
526
|
-
Ok(()) => unsafe {
|
527
|
-
callback(
|
528
|
-
user_data.into(),
|
529
|
-
&*DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES,
|
530
|
-
);
|
531
|
-
},
|
532
|
-
Err(err) => {
|
533
|
-
let resp = bridge::CompleteWorkflowActivationResponse { error: Some(err) };
|
534
|
-
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
535
|
-
}
|
536
|
-
}
|
537
|
-
});
|
538
|
-
}
|
539
|
-
|
540
|
-
/// Complete an activity task.
|
541
|
-
///
|
542
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
543
|
-
/// [bridge::CompleteActivityTaskRequest] protobuf message. The callback is invoked on completion
|
544
|
-
/// with a [bridge::CompleteActivityTaskResponse] protobuf message.
|
545
|
-
#[no_mangle]
|
546
|
-
pub extern "C" fn tmprl_complete_activity_task(
|
547
|
-
worker: *mut tmprl_worker_t,
|
548
|
-
req_proto: *const u8,
|
549
|
-
req_proto_len: libc::size_t,
|
550
|
-
user_data: *mut libc::c_void,
|
551
|
-
callback: tmprl_callback,
|
552
|
-
) {
|
553
|
-
let worker = unsafe { &mut *worker };
|
554
|
-
let req = match tmprl_worker_t::decode_proto::<bridge::CompleteActivityTaskRequest>(
|
555
|
-
req_proto,
|
556
|
-
req_proto_len,
|
557
|
-
) {
|
558
|
-
Ok(req) => req,
|
559
|
-
Err(message) => {
|
560
|
-
let resp = bridge::CompleteActivityTaskResponse {
|
561
|
-
error: Some(bridge::complete_activity_task_response::Error { message }),
|
562
|
-
};
|
563
|
-
unsafe {
|
564
|
-
callback(user_data, worker.encode_proto(&resp).into_raw());
|
565
|
-
}
|
566
|
-
return;
|
567
|
-
}
|
568
|
-
};
|
569
|
-
let user_data = UserDataHandle(user_data);
|
570
|
-
worker.tokio_runtime.clone().spawn(async move {
|
571
|
-
match worker.complete_activity_task(req).await {
|
572
|
-
Ok(()) => unsafe {
|
573
|
-
callback(
|
574
|
-
user_data.into(),
|
575
|
-
&*DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES,
|
576
|
-
);
|
577
|
-
},
|
578
|
-
Err(err) => {
|
579
|
-
let resp = bridge::CompleteActivityTaskResponse { error: Some(err) };
|
580
|
-
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
581
|
-
}
|
582
|
-
}
|
583
|
-
});
|
584
|
-
}
|
585
|
-
|
586
|
-
/// Record an activity heartbeat.
|
587
|
-
///
|
588
|
-
/// `req_proto` and `req_proto_len` represent a byte array for a
|
589
|
-
/// [bridge::RecordActivityHeartbeatRequest] protobuf message. The callback is invoked on completion
|
590
|
-
/// with a RecordActivityHeartbeatResponse protobuf message.
|
591
|
-
#[no_mangle]
|
592
|
-
pub extern "C" fn tmprl_record_activity_heartbeat(
|
593
|
-
worker: *mut tmprl_worker_t,
|
594
|
-
req_proto: *const u8,
|
595
|
-
req_proto_len: libc::size_t,
|
596
|
-
user_data: *mut libc::c_void,
|
597
|
-
callback: tmprl_callback,
|
598
|
-
) {
|
599
|
-
let worker = unsafe { &mut *worker };
|
600
|
-
let req = match tmprl_worker_t::decode_proto::<bridge::RecordActivityHeartbeatRequest>(
|
601
|
-
req_proto,
|
602
|
-
req_proto_len,
|
603
|
-
) {
|
604
|
-
Ok(req) => req,
|
605
|
-
Err(message) => {
|
606
|
-
let resp = bridge::RecordActivityHeartbeatResponse {
|
607
|
-
error: Some(bridge::record_activity_heartbeat_response::Error { message }),
|
608
|
-
};
|
609
|
-
unsafe {
|
610
|
-
callback(user_data, worker.encode_proto(&resp).into_raw());
|
611
|
-
}
|
612
|
-
return;
|
613
|
-
}
|
614
|
-
};
|
615
|
-
let user_data = UserDataHandle(user_data);
|
616
|
-
// We intentionally spawn even though the core call is not async so the
|
617
|
-
// callback can be made in the tokio runtime
|
618
|
-
worker.tokio_runtime.clone().spawn(async move {
|
619
|
-
worker.record_activity_heartbeat(req);
|
620
|
-
unsafe {
|
621
|
-
callback(
|
622
|
-
user_data.into(),
|
623
|
-
&*DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES,
|
624
|
-
);
|
625
|
-
}
|
626
|
-
});
|
627
|
-
}
|
628
|
-
|
629
|
-
/// Request a workflow eviction.
|
630
|
-
///
|
631
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
632
|
-
/// [bridge::RequestWorkflowEvictionRequest] protobuf message. The callback is invoked on completion
|
633
|
-
/// with a [bridge::RequestWorkflowEvictionResponse] protobuf message.
|
634
|
-
#[no_mangle]
|
635
|
-
pub extern "C" fn tmprl_request_workflow_eviction(
|
636
|
-
worker: *mut tmprl_worker_t,
|
637
|
-
req_proto: *const u8,
|
638
|
-
req_proto_len: libc::size_t,
|
639
|
-
user_data: *mut libc::c_void,
|
640
|
-
callback: tmprl_callback,
|
641
|
-
) {
|
642
|
-
let worker = unsafe { &mut *worker };
|
643
|
-
let req = match tmprl_worker_t::decode_proto::<bridge::RequestWorkflowEvictionRequest>(
|
644
|
-
req_proto,
|
645
|
-
req_proto_len,
|
646
|
-
) {
|
647
|
-
Ok(req) => req,
|
648
|
-
Err(message) => {
|
649
|
-
let resp = bridge::RequestWorkflowEvictionResponse {
|
650
|
-
error: Some(bridge::request_workflow_eviction_response::Error { message }),
|
651
|
-
};
|
652
|
-
unsafe {
|
653
|
-
callback(user_data, worker.encode_proto(&resp).into_raw());
|
654
|
-
}
|
655
|
-
return;
|
656
|
-
}
|
657
|
-
};
|
658
|
-
let user_data = UserDataHandle(user_data);
|
659
|
-
// We intentionally spawn even though the core call is not async so the
|
660
|
-
// callback can be made in the tokio runtime
|
661
|
-
worker.tokio_runtime.clone().spawn(async move {
|
662
|
-
worker.request_workflow_eviction(req);
|
663
|
-
unsafe {
|
664
|
-
callback(
|
665
|
-
user_data.into(),
|
666
|
-
&*DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES,
|
667
|
-
);
|
668
|
-
}
|
669
|
-
});
|
670
|
-
}
|
671
|
-
|
672
|
-
/// Fetch buffered logs. Blocks until complete. This is still using the callback since we might
|
673
|
-
/// reasonably change log fetching to be async in the future.
|
674
|
-
///
|
675
|
-
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
676
|
-
/// [bridge::FetchBufferedLogsRequest] protobuf message. The callback is invoked on completion with
|
677
|
-
/// a [bridge::FetchBufferedLogsResponse] protobuf message.
|
678
|
-
#[no_mangle]
|
679
|
-
pub extern "C" fn tmprl_fetch_buffered_logs(
|
680
|
-
#[allow(unused_variables)] // We intentionally ignore the request
|
681
|
-
req_proto: *const u8,
|
682
|
-
#[allow(unused_variables)] req_proto_len: libc::size_t,
|
683
|
-
user_data: *mut libc::c_void,
|
684
|
-
callback: tmprl_callback,
|
685
|
-
) {
|
686
|
-
let user_data = UserDataHandle(user_data);
|
687
|
-
// We intentionally spawn even though the core call is not async so the
|
688
|
-
// callback can be made in the tokio runtime
|
689
|
-
let resp = bridge::FetchBufferedLogsResponse {
|
690
|
-
entries: fetch_global_buffered_logs()
|
691
|
-
.into_iter()
|
692
|
-
.map(|log| bridge::fetch_buffered_logs_response::LogEntry {
|
693
|
-
message: log.message,
|
694
|
-
timestamp: Some(log.timestamp.into()),
|
695
|
-
level: match log.level {
|
696
|
-
log::Level::Error => bridge::LogLevel::Error.into(),
|
697
|
-
log::Level::Warn => bridge::LogLevel::Warn.into(),
|
698
|
-
log::Level::Info => bridge::LogLevel::Info.into(),
|
699
|
-
log::Level::Debug => bridge::LogLevel::Debug.into(),
|
700
|
-
log::Level::Trace => bridge::LogLevel::Trace.into(),
|
701
|
-
},
|
702
|
-
})
|
703
|
-
.collect(),
|
704
|
-
};
|
705
|
-
|
706
|
-
unsafe {
|
707
|
-
callback(
|
708
|
-
user_data.into(),
|
709
|
-
// TODO: Creates vec every time since no worker/core instance. Can be fixed with a
|
710
|
-
// pool if optimizations needed.
|
711
|
-
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
712
|
-
)
|
713
|
-
};
|
714
|
-
}
|
715
|
-
|
716
|
-
impl tmprl_worker_t {
|
717
|
-
fn new(
|
718
|
-
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
719
|
-
client: Arc<RetryClient<Client>>,
|
720
|
-
opts: wrappers::WorkerConfig,
|
721
|
-
) -> Result<tmprl_worker_t, String> {
|
722
|
-
Ok(tmprl_worker_t {
|
723
|
-
tokio_runtime,
|
724
|
-
worker: Arc::new(temporal_sdk_core::init_worker(opts.try_into()?, client)),
|
725
|
-
})
|
726
|
-
}
|
727
|
-
|
728
|
-
async fn shutdown(&self) {
|
729
|
-
self.worker.shutdown().await;
|
730
|
-
}
|
731
|
-
|
732
|
-
async fn poll_workflow_activation(
|
733
|
-
&self,
|
734
|
-
) -> Result<
|
735
|
-
temporal_sdk_core_protos::coresdk::workflow_activation::WorkflowActivation,
|
736
|
-
bridge::poll_workflow_activation_response::Error,
|
737
|
-
> {
|
738
|
-
self.worker.poll_workflow_activation().await.map_err(|err| {
|
739
|
-
bridge::poll_workflow_activation_response::Error {
|
740
|
-
message: format!("{}", err),
|
741
|
-
shutdown: matches!(err, temporal_sdk_core_api::errors::PollWfError::ShutDown),
|
742
|
-
}
|
743
|
-
})
|
744
|
-
}
|
745
|
-
|
746
|
-
async fn poll_activity_task(
|
747
|
-
&self,
|
748
|
-
) -> Result<
|
749
|
-
temporal_sdk_core_protos::coresdk::activity_task::ActivityTask,
|
750
|
-
bridge::poll_activity_task_response::Error,
|
751
|
-
> {
|
752
|
-
self.worker.poll_activity_task().await.map_err(|err| {
|
753
|
-
bridge::poll_activity_task_response::Error {
|
754
|
-
message: format!("{}", err),
|
755
|
-
shutdown: matches!(
|
756
|
-
err,
|
757
|
-
temporal_sdk_core_api::errors::PollActivityError::ShutDown
|
758
|
-
),
|
759
|
-
}
|
760
|
-
})
|
761
|
-
}
|
762
|
-
|
763
|
-
async fn complete_workflow_activation(
|
764
|
-
&self,
|
765
|
-
req: bridge::CompleteWorkflowActivationRequest,
|
766
|
-
) -> Result<(), bridge::complete_workflow_activation_response::Error> {
|
767
|
-
self.worker
|
768
|
-
.complete_workflow_activation(req.completion.unwrap_or_default())
|
769
|
-
.await
|
770
|
-
.map_err(|err| bridge::complete_workflow_activation_response::Error {
|
771
|
-
message: format!("{}", err),
|
772
|
-
})
|
773
|
-
}
|
774
|
-
|
775
|
-
async fn complete_activity_task(
|
776
|
-
&self,
|
777
|
-
req: bridge::CompleteActivityTaskRequest,
|
778
|
-
) -> Result<(), bridge::complete_activity_task_response::Error> {
|
779
|
-
self.worker
|
780
|
-
.complete_activity_task(req.completion.unwrap_or_default())
|
781
|
-
.await
|
782
|
-
.map_err(|err| bridge::complete_activity_task_response::Error {
|
783
|
-
message: format!("{}", err),
|
784
|
-
})
|
785
|
-
}
|
786
|
-
|
787
|
-
fn record_activity_heartbeat(&self, req: bridge::RecordActivityHeartbeatRequest) {
|
788
|
-
self.worker
|
789
|
-
.record_activity_heartbeat(req.heartbeat.unwrap_or_default());
|
790
|
-
}
|
791
|
-
|
792
|
-
fn request_workflow_eviction(&self, req: bridge::RequestWorkflowEvictionRequest) {
|
793
|
-
self.worker.request_workflow_eviction(&req.run_id);
|
794
|
-
}
|
795
|
-
|
796
|
-
fn borrow_buf(&mut self) -> Vec<u8> {
|
797
|
-
// We currently do not use a thread-safe byte pool, but if wanted, it
|
798
|
-
// can be added here
|
799
|
-
Vec::new()
|
800
|
-
}
|
801
|
-
|
802
|
-
fn return_buf(&mut self, _vec: Vec<u8>) {
|
803
|
-
// We currently do not use a thread-safe byte pool, but if wanted, it
|
804
|
-
// can be added here
|
805
|
-
}
|
806
|
-
|
807
|
-
fn encode_proto(&mut self, proto: &impl prost::Message) -> tmprl_bytes_t {
|
808
|
-
let mut buf = self.borrow_buf();
|
809
|
-
buf.clear();
|
810
|
-
// Increase buf capacity if needed
|
811
|
-
buf.reserve(proto.encoded_len());
|
812
|
-
// Only fails if size not big enough which can't happen in our case
|
813
|
-
proto.encode(&mut buf).unwrap();
|
814
|
-
tmprl_bytes_t::from_vec(buf)
|
815
|
-
}
|
816
|
-
|
817
|
-
fn decode_proto<P>(bytes: *const u8, bytes_len: libc::size_t) -> Result<P, String>
|
818
|
-
where
|
819
|
-
P: prost::Message,
|
820
|
-
P: Default,
|
821
|
-
{
|
822
|
-
P::decode(unsafe { std::slice::from_raw_parts(bytes, bytes_len) })
|
823
|
-
.map_err(|err| format!("failed decoding proto: {}", err))
|
824
|
-
}
|
825
|
-
}
|