@temporalio/core-bridge 1.15.0 → 1.16.1
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 +172 -70
- package/lib/native.d.ts +1 -1
- package/package.json +2 -2
- 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/.github/workflows/per-pr.yml +6 -6
- package/sdk-core/AGENTS.md +41 -30
- package/sdk-core/Cargo.toml +3 -0
- package/sdk-core/README.md +15 -9
- package/sdk-core/crates/client/Cargo.toml +4 -0
- package/sdk-core/crates/client/README.md +139 -0
- package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
- package/sdk-core/crates/client/src/callback_based.rs +7 -0
- package/sdk-core/crates/client/src/errors.rs +294 -0
- package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +280 -159
- package/sdk-core/crates/client/src/lib.rs +920 -1326
- package/sdk-core/crates/client/src/metrics.rs +24 -33
- package/sdk-core/crates/client/src/options_structs.rs +457 -0
- package/sdk-core/crates/client/src/replaceable.rs +5 -4
- package/sdk-core/crates/client/src/request_extensions.rs +8 -9
- package/sdk-core/crates/client/src/retry.rs +99 -54
- package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +1 -1
- package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
- package/sdk-core/crates/common/Cargo.toml +61 -2
- package/sdk-core/crates/common/build.rs +742 -12
- package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
- package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
- package/sdk-core/crates/common/protos/api_upstream/buf.yaml +0 -3
- package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +1166 -770
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +1243 -750
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +2 -2
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -3
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +16 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -6
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +88 -33
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +4 -2
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +5 -5
- package/sdk-core/crates/common/src/activity_definition.rs +20 -0
- package/sdk-core/crates/common/src/data_converters.rs +770 -0
- package/sdk-core/crates/common/src/envconfig.rs +5 -0
- package/sdk-core/crates/common/src/lib.rs +15 -211
- package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
- package/sdk-core/crates/common/src/priority.rs +110 -0
- package/sdk-core/crates/common/src/protos/canned_histories.rs +3 -0
- package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
- package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
- package/sdk-core/crates/common/src/protos/mod.rs +122 -27
- package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
- package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +5 -7
- package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
- package/sdk-core/crates/common/src/telemetry/metrics.rs +268 -223
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
- package/sdk-core/crates/common/src/telemetry.rs +264 -4
- package/sdk-core/crates/common/src/worker.rs +68 -603
- package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
- package/sdk-core/crates/macros/Cargo.toml +5 -1
- package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
- package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
- package/sdk-core/crates/macros/src/lib.rs +138 -512
- package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
- package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
- package/sdk-core/crates/sdk/Cargo.toml +19 -6
- package/sdk-core/crates/sdk/README.md +415 -0
- package/sdk-core/crates/sdk/src/activities.rs +417 -0
- package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
- package/sdk-core/crates/sdk/src/lib.rs +757 -442
- package/sdk-core/crates/sdk/src/workflow_context/options.rs +45 -35
- package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
- package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
- package/sdk-core/crates/sdk/src/workflows.rs +711 -0
- package/sdk-core/crates/sdk-core/Cargo.toml +57 -64
- package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +41 -35
- package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
- package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
- package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
- package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +13 -15
- package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
- package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
- package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
- package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +493 -26
- package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +4 -8
- package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +7 -7
- package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
- package/sdk-core/crates/sdk-core/src/lib.rs +41 -111
- package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
- package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +118 -19
- package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
- package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
- package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +179 -196
- package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -280
- package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +6 -9
- package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
- package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
- package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
- package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +9 -5
- package/sdk-core/crates/sdk-core/src/worker/client.rs +103 -81
- package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +7 -11
- package/sdk-core/crates/sdk-core/src/worker/mod.rs +1124 -229
- package/sdk-core/crates/sdk-core/src/worker/nexus.rs +145 -23
- package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +13 -13
- package/sdk-core/crates/sdk-core/src/worker/tuner.rs +28 -8
- package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +19 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +14 -18
- package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +4 -6
- package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
- package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
- package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
- package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
- package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
- package/sdk-core/crates/sdk-core/tests/common/mod.rs +241 -196
- package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
- package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +3 -5
- package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -64
- package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +298 -252
- package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
- package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +16 -12
- package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +48 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +327 -255
- package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
- package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +147 -126
- package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
- package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -453
- package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +360 -231
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +248 -185
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -43
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +428 -315
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -56
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -28
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -243
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +101 -42
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -147
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -28
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1036
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -41
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +397 -238
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +414 -189
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +154 -137
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -105
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -38
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -54
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +363 -226
- package/sdk-core/crates/sdk-core/tests/main.rs +17 -15
- package/sdk-core/crates/sdk-core/tests/manual_tests.rs +207 -152
- package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +65 -34
- package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
- package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +7 -1
- package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +14 -14
- package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +83 -74
- package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +9 -14
- package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +1 -2
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +13 -13
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +6 -6
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +3 -4
- package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +62 -75
- package/sdk-core/rustfmt.toml +2 -1
- package/src/client.rs +205 -318
- package/src/metrics.rs +22 -30
- package/src/runtime.rs +4 -5
- package/src/worker.rs +16 -19
- package/ts/native.ts +1 -1
- package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
- package/sdk-core/crates/common/src/errors.rs +0 -85
- package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
- package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
- package/sdk-core/crates/sdk/src/app_data.rs +0 -37
- package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
use temporalio_common::worker::{WorkerConfig, WorkerTaskTypes, WorkerVersioningStrategy};
|
|
2
|
-
|
|
3
|
-
fn default_versioning_strategy() -> WorkerVersioningStrategy {
|
|
4
|
-
WorkerVersioningStrategy::None {
|
|
5
|
-
build_id: String::new(),
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
#[test]
|
|
10
|
-
fn test_default_configuration_polls_all_types() {
|
|
11
|
-
let config = WorkerConfig::builder()
|
|
12
|
-
.namespace("default")
|
|
13
|
-
.task_queue("test-queue")
|
|
14
|
-
.versioning_strategy(default_versioning_strategy())
|
|
15
|
-
.task_types(WorkerTaskTypes::all())
|
|
16
|
-
.build()
|
|
17
|
-
.unwrap();
|
|
18
|
-
|
|
19
|
-
let effective = &config.task_types;
|
|
20
|
-
assert!(
|
|
21
|
-
effective.enable_workflows,
|
|
22
|
-
"Should poll workflows by default"
|
|
23
|
-
);
|
|
24
|
-
assert!(
|
|
25
|
-
effective.enable_local_activities,
|
|
26
|
-
"should poll local activities by default"
|
|
27
|
-
);
|
|
28
|
-
assert!(
|
|
29
|
-
effective.enable_remote_activities,
|
|
30
|
-
"Should poll remote activities by default"
|
|
31
|
-
);
|
|
32
|
-
assert!(effective.enable_nexus, "Should poll nexus by default");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#[test]
|
|
36
|
-
fn test_invalid_task_types_fails_validation() {
|
|
37
|
-
// empty task types
|
|
38
|
-
let result = WorkerConfig::builder()
|
|
39
|
-
.namespace("default")
|
|
40
|
-
.task_queue("test-queue")
|
|
41
|
-
.versioning_strategy(default_versioning_strategy())
|
|
42
|
-
.task_types(WorkerTaskTypes {
|
|
43
|
-
enable_workflows: false,
|
|
44
|
-
enable_local_activities: false,
|
|
45
|
-
enable_remote_activities: false,
|
|
46
|
-
enable_nexus: false,
|
|
47
|
-
})
|
|
48
|
-
.build();
|
|
49
|
-
|
|
50
|
-
assert!(result.is_err(), "Empty task_types should fail validation");
|
|
51
|
-
let err = result.err().unwrap();
|
|
52
|
-
assert!(
|
|
53
|
-
err.contains("At least one task type"),
|
|
54
|
-
"Error should mention task types: {err}",
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// local activities with no workflows
|
|
58
|
-
let result = WorkerConfig::builder()
|
|
59
|
-
.namespace("default")
|
|
60
|
-
.task_queue("test-queue")
|
|
61
|
-
.versioning_strategy(default_versioning_strategy())
|
|
62
|
-
.task_types(WorkerTaskTypes {
|
|
63
|
-
enable_workflows: false,
|
|
64
|
-
enable_local_activities: true,
|
|
65
|
-
enable_remote_activities: false,
|
|
66
|
-
enable_nexus: false,
|
|
67
|
-
})
|
|
68
|
-
.build();
|
|
69
|
-
|
|
70
|
-
assert!(result.is_err(), "Empty task_types should fail validation");
|
|
71
|
-
let err = result.err().unwrap();
|
|
72
|
-
assert!(
|
|
73
|
-
err.contains("cannot enable local activities without workflows"),
|
|
74
|
-
"Error should mention task types: {err}",
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
#[test]
|
|
79
|
-
fn test_all_combinations() {
|
|
80
|
-
let combinations = [
|
|
81
|
-
(WorkerTaskTypes::workflow_only(), "workflows only"),
|
|
82
|
-
(WorkerTaskTypes::activity_only(), "activities only"),
|
|
83
|
-
(WorkerTaskTypes::nexus_only(), "nexus only"),
|
|
84
|
-
(
|
|
85
|
-
WorkerTaskTypes {
|
|
86
|
-
enable_workflows: true,
|
|
87
|
-
enable_local_activities: true,
|
|
88
|
-
enable_remote_activities: true,
|
|
89
|
-
enable_nexus: false,
|
|
90
|
-
},
|
|
91
|
-
"workflows + activities",
|
|
92
|
-
),
|
|
93
|
-
(
|
|
94
|
-
WorkerTaskTypes {
|
|
95
|
-
enable_workflows: true,
|
|
96
|
-
enable_local_activities: true,
|
|
97
|
-
enable_remote_activities: false,
|
|
98
|
-
enable_nexus: true,
|
|
99
|
-
},
|
|
100
|
-
"workflows + nexus",
|
|
101
|
-
),
|
|
102
|
-
(
|
|
103
|
-
WorkerTaskTypes {
|
|
104
|
-
enable_workflows: false,
|
|
105
|
-
enable_local_activities: false,
|
|
106
|
-
enable_remote_activities: true,
|
|
107
|
-
enable_nexus: true,
|
|
108
|
-
},
|
|
109
|
-
"activities + nexus",
|
|
110
|
-
),
|
|
111
|
-
(WorkerTaskTypes::all(), "all types"),
|
|
112
|
-
];
|
|
113
|
-
|
|
114
|
-
for (task_types, description) in combinations {
|
|
115
|
-
let config = WorkerConfig::builder()
|
|
116
|
-
.namespace("default")
|
|
117
|
-
.task_queue("test-queue")
|
|
118
|
-
.versioning_strategy(default_versioning_strategy())
|
|
119
|
-
.task_types(task_types)
|
|
120
|
-
.build()
|
|
121
|
-
.unwrap();
|
|
122
|
-
|
|
123
|
-
let effective = config.task_types;
|
|
124
|
-
assert_eq!(
|
|
125
|
-
effective, task_types,
|
|
126
|
-
"Effective types should match for {description}",
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
use crate::app_data::AppData;
|
|
2
|
-
|
|
3
|
-
use prost_types::{Duration, Timestamp};
|
|
4
|
-
use std::{
|
|
5
|
-
collections::HashMap,
|
|
6
|
-
sync::Arc,
|
|
7
|
-
time::{Duration as StdDuration, SystemTime},
|
|
8
|
-
};
|
|
9
|
-
use temporalio_client::Priority;
|
|
10
|
-
use temporalio_common::{
|
|
11
|
-
Worker,
|
|
12
|
-
protos::{
|
|
13
|
-
coresdk::{ActivityHeartbeat, activity_task},
|
|
14
|
-
temporal::api::common::v1::{Payload, RetryPolicy, WorkflowExecution},
|
|
15
|
-
utilities::TryIntoOrNone,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
use tokio_util::sync::CancellationToken;
|
|
19
|
-
|
|
20
|
-
/// Used within activities to get info, heartbeat management etc.
|
|
21
|
-
#[derive(Clone)]
|
|
22
|
-
pub struct ActContext {
|
|
23
|
-
worker: Arc<dyn Worker>,
|
|
24
|
-
app_data: Arc<AppData>,
|
|
25
|
-
cancellation_token: CancellationToken,
|
|
26
|
-
input: Vec<Payload>,
|
|
27
|
-
heartbeat_details: Vec<Payload>,
|
|
28
|
-
header_fields: HashMap<String, Payload>,
|
|
29
|
-
info: ActivityInfo,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[derive(Clone)]
|
|
33
|
-
pub struct ActivityInfo {
|
|
34
|
-
pub task_token: Vec<u8>,
|
|
35
|
-
pub workflow_type: String,
|
|
36
|
-
pub workflow_namespace: String,
|
|
37
|
-
pub workflow_execution: Option<WorkflowExecution>,
|
|
38
|
-
pub activity_id: String,
|
|
39
|
-
pub activity_type: String,
|
|
40
|
-
pub task_queue: String,
|
|
41
|
-
pub heartbeat_timeout: Option<StdDuration>,
|
|
42
|
-
/// Time activity was scheduled by a workflow
|
|
43
|
-
pub scheduled_time: Option<SystemTime>,
|
|
44
|
-
/// Time of activity start
|
|
45
|
-
pub started_time: Option<SystemTime>,
|
|
46
|
-
/// Time of activity timeout
|
|
47
|
-
pub deadline: Option<SystemTime>,
|
|
48
|
-
/// Attempt starts from 1, and increase by 1 for every retry, if retry policy is specified.
|
|
49
|
-
pub attempt: u32,
|
|
50
|
-
/// Time this attempt at the activity was scheduled
|
|
51
|
-
pub current_attempt_scheduled_time: Option<SystemTime>,
|
|
52
|
-
pub retry_policy: Option<RetryPolicy>,
|
|
53
|
-
pub is_local: bool,
|
|
54
|
-
/// Priority of this activity. If unset uses [Priority::default]
|
|
55
|
-
pub priority: Priority,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
impl ActContext {
|
|
59
|
-
/// Construct new Activity Context, returning the context and the first argument to the activity
|
|
60
|
-
/// (which may be a default [Payload]).
|
|
61
|
-
pub fn new(
|
|
62
|
-
worker: Arc<dyn Worker>,
|
|
63
|
-
app_data: Arc<AppData>,
|
|
64
|
-
cancellation_token: CancellationToken,
|
|
65
|
-
task_queue: String,
|
|
66
|
-
task_token: Vec<u8>,
|
|
67
|
-
task: activity_task::Start,
|
|
68
|
-
) -> (Self, Payload) {
|
|
69
|
-
let activity_task::Start {
|
|
70
|
-
workflow_namespace,
|
|
71
|
-
workflow_type,
|
|
72
|
-
workflow_execution,
|
|
73
|
-
activity_id,
|
|
74
|
-
activity_type,
|
|
75
|
-
header_fields,
|
|
76
|
-
mut input,
|
|
77
|
-
heartbeat_details,
|
|
78
|
-
scheduled_time,
|
|
79
|
-
current_attempt_scheduled_time,
|
|
80
|
-
started_time,
|
|
81
|
-
attempt,
|
|
82
|
-
schedule_to_close_timeout,
|
|
83
|
-
start_to_close_timeout,
|
|
84
|
-
heartbeat_timeout,
|
|
85
|
-
retry_policy,
|
|
86
|
-
is_local,
|
|
87
|
-
priority,
|
|
88
|
-
} = task;
|
|
89
|
-
let deadline = calculate_deadline(
|
|
90
|
-
scheduled_time.as_ref(),
|
|
91
|
-
started_time.as_ref(),
|
|
92
|
-
start_to_close_timeout.as_ref(),
|
|
93
|
-
schedule_to_close_timeout.as_ref(),
|
|
94
|
-
);
|
|
95
|
-
let first_arg = input.pop().unwrap_or_default();
|
|
96
|
-
|
|
97
|
-
(
|
|
98
|
-
ActContext {
|
|
99
|
-
worker,
|
|
100
|
-
app_data,
|
|
101
|
-
cancellation_token,
|
|
102
|
-
input,
|
|
103
|
-
heartbeat_details,
|
|
104
|
-
header_fields,
|
|
105
|
-
info: ActivityInfo {
|
|
106
|
-
task_token,
|
|
107
|
-
task_queue,
|
|
108
|
-
workflow_type,
|
|
109
|
-
workflow_namespace,
|
|
110
|
-
workflow_execution,
|
|
111
|
-
activity_id,
|
|
112
|
-
activity_type,
|
|
113
|
-
heartbeat_timeout: heartbeat_timeout.try_into_or_none(),
|
|
114
|
-
scheduled_time: scheduled_time.try_into_or_none(),
|
|
115
|
-
started_time: started_time.try_into_or_none(),
|
|
116
|
-
deadline,
|
|
117
|
-
attempt,
|
|
118
|
-
current_attempt_scheduled_time: current_attempt_scheduled_time
|
|
119
|
-
.try_into_or_none(),
|
|
120
|
-
retry_policy,
|
|
121
|
-
is_local,
|
|
122
|
-
priority: priority.map(Into::into).unwrap_or_default(),
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
first_arg,
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/// Returns a future the completes if and when the activity this was called inside has been
|
|
130
|
-
/// cancelled
|
|
131
|
-
pub async fn cancelled(&self) {
|
|
132
|
-
self.cancellation_token.clone().cancelled().await
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/// Returns true if this activity has already been cancelled
|
|
136
|
-
pub fn is_cancelled(&self) -> bool {
|
|
137
|
-
self.cancellation_token.is_cancelled()
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/// Retrieve extra parameters to the Activity. The first input is always popped and passed to
|
|
141
|
-
/// the Activity function for the currently executing activity. However, if more parameters are
|
|
142
|
-
/// passed, perhaps from another language's SDK, explicit access is available from extra_inputs
|
|
143
|
-
pub fn extra_inputs(&mut self) -> &mut [Payload] {
|
|
144
|
-
&mut self.input
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/// Extract heartbeat details from last failed attempt. This is used in combination with retry policy.
|
|
148
|
-
pub fn get_heartbeat_details(&self) -> &[Payload] {
|
|
149
|
-
&self.heartbeat_details
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/// RecordHeartbeat sends heartbeat for the currently executing activity
|
|
153
|
-
pub fn record_heartbeat(&self, details: Vec<Payload>) {
|
|
154
|
-
if !self.info.is_local {
|
|
155
|
-
self.worker.record_activity_heartbeat(ActivityHeartbeat {
|
|
156
|
-
task_token: self.info.task_token.clone(),
|
|
157
|
-
details,
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/// Get activity info of the executing activity
|
|
163
|
-
pub fn get_info(&self) -> &ActivityInfo {
|
|
164
|
-
&self.info
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/// Get headers attached to this activity
|
|
168
|
-
pub fn headers(&self) -> &HashMap<String, Payload> {
|
|
169
|
-
&self.header_fields
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/// Get custom Application Data
|
|
173
|
-
pub fn app_data<T: Send + Sync + 'static>(&self) -> Option<&T> {
|
|
174
|
-
self.app_data.get::<T>()
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/// Deadline calculation. This is a port of
|
|
179
|
-
/// https://github.com/temporalio/sdk-go/blob/8651550973088f27f678118f997839fb1bb9e62f/internal/activity.go#L225
|
|
180
|
-
fn calculate_deadline(
|
|
181
|
-
scheduled_time: Option<&Timestamp>,
|
|
182
|
-
started_time: Option<&Timestamp>,
|
|
183
|
-
start_to_close_timeout: Option<&Duration>,
|
|
184
|
-
schedule_to_close_timeout: Option<&Duration>,
|
|
185
|
-
) -> Option<SystemTime> {
|
|
186
|
-
match (
|
|
187
|
-
scheduled_time,
|
|
188
|
-
started_time,
|
|
189
|
-
start_to_close_timeout,
|
|
190
|
-
schedule_to_close_timeout,
|
|
191
|
-
) {
|
|
192
|
-
(
|
|
193
|
-
Some(scheduled),
|
|
194
|
-
Some(started),
|
|
195
|
-
Some(start_to_close_timeout),
|
|
196
|
-
Some(schedule_to_close_timeout),
|
|
197
|
-
) => {
|
|
198
|
-
let scheduled: SystemTime = maybe_convert_timestamp(scheduled)?;
|
|
199
|
-
let started: SystemTime = maybe_convert_timestamp(started)?;
|
|
200
|
-
let start_to_close_timeout: StdDuration = (*start_to_close_timeout).try_into().ok()?;
|
|
201
|
-
let schedule_to_close_timeout: StdDuration =
|
|
202
|
-
(*schedule_to_close_timeout).try_into().ok()?;
|
|
203
|
-
|
|
204
|
-
let start_to_close_deadline: SystemTime =
|
|
205
|
-
started.checked_add(start_to_close_timeout)?;
|
|
206
|
-
if schedule_to_close_timeout > StdDuration::ZERO {
|
|
207
|
-
let schedule_to_close_deadline =
|
|
208
|
-
scheduled.checked_add(schedule_to_close_timeout)?;
|
|
209
|
-
// Minimum of the two deadlines.
|
|
210
|
-
if schedule_to_close_deadline < start_to_close_deadline {
|
|
211
|
-
Some(schedule_to_close_deadline)
|
|
212
|
-
} else {
|
|
213
|
-
Some(start_to_close_deadline)
|
|
214
|
-
}
|
|
215
|
-
} else {
|
|
216
|
-
Some(start_to_close_deadline)
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
_ => None,
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/// Helper function lifted from prost_types::Timestamp implementation to prevent double cloning in
|
|
224
|
-
/// error construction
|
|
225
|
-
fn maybe_convert_timestamp(timestamp: &Timestamp) -> Option<SystemTime> {
|
|
226
|
-
let mut timestamp = *timestamp;
|
|
227
|
-
timestamp.normalize();
|
|
228
|
-
|
|
229
|
-
let system_time = if timestamp.seconds >= 0 {
|
|
230
|
-
std::time::UNIX_EPOCH.checked_add(StdDuration::from_secs(timestamp.seconds as u64))
|
|
231
|
-
} else {
|
|
232
|
-
std::time::UNIX_EPOCH.checked_sub(StdDuration::from_secs((-timestamp.seconds) as u64))
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
system_time.and_then(|system_time| {
|
|
236
|
-
system_time.checked_add(StdDuration::from_nanos(timestamp.nanos as u64))
|
|
237
|
-
})
|
|
238
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
use std::{
|
|
2
|
-
any::{Any, TypeId},
|
|
3
|
-
collections::HashMap,
|
|
4
|
-
fmt,
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
/// A Wrapper Type for workflow and activity app data
|
|
8
|
-
#[derive(Default)]
|
|
9
|
-
pub struct AppData {
|
|
10
|
-
map: HashMap<TypeId, Box<dyn Any + Send + Sync>>,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
impl AppData {
|
|
14
|
-
/// Insert an item, overwritting duplicates
|
|
15
|
-
pub(crate) fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
|
|
16
|
-
self.map
|
|
17
|
-
.insert(TypeId::of::<T>(), Box::new(val))
|
|
18
|
-
.and_then(downcast_owned)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/// Get a reference to a type in the map
|
|
22
|
-
pub(crate) fn get<T: 'static>(&self) -> Option<&T> {
|
|
23
|
-
self.map
|
|
24
|
-
.get(&TypeId::of::<T>())
|
|
25
|
-
.and_then(|boxed| boxed.downcast_ref())
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
impl fmt::Debug for AppData {
|
|
30
|
-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
31
|
-
f.debug_struct("AppData").finish()
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
fn downcast_owned<T: Send + Sync + 'static>(boxed: Box<dyn Any + Send + Sync>) -> Option<T> {
|
|
36
|
-
boxed.downcast().ok().map(|boxed| *boxed)
|
|
37
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
use crate::common::CoreWfStarter;
|
|
2
|
-
use assert_matches::assert_matches;
|
|
3
|
-
use std::time::Duration;
|
|
4
|
-
use temporalio_client::{WfClientExt, WorkflowExecutionResult, WorkflowOptions};
|
|
5
|
-
use temporalio_common::protos::coresdk::AsJsonPayloadExt;
|
|
6
|
-
use temporalio_sdk::{ActContext, ActivityOptions, WfContext, WorkflowResult};
|
|
7
|
-
|
|
8
|
-
const TEST_APPDATA_MESSAGE: &str = "custom app data, yay";
|
|
9
|
-
|
|
10
|
-
struct Data {
|
|
11
|
-
message: String,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
pub(crate) async fn appdata_activity_wf(ctx: WfContext) -> WorkflowResult<()> {
|
|
15
|
-
ctx.activity(ActivityOptions {
|
|
16
|
-
activity_type: "echo_activity".to_string(),
|
|
17
|
-
start_to_close_timeout: Some(Duration::from_secs(5)),
|
|
18
|
-
input: "hi!".as_json_payload().expect("serializes fine"),
|
|
19
|
-
..Default::default()
|
|
20
|
-
})
|
|
21
|
-
.await;
|
|
22
|
-
Ok(().into())
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
#[tokio::test]
|
|
26
|
-
async fn appdata_access_in_activities_and_workflows() {
|
|
27
|
-
let wf_name = "appdata_activity";
|
|
28
|
-
let mut starter = CoreWfStarter::new(wf_name);
|
|
29
|
-
let mut worker = starter.worker().await;
|
|
30
|
-
worker.inner_mut().insert_app_data(Data {
|
|
31
|
-
message: TEST_APPDATA_MESSAGE.to_owned(),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
let client = starter.get_client().await;
|
|
35
|
-
worker.register_wf(wf_name.to_owned(), appdata_activity_wf);
|
|
36
|
-
worker.register_activity(
|
|
37
|
-
"echo_activity",
|
|
38
|
-
|ctx: ActContext, echo_me: String| async move {
|
|
39
|
-
let data = ctx.app_data::<Data>().expect("appdata exists. qed");
|
|
40
|
-
assert_eq!(data.message, TEST_APPDATA_MESSAGE.to_owned());
|
|
41
|
-
Ok(echo_me)
|
|
42
|
-
},
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
let run_id = worker
|
|
46
|
-
.submit_wf(
|
|
47
|
-
wf_name.to_owned(),
|
|
48
|
-
wf_name.to_owned(),
|
|
49
|
-
vec![],
|
|
50
|
-
WorkflowOptions::default(),
|
|
51
|
-
)
|
|
52
|
-
.await
|
|
53
|
-
.unwrap();
|
|
54
|
-
worker.run_until_done().await.unwrap();
|
|
55
|
-
let handle = client.get_untyped_workflow_handle(wf_name, run_id);
|
|
56
|
-
let res = handle
|
|
57
|
-
.get_workflow_result(Default::default())
|
|
58
|
-
.await
|
|
59
|
-
.unwrap();
|
|
60
|
-
assert_matches!(res, WorkflowExecutionResult::Succeeded(_));
|
|
61
|
-
}
|