@temporalio/core-bridge 0.16.4 → 0.18.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.
Files changed (170) hide show
  1. package/Cargo.lock +339 -226
  2. package/Cargo.toml +7 -3
  3. package/common.js +50 -0
  4. package/index.d.ts +7 -0
  5. package/index.js +12 -0
  6. package/package.json +7 -4
  7. package/releases/aarch64-apple-darwin/index.node +0 -0
  8. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  9. package/{index.node → releases/index.node} +0 -0
  10. package/releases/x86_64-apple-darwin/index.node +0 -0
  11. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  12. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  13. package/scripts/build.js +10 -50
  14. package/sdk-core/.buildkite/docker/Dockerfile +1 -1
  15. package/sdk-core/.buildkite/docker/docker-compose.yaml +2 -2
  16. package/sdk-core/.buildkite/pipeline.yml +2 -0
  17. package/sdk-core/Cargo.toml +1 -88
  18. package/sdk-core/README.md +30 -6
  19. package/sdk-core/bridge-ffi/Cargo.toml +24 -0
  20. package/sdk-core/bridge-ffi/LICENSE.txt +23 -0
  21. package/sdk-core/bridge-ffi/build.rs +25 -0
  22. package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +216 -0
  23. package/sdk-core/bridge-ffi/src/lib.rs +829 -0
  24. package/sdk-core/bridge-ffi/src/wrappers.rs +193 -0
  25. package/sdk-core/client/Cargo.toml +32 -0
  26. package/sdk-core/{src/pollers/gateway.rs → client/src/lib.rs} +101 -195
  27. package/sdk-core/client/src/metrics.rs +89 -0
  28. package/sdk-core/client/src/mocks.rs +167 -0
  29. package/sdk-core/{src/pollers → client/src}/retry.rs +172 -14
  30. package/sdk-core/core/Cargo.toml +96 -0
  31. package/sdk-core/{src → core/src}/core_tests/activity_tasks.rs +193 -37
  32. package/sdk-core/{src → core/src}/core_tests/child_workflows.rs +14 -14
  33. package/sdk-core/{src → core/src}/core_tests/determinism.rs +8 -8
  34. package/sdk-core/core/src/core_tests/local_activities.rs +328 -0
  35. package/sdk-core/{src → core/src}/core_tests/mod.rs +6 -9
  36. package/sdk-core/{src → core/src}/core_tests/queries.rs +54 -54
  37. package/sdk-core/{src → core/src}/core_tests/replay_flag.rs +8 -12
  38. package/sdk-core/{src → core/src}/core_tests/workers.rs +120 -33
  39. package/sdk-core/{src → core/src}/core_tests/workflow_cancels.rs +16 -26
  40. package/sdk-core/{src → core/src}/core_tests/workflow_tasks.rs +280 -292
  41. package/sdk-core/core/src/lib.rs +374 -0
  42. package/sdk-core/{src → core/src}/log_export.rs +3 -27
  43. package/sdk-core/core/src/pending_activations.rs +162 -0
  44. package/sdk-core/{src → core/src}/pollers/mod.rs +4 -22
  45. package/sdk-core/{src → core/src}/pollers/poll_buffer.rs +1 -1
  46. package/sdk-core/core/src/protosext/mod.rs +396 -0
  47. package/sdk-core/core/src/replay/mod.rs +210 -0
  48. package/sdk-core/core/src/retry_logic.rs +144 -0
  49. package/sdk-core/{src → core/src}/telemetry/metrics.rs +3 -58
  50. package/sdk-core/{src → core/src}/telemetry/mod.rs +8 -8
  51. package/sdk-core/{src → core/src}/telemetry/prometheus_server.rs +0 -0
  52. package/sdk-core/{src → core/src}/test_help/mod.rs +35 -83
  53. package/sdk-core/{src → core/src}/worker/activities/activity_heartbeat_manager.rs +95 -42
  54. package/sdk-core/core/src/worker/activities/local_activities.rs +973 -0
  55. package/sdk-core/{src → core/src}/worker/activities.rs +52 -33
  56. package/sdk-core/{src → core/src}/worker/dispatcher.rs +8 -6
  57. package/sdk-core/{src → core/src}/worker/mod.rs +347 -221
  58. package/sdk-core/core/src/worker/wft_delivery.rs +81 -0
  59. package/sdk-core/{src → core/src}/workflow/bridge.rs +5 -2
  60. package/sdk-core/{src → core/src}/workflow/driven_workflow.rs +17 -7
  61. package/sdk-core/{src → core/src}/workflow/history_update.rs +33 -7
  62. package/sdk-core/{src → core/src/workflow}/machines/activity_state_machine.rs +26 -26
  63. package/sdk-core/{src → core/src/workflow}/machines/cancel_external_state_machine.rs +8 -11
  64. package/sdk-core/{src → core/src/workflow}/machines/cancel_workflow_state_machine.rs +19 -21
  65. package/sdk-core/{src → core/src/workflow}/machines/child_workflow_state_machine.rs +20 -31
  66. package/sdk-core/{src → core/src/workflow}/machines/complete_workflow_state_machine.rs +3 -5
  67. package/sdk-core/{src → core/src/workflow}/machines/continue_as_new_workflow_state_machine.rs +18 -18
  68. package/sdk-core/{src → core/src/workflow}/machines/fail_workflow_state_machine.rs +5 -6
  69. package/sdk-core/core/src/workflow/machines/local_activity_state_machine.rs +1451 -0
  70. package/sdk-core/{src → core/src/workflow}/machines/mod.rs +54 -107
  71. package/sdk-core/{src → core/src/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
  72. package/sdk-core/{src → core/src/workflow}/machines/patch_state_machine.rs +29 -30
  73. package/sdk-core/{src → core/src/workflow}/machines/side_effect_state_machine.rs +0 -0
  74. package/sdk-core/{src → core/src/workflow}/machines/signal_external_state_machine.rs +17 -19
  75. package/sdk-core/{src → core/src/workflow}/machines/timer_state_machine.rs +20 -21
  76. package/sdk-core/{src → core/src/workflow}/machines/transition_coverage.rs +5 -2
  77. package/sdk-core/{src → core/src/workflow}/machines/upsert_search_attributes_state_machine.rs +0 -0
  78. package/sdk-core/core/src/workflow/machines/workflow_machines/local_acts.rs +96 -0
  79. package/sdk-core/{src → core/src/workflow}/machines/workflow_machines.rs +357 -171
  80. package/sdk-core/{src → core/src/workflow}/machines/workflow_task_state_machine.rs +1 -1
  81. package/sdk-core/{src → core/src}/workflow/mod.rs +200 -39
  82. package/sdk-core/{src → core/src}/workflow/workflow_tasks/cache_manager.rs +0 -0
  83. package/sdk-core/{src → core/src}/workflow/workflow_tasks/concurrency_manager.rs +38 -5
  84. package/sdk-core/{src → core/src}/workflow/workflow_tasks/mod.rs +317 -103
  85. package/sdk-core/{test_utils → core-api}/Cargo.toml +10 -7
  86. package/sdk-core/{src → core-api/src}/errors.rs +42 -92
  87. package/sdk-core/core-api/src/lib.rs +158 -0
  88. package/sdk-core/{src/worker/config.rs → core-api/src/worker.rs} +18 -23
  89. package/sdk-core/etc/deps.svg +156 -0
  90. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +5 -5
  91. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +3 -5
  92. package/sdk-core/fsm/rustfsm_trait/src/lib.rs +7 -1
  93. package/sdk-core/histories/fail_wf_task.bin +0 -0
  94. package/sdk-core/histories/timer_workflow_history.bin +0 -0
  95. package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +44 -13
  96. package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +19 -1
  97. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +1 -1
  98. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +9 -0
  99. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +1 -0
  100. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +1 -0
  101. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +13 -0
  102. package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +14 -7
  103. package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +176 -18
  104. package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
  105. package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +11 -0
  106. package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +3 -0
  107. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +156 -7
  108. package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +135 -104
  109. package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
  110. package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +78 -0
  111. package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +205 -0
  112. package/sdk-core/protos/local/temporal/sdk/core/bridge/service.proto +61 -0
  113. package/sdk-core/protos/local/{child_workflow.proto → temporal/sdk/core/child_workflow/child_workflow.proto} +1 -1
  114. package/sdk-core/protos/local/{common.proto → temporal/sdk/core/common/common.proto} +5 -3
  115. package/sdk-core/protos/local/{core_interface.proto → temporal/sdk/core/core_interface.proto} +10 -10
  116. package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
  117. package/sdk-core/protos/local/{workflow_activation.proto → temporal/sdk/core/workflow_activation/workflow_activation.proto} +35 -11
  118. package/sdk-core/protos/local/{workflow_commands.proto → temporal/sdk/core/workflow_commands/workflow_commands.proto} +55 -4
  119. package/sdk-core/protos/local/{workflow_completion.proto → temporal/sdk/core/workflow_completion/workflow_completion.proto} +3 -3
  120. package/sdk-core/sdk/Cargo.toml +32 -0
  121. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/conversions.rs +0 -0
  122. package/sdk-core/sdk/src/lib.rs +699 -0
  123. package/sdk-core/sdk/src/payload_converter.rs +11 -0
  124. package/sdk-core/sdk/src/workflow_context/options.rs +180 -0
  125. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_context.rs +201 -124
  126. package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_future.rs +63 -30
  127. package/sdk-core/sdk-core-protos/Cargo.toml +10 -0
  128. package/sdk-core/sdk-core-protos/build.rs +28 -6
  129. package/sdk-core/sdk-core-protos/src/constants.rs +7 -0
  130. package/sdk-core/{src/test_help → sdk-core-protos/src}/history_builder.rs +134 -49
  131. package/sdk-core/sdk-core-protos/src/history_info.rs +216 -0
  132. package/sdk-core/sdk-core-protos/src/lib.rs +601 -168
  133. package/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
  134. package/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  135. package/sdk-core/test-utils/Cargo.toml +32 -0
  136. package/sdk-core/{src/test_help → test-utils/src}/canned_histories.rs +59 -78
  137. package/sdk-core/test-utils/src/histfetch.rs +28 -0
  138. package/sdk-core/{test_utils → test-utils}/src/lib.rs +131 -68
  139. package/sdk-core/tests/integ_tests/client_tests.rs +1 -1
  140. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -7
  141. package/sdk-core/tests/integ_tests/polling_tests.rs +12 -11
  142. package/sdk-core/tests/integ_tests/queries_tests.rs +82 -78
  143. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +91 -71
  144. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +3 -4
  145. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +2 -4
  146. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +4 -6
  147. package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +4 -6
  148. package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -4
  149. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +496 -0
  150. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +5 -8
  151. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +125 -0
  152. package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +7 -13
  153. package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +33 -5
  154. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +12 -16
  155. package/sdk-core/tests/integ_tests/workflow_tests.rs +85 -82
  156. package/sdk-core/tests/load_tests.rs +6 -6
  157. package/sdk-core/tests/main.rs +2 -2
  158. package/src/conversions.rs +24 -21
  159. package/src/errors.rs +8 -0
  160. package/src/lib.rs +323 -211
  161. package/sdk-core/protos/local/activity_result.proto +0 -46
  162. package/sdk-core/protos/local/activity_task.proto +0 -66
  163. package/sdk-core/src/core_tests/retry.rs +0 -147
  164. package/sdk-core/src/lib.rs +0 -403
  165. package/sdk-core/src/machines/local_activity_state_machine.rs +0 -117
  166. package/sdk-core/src/pending_activations.rs +0 -249
  167. package/sdk-core/src/protosext/mod.rs +0 -160
  168. package/sdk-core/src/prototype_rust_sdk.rs +0 -412
  169. package/sdk-core/src/task_token.rs +0 -20
  170. package/sdk-core/src/test_help/history_info.rs +0 -157
@@ -0,0 +1,11 @@
1
+ //! Very much subject to change. Defines traits for converting inputs/outputs to/from payloads
2
+
3
+ use serde::{Deserialize, Serialize};
4
+
5
+ /// Something that can be deserialized from a payload. Currently just a pass-through to
6
+ /// [Deserialize] which may actually be the best long-run choice.
7
+ pub trait FromPayload<'de>: Deserialize<'de> {}
8
+
9
+ /// Something that can be serialized into a payload. Currently just a pass-through to
10
+ /// [Serialize] which may actually be the best long-run choice.
11
+ pub trait IntoPayload: Serialize {}
@@ -0,0 +1,180 @@
1
+ use std::time::Duration;
2
+ use temporal_sdk_core_protos::coresdk::{
3
+ child_workflow::ChildWorkflowCancellationType,
4
+ common::{Payload, RetryPolicy},
5
+ workflow_commands::{
6
+ ActivityCancellationType, ScheduleActivity, ScheduleLocalActivity,
7
+ StartChildWorkflowExecution,
8
+ },
9
+ };
10
+
11
+ // TODO: Before release, probably best to avoid using proto types entirely here. They're awkward.
12
+
13
+ pub trait IntoWorkflowCommand {
14
+ type WFCommandType;
15
+
16
+ /// Produces a workflow command from some options
17
+ fn into_command(self, seq: u32) -> Self::WFCommandType;
18
+ }
19
+
20
+ /// Options for scheduling an activity
21
+ #[derive(Default, Debug)]
22
+ pub struct ActivityOptions {
23
+ /// Identifier to use for tracking the activity in Workflow history.
24
+ /// The `activityId` can be accessed by the activity function.
25
+ /// Does not need to be unique.
26
+ ///
27
+ /// If `None` use the context's sequence number
28
+ pub activity_id: Option<String>,
29
+ /// Type of activity to schedule
30
+ pub activity_type: String,
31
+ /// Input to the activity
32
+ pub input: Payload,
33
+ /// Task queue to schedule the activity in
34
+ pub task_queue: String,
35
+ /// Time that the Activity Task can stay in the Task Queue before it is picked up by a Worker.
36
+ /// Do not specify this timeout unless using host specific Task Queues for Activity Tasks are
37
+ /// being used for routing.
38
+ /// `schedule_to_start_timeout` is always non-retryable.
39
+ /// Retrying after this timeout doesn't make sense as it would just put the Activity Task back
40
+ /// into the same Task Queue.
41
+ pub schedule_to_start_timeout: Option<Duration>,
42
+ /// Maximum time of a single Activity execution attempt.
43
+ /// Note that the Temporal Server doesn't detect Worker process failures directly.
44
+ /// It relies on this timeout to detect that an Activity that didn't complete on time.
45
+ /// So this timeout should be as short as the longest possible execution of the Activity body.
46
+ /// Potentially long running Activities must specify `heartbeat_timeout` and heartbeat from the
47
+ /// activity periodically for timely failure detection.
48
+ /// Either this option or `schedule_to_close_timeout` is required.
49
+ pub start_to_close_timeout: Option<Duration>,
50
+ /// Total time that a workflow is willing to wait for Activity to complete.
51
+ /// `schedule_to_close_timeout` limits the total time of an Activity's execution including
52
+ /// retries (use `start_to_close_timeout` to limit the time of a single attempt).
53
+ /// Either this option or `start_to_close_timeout` is required.
54
+ pub schedule_to_close_timeout: Option<Duration>,
55
+ /// Heartbeat interval. Activity must heartbeat before this interval passes after a last
56
+ /// heartbeat or activity start.
57
+ pub heartbeat_timeout: Option<Duration>,
58
+ /// Determines what the SDK does when the Activity is cancelled.
59
+ pub cancellation_type: ActivityCancellationType,
60
+ }
61
+
62
+ impl IntoWorkflowCommand for ActivityOptions {
63
+ type WFCommandType = ScheduleActivity;
64
+ fn into_command(self, seq: u32) -> ScheduleActivity {
65
+ ScheduleActivity {
66
+ seq,
67
+ activity_id: match self.activity_id {
68
+ None => seq.to_string(),
69
+ Some(aid) => aid,
70
+ },
71
+ activity_type: self.activity_type,
72
+ task_queue: self.task_queue,
73
+ schedule_to_close_timeout: self.schedule_to_close_timeout.map(Into::into),
74
+ schedule_to_start_timeout: self.schedule_to_start_timeout.map(Into::into),
75
+ start_to_close_timeout: self.start_to_close_timeout.map(Into::into),
76
+ heartbeat_timeout: self.heartbeat_timeout.map(Into::into),
77
+ cancellation_type: self.cancellation_type as i32,
78
+ arguments: vec![self.input],
79
+ ..Default::default()
80
+ }
81
+ }
82
+ }
83
+
84
+ /// Options for scheduling a local activity
85
+ #[derive(Default, Debug, Clone)]
86
+ pub struct LocalActivityOptions {
87
+ /// Identifier to use for tracking the activity in Workflow history.
88
+ /// The `activityId` can be accessed by the activity function.
89
+ /// Does not need to be unique.
90
+ ///
91
+ /// If `None` use the context's sequence number
92
+ pub activity_id: Option<String>,
93
+ /// Type of activity to schedule
94
+ pub activity_type: String,
95
+ /// Input to the activity
96
+ pub input: Payload,
97
+ /// Retry policy
98
+ pub retry_policy: RetryPolicy,
99
+ /// Override attempt number rather than using 1.
100
+ /// Ideally we would not expose this in a released Rust SDK, but it's needed for test.
101
+ pub attempt: Option<u32>,
102
+ /// Override schedule time when doing timer backoff.
103
+ /// Ideally we would not expose this in a released Rust SDK, but it's needed for test.
104
+ pub original_schedule_time: Option<prost_types::Timestamp>,
105
+ /// Retry backoffs over this amount will use a timer rather than a local retry
106
+ pub timer_backoff_threshold: Option<Duration>,
107
+ /// How the activity will cancel
108
+ pub cancel_type: ActivityCancellationType,
109
+ /// Indicates how long the caller is willing to wait for local activity completion. Limits how
110
+ /// long retries will be attempted. When not specified defaults to the workflow execution
111
+ /// timeout (which may be unset).
112
+ pub schedule_to_close_timeout: Option<Duration>,
113
+ /// Limits time the local activity can idle internally before being executed. That can happen if
114
+ /// the worker is currently at max concurrent local activity executions. This timeout is always
115
+ /// non retryable as all a retry would achieve is to put it back into the same queue. Defaults
116
+ /// to `schedule_to_close_timeout` if not specified and that is set. Must be <=
117
+ /// `schedule_to_close_timeout` when set, if not, it will be clamped down.
118
+ pub schedule_to_start_timeout: Option<Duration>,
119
+ /// Maximum time the local activity is allowed to execute after the task is dispatched. This
120
+ /// timeout is always retryable. Either or both of `schedule_to_close_timeout` and this must be
121
+ /// specified. If set, this must be <= `schedule_to_close_timeout`, if not, it will be clamped
122
+ /// down.
123
+ pub start_to_close_timeout: Option<Duration>,
124
+ }
125
+
126
+ impl IntoWorkflowCommand for LocalActivityOptions {
127
+ type WFCommandType = ScheduleLocalActivity;
128
+ fn into_command(mut self, seq: u32) -> ScheduleLocalActivity {
129
+ // Allow tests to avoid extra verbosity when they don't care about timeouts
130
+ // TODO: Builderize LA options
131
+ self.schedule_to_close_timeout
132
+ .get_or_insert(Duration::from_secs(100));
133
+
134
+ ScheduleLocalActivity {
135
+ seq,
136
+ attempt: self.attempt.unwrap_or(1),
137
+ original_schedule_time: self.original_schedule_time,
138
+ activity_id: match self.activity_id {
139
+ None => seq.to_string(),
140
+ Some(aid) => aid,
141
+ },
142
+ activity_type: self.activity_type,
143
+ arguments: vec![self.input],
144
+ retry_policy: Some(self.retry_policy),
145
+ local_retry_threshold: self.timer_backoff_threshold.map(Into::into),
146
+ cancellation_type: self.cancel_type.into(),
147
+ schedule_to_close_timeout: self.schedule_to_close_timeout.map(Into::into),
148
+ schedule_to_start_timeout: self.schedule_to_start_timeout.map(Into::into),
149
+ start_to_close_timeout: self.start_to_close_timeout.map(Into::into),
150
+ ..Default::default()
151
+ }
152
+ }
153
+ }
154
+
155
+ /// Options for scheduling a child workflow
156
+ #[derive(Default, Debug, Clone)]
157
+ pub struct ChildWorkflowOptions {
158
+ /// Workflow ID
159
+ pub workflow_id: String,
160
+ /// Type of workflow to schedule
161
+ pub workflow_type: String,
162
+ /// Input to send the child Workflow
163
+ pub input: Vec<Payload>,
164
+ /// Cancellation strategy for the child workflow
165
+ pub cancel_type: ChildWorkflowCancellationType,
166
+ }
167
+
168
+ impl IntoWorkflowCommand for ChildWorkflowOptions {
169
+ type WFCommandType = StartChildWorkflowExecution;
170
+ fn into_command(self, seq: u32) -> StartChildWorkflowExecution {
171
+ StartChildWorkflowExecution {
172
+ seq,
173
+ workflow_id: self.workflow_id,
174
+ workflow_type: self.workflow_type,
175
+ input: self.input,
176
+ cancellation_type: self.cancel_type as i32,
177
+ ..Default::default()
178
+ }
179
+ }
180
+ }