temporalio 0.0.1 → 0.0.2

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 (232) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +175 -4
  3. data/bridge/Cargo.lock +44 -21
  4. data/bridge/Cargo.toml +1 -0
  5. data/bridge/sdk-core/Cargo.toml +1 -1
  6. data/bridge/sdk-core/README.md +1 -4
  7. data/bridge/sdk-core/client/Cargo.toml +1 -1
  8. data/bridge/sdk-core/client/src/lib.rs +12 -20
  9. data/bridge/sdk-core/client/src/raw.rs +9 -8
  10. data/bridge/sdk-core/client/src/retry.rs +100 -23
  11. data/bridge/sdk-core/core/Cargo.toml +7 -7
  12. data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
  13. data/bridge/sdk-core/core/src/abstractions.rs +22 -22
  14. data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +146 -43
  15. data/bridge/sdk-core/core/src/core_tests/local_activities.rs +419 -9
  16. data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -89
  17. data/bridge/sdk-core/core/src/core_tests/workers.rs +2 -2
  18. data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
  19. data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +47 -27
  20. data/bridge/sdk-core/core/src/lib.rs +139 -32
  21. data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
  22. data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
  23. data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
  24. data/bridge/sdk-core/core/src/telemetry/metrics.rs +184 -139
  25. data/bridge/sdk-core/core/src/telemetry/mod.rs +310 -315
  26. data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +4 -3
  27. data/bridge/sdk-core/core/src/test_help/mod.rs +23 -9
  28. data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +12 -6
  29. data/bridge/sdk-core/core/src/worker/activities.rs +40 -23
  30. data/bridge/sdk-core/core/src/worker/client/mocks.rs +1 -1
  31. data/bridge/sdk-core/core/src/worker/client.rs +30 -4
  32. data/bridge/sdk-core/core/src/worker/mod.rs +23 -19
  33. data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +10 -19
  34. data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +99 -25
  35. data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -5
  36. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +1 -5
  37. data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +1 -5
  38. data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +3 -5
  39. data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +1 -5
  40. data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +2 -6
  41. data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +1 -5
  42. data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +24 -22
  43. data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -38
  44. data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
  45. data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +1 -5
  46. data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +1 -5
  47. data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -5
  48. data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +8 -2
  49. data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +1 -5
  50. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +1 -1
  51. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +233 -217
  52. data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +1 -6
  53. data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +4 -4
  54. data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +13 -5
  55. data/bridge/sdk-core/core/src/worker/workflow/mod.rs +86 -29
  56. data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +2 -2
  57. data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +56 -11
  58. data/bridge/sdk-core/core-api/Cargo.toml +4 -3
  59. data/bridge/sdk-core/core-api/src/lib.rs +1 -43
  60. data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
  61. data/bridge/sdk-core/core-api/src/worker.rs +13 -0
  62. data/bridge/sdk-core/etc/deps.svg +115 -140
  63. data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
  64. data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  65. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
  66. data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
  67. data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
  68. data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
  69. data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
  70. data/bridge/sdk-core/protos/api_upstream/{temporal/api/update/v1/message.proto → build/tools.go} +6 -23
  71. data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
  72. data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
  73. data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +20 -19
  74. data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +2 -2
  75. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
  76. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -4
  77. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
  78. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +5 -3
  79. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +23 -2
  80. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/{cluster.proto → interaction_type.proto} +10 -11
  81. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
  82. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
  83. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
  84. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
  85. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
  86. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +2 -13
  87. data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
  88. data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
  89. data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
  90. data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
  91. data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +26 -19
  92. data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
  93. data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -2
  94. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +21 -61
  95. data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
  96. data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
  97. data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
  98. data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
  99. data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
  100. data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
  101. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
  102. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -16
  103. data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +17 -3
  104. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
  105. data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +8 -1
  106. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
  107. data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
  108. data/bridge/sdk-core/sdk/Cargo.toml +2 -2
  109. data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
  110. data/bridge/sdk-core/sdk/src/lib.rs +7 -5
  111. data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
  112. data/bridge/sdk-core/sdk/src/workflow_future.rs +3 -7
  113. data/bridge/sdk-core/sdk-core-protos/Cargo.toml +1 -1
  114. data/bridge/sdk-core/sdk-core-protos/build.rs +0 -1
  115. data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +65 -18
  116. data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +22 -22
  117. data/bridge/sdk-core/sdk-core-protos/src/lib.rs +104 -44
  118. data/bridge/sdk-core/test-utils/Cargo.toml +2 -1
  119. data/bridge/sdk-core/test-utils/src/lib.rs +81 -29
  120. data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -2
  121. data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
  122. data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -13
  123. data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +167 -13
  124. data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
  125. data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +106 -20
  126. data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +18 -8
  127. data/bridge/sdk-core/tests/main.rs +6 -4
  128. data/bridge/src/connection.rs +81 -62
  129. data/bridge/src/lib.rs +92 -33
  130. data/bridge/src/runtime.rs +9 -2
  131. data/bridge/src/worker.rs +53 -2
  132. data/lib/bridge.so +0 -0
  133. data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
  134. data/lib/gen/temporal/api/command/v1/message_pb.rb +17 -9
  135. data/lib/gen/temporal/api/common/v1/message_pb.rb +1 -1
  136. data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
  137. data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -1
  138. data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
  139. data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +3 -2
  140. data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +7 -1
  141. data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
  142. data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
  143. data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
  144. data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
  145. data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
  146. data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
  147. data/lib/gen/temporal/api/enums/v1/update_pb.rb +1 -6
  148. data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
  149. data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
  150. data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
  151. data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
  152. data/lib/gen/temporal/api/history/v1/message_pb.rb +19 -18
  153. data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
  154. data/lib/gen/temporal/api/namespace/v1/message_pb.rb +1 -1
  155. data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +11 -51
  156. data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
  157. data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
  158. data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
  159. data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
  160. data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
  161. data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
  162. data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
  163. data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +27 -10
  164. data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
  165. data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +1 -0
  166. data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +5 -1
  167. data/lib/temporalio/activity/context.rb +97 -0
  168. data/lib/temporalio/activity/info.rb +67 -0
  169. data/lib/temporalio/activity.rb +85 -0
  170. data/lib/temporalio/bridge/error.rb +8 -0
  171. data/lib/temporalio/bridge.rb +14 -0
  172. data/lib/{temporal → temporalio}/client/implementation.rb +49 -48
  173. data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
  174. data/lib/{temporal → temporalio}/client.rb +19 -32
  175. data/lib/{temporal → temporalio}/connection.rb +238 -223
  176. data/lib/{temporal → temporalio}/data_converter.rb +76 -35
  177. data/lib/{temporal → temporalio}/error/failure.rb +6 -6
  178. data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
  179. data/lib/{temporal → temporalio}/errors.rb +19 -1
  180. data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
  181. data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
  182. data/lib/temporalio/failure_converter.rb +7 -0
  183. data/lib/{temporal → temporalio}/interceptor/chain.rb +2 -1
  184. data/lib/{temporal → temporalio}/interceptor/client.rb +22 -1
  185. data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
  186. data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
  187. data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
  188. data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
  189. data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
  190. data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
  191. data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
  192. data/lib/temporalio/payload_converter.rb +14 -0
  193. data/lib/{temporal → temporalio}/retry_policy.rb +4 -4
  194. data/lib/{temporal → temporalio}/retry_state.rb +1 -1
  195. data/lib/temporalio/runtime.rb +25 -0
  196. data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
  197. data/lib/temporalio/version.rb +3 -0
  198. data/lib/temporalio/worker/activity_runner.rb +92 -0
  199. data/lib/temporalio/worker/activity_worker.rb +138 -0
  200. data/lib/temporalio/worker/reactor.rb +46 -0
  201. data/lib/temporalio/worker/runner.rb +63 -0
  202. data/lib/temporalio/worker/sync_worker.rb +88 -0
  203. data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
  204. data/lib/temporalio/worker.rb +198 -0
  205. data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
  206. data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
  207. data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
  208. data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
  209. data/lib/temporalio.rb +12 -3
  210. data/temporalio.gemspec +7 -3
  211. metadata +79 -56
  212. data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
  213. data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
  214. data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
  215. data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
  216. data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
  217. data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
  218. data/bridge/sdk-core/core/src/log_export.rs +0 -62
  219. data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
  220. data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
  221. data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
  222. data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
  223. data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
  224. data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
  225. data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
  226. data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -26
  227. data/lib/temporal/bridge.rb +0 -14
  228. data/lib/temporal/failure_converter.rb +0 -8
  229. data/lib/temporal/payload_converter.rb +0 -14
  230. data/lib/temporal/runtime.rb +0 -22
  231. data/lib/temporal/version.rb +0 -3
  232. data/lib/temporal.rb +0 -8
@@ -1,7 +1,11 @@
1
1
  //! User-definable interceptors are defined in this module
2
2
 
3
3
  use crate::Worker;
4
- use temporal_sdk_core_protos::coresdk::workflow_completion::WorkflowActivationCompletion;
4
+ use anyhow::bail;
5
+ use temporal_sdk_core_protos::coresdk::{
6
+ workflow_activation::{remove_from_cache::EvictionReason, WorkflowActivation},
7
+ workflow_completion::WorkflowActivationCompletion,
8
+ };
5
9
 
6
10
  /// Implementors can intercept certain actions that happen within the Worker.
7
11
  ///
@@ -10,8 +14,37 @@ use temporal_sdk_core_protos::coresdk::workflow_completion::WorkflowActivationCo
10
14
  pub trait WorkerInterceptor {
11
15
  /// Called every time a workflow activation completes (just before sending the completion to
12
16
  /// core).
13
- async fn on_workflow_activation_completion(&self, completion: &WorkflowActivationCompletion);
17
+ async fn on_workflow_activation_completion(&self, _completion: &WorkflowActivationCompletion) {}
14
18
  /// Called after the worker has initiated shutdown and the workflow/activity polling loops
15
19
  /// have exited, but just before waiting for the inner core worker shutdown
16
- fn on_shutdown(&self, sdk_worker: &Worker);
20
+ fn on_shutdown(&self, _sdk_worker: &Worker) {}
21
+ /// Called every time a workflow is about to be activated
22
+ async fn on_workflow_activation(
23
+ &self,
24
+ _activation: &WorkflowActivation,
25
+ ) -> Result<(), anyhow::Error> {
26
+ Ok(())
27
+ }
28
+ }
29
+
30
+ /// An interceptor which causes the worker's run function to exit early if nondeterminism errors are
31
+ /// encountered
32
+ pub struct FailOnNondeterminismInterceptor {}
33
+ #[async_trait::async_trait(?Send)]
34
+ impl WorkerInterceptor for FailOnNondeterminismInterceptor {
35
+ async fn on_workflow_activation(
36
+ &self,
37
+ activation: &WorkflowActivation,
38
+ ) -> Result<(), anyhow::Error> {
39
+ if matches!(
40
+ activation.eviction_reason(),
41
+ Some(EvictionReason::Nondeterminism)
42
+ ) {
43
+ bail!(
44
+ "Workflow is being evicted because of nondeterminism! {}",
45
+ activation
46
+ );
47
+ }
48
+ Ok(())
49
+ }
17
50
  }
@@ -10,8 +10,8 @@
10
10
  //! ```no_run
11
11
  //! use std::{str::FromStr, sync::Arc};
12
12
  //! use temporal_sdk::{sdk_client_options, ActContext, Worker};
13
- //! use temporal_sdk_core::{init_worker, telemetry_init, TelemetryOptionsBuilder, Url};
14
- //! use temporal_sdk_core_api::worker::WorkerConfigBuilder;
13
+ //! use temporal_sdk_core::{init_worker, Url, CoreRuntime};
14
+ //! use temporal_sdk_core_api::{worker::WorkerConfigBuilder, telemetry::TelemetryOptionsBuilder};
15
15
  //!
16
16
  //! #[tokio::main]
17
17
  //! async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -20,14 +20,14 @@
20
20
  //! let client = server_options.connect("default", None, None).await?;
21
21
  //!
22
22
  //! let telemetry_options = TelemetryOptionsBuilder::default().build()?;
23
- //! telemetry_init(&telemetry_options)?;
23
+ //! let runtime = CoreRuntime::new_assume_tokio(telemetry_options)?;
24
24
  //!
25
25
  //! let worker_config = WorkerConfigBuilder::default()
26
26
  //! .namespace("default")
27
27
  //! .task_queue("task_queue")
28
28
  //! .build()?;
29
29
  //!
30
- //! let core_worker = init_worker(worker_config, client);
30
+ //! let core_worker = init_worker(&runtime, worker_config, client)?;
31
31
  //!
32
32
  //! let mut worker = Worker::new_from_core(Arc::new(core_worker), "task_queue");
33
33
  //! worker.register_activity(
@@ -46,7 +46,6 @@ extern crate tracing;
46
46
 
47
47
  mod activity_context;
48
48
  mod app_data;
49
- mod conversions;
50
49
  pub mod interceptors;
51
50
  mod payload_converter;
52
51
  mod workflow_context;
@@ -279,6 +278,9 @@ impl Worker {
279
278
  }
280
279
  o => o?,
281
280
  };
281
+ if let Some(ref i) = common.worker_interceptor {
282
+ i.on_workflow_activation(&activation).await?;
283
+ }
282
284
  if let Some(wf_fut) = wf_half.workflow_activation_handler(
283
285
  common,
284
286
  shutdown_token.clone(),
@@ -34,11 +34,11 @@ use temporal_sdk_core_protos::{
34
34
  workflow_commands::{
35
35
  request_cancel_external_workflow_execution as cancel_we,
36
36
  signal_external_workflow_execution as sig_we, workflow_command,
37
- RequestCancelExternalWorkflowExecution, SetPatchMarker,
37
+ ModifyWorkflowProperties, RequestCancelExternalWorkflowExecution, SetPatchMarker,
38
38
  SignalExternalWorkflowExecution, StartTimer, UpsertWorkflowSearchAttributes,
39
39
  },
40
40
  },
41
- temporal::api::common::v1::Payload,
41
+ temporal::api::common::v1::{Memo, Payload},
42
42
  };
43
43
  use tokio::sync::{mpsc, oneshot, watch};
44
44
  use tokio_stream::wrappers::UnboundedReceiverStream;
@@ -297,6 +297,17 @@ impl WfContext {
297
297
  ))
298
298
  }
299
299
 
300
+ /// Add or create a set of search attributes
301
+ pub fn upsert_memo(&self, attr_iter: impl IntoIterator<Item = (String, Payload)>) {
302
+ self.send(RustWfCmd::NewNonblockingCmd(
303
+ workflow_command::Variant::ModifyWorkflowProperties(ModifyWorkflowProperties {
304
+ upserted_memo: Some(Memo {
305
+ fields: HashMap::from_iter(attr_iter.into_iter()),
306
+ }),
307
+ }),
308
+ ))
309
+ }
310
+
300
311
  /// Return a stream that produces values when the named signal is sent to this workflow
301
312
  pub fn make_signal_channel(&self, signal_name: impl Into<String>) -> DrainableSignalStream {
302
313
  let (tx, rx) = mpsc::unbounded_channel();
@@ -1,7 +1,6 @@
1
1
  use crate::{
2
- conversions::anyhow_to_fail, workflow_context::WfContextSharedData, CancellableID, RustWfCmd,
3
- SignalData, TimerResult, UnblockEvent, WfContext, WfExitValue, WorkflowFunction,
4
- WorkflowResult,
2
+ workflow_context::WfContextSharedData, CancellableID, RustWfCmd, SignalData, TimerResult,
3
+ UnblockEvent, WfContext, WfExitValue, WorkflowFunction, WorkflowResult,
5
4
  };
6
5
  use anyhow::{anyhow, bail, Context as AnyhowContext, Error};
7
6
  use crossbeam::channel::Receiver;
@@ -132,10 +131,7 @@ impl WorkflowFuture {
132
131
  fn fail_wft(&self, run_id: String, fail: Error) {
133
132
  warn!("Workflow task failed for {}: {}", run_id, fail);
134
133
  self.outgoing_completions
135
- .send(WorkflowActivationCompletion::fail(
136
- run_id,
137
- anyhow_to_fail(fail),
138
- ))
134
+ .send(WorkflowActivationCompletion::fail(run_id, fail.into()))
139
135
  .expect("Completion channel intact");
140
136
  }
141
137
 
@@ -15,7 +15,7 @@ history_builders = ["uuid", "rand"]
15
15
 
16
16
  [dependencies]
17
17
  anyhow = "1.0"
18
- base64 = "0.13"
18
+ base64 = "0.20"
19
19
  derive_more = "0.99"
20
20
  prost = "0.11"
21
21
  prost-types = "0.11"
@@ -91,7 +91,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
91
91
  .compile(
92
92
  &[
93
93
  "../protos/local/temporal/sdk/core/core_interface.proto",
94
- "../protos/local/temporal/sdk/core/bridge/bridge.proto",
95
94
  "../protos/api_upstream/temporal/api/workflowservice/v1/service.proto",
96
95
  "../protos/api_upstream/temporal/api/operatorservice/v1/service.proto",
97
96
  "../protos/testsrv_upstream/temporal/api/testservice/v1/service.proto",
@@ -10,9 +10,10 @@ use crate::{
10
10
  },
11
11
  temporal::api::{
12
12
  common::v1::{Payload, Payloads, WorkflowExecution, WorkflowType},
13
- enums::v1::{EventType, WorkflowTaskFailedCause},
13
+ enums::v1::{EventType, TaskQueueKind, WorkflowTaskFailedCause},
14
14
  failure::v1::{failure, CanceledFailureInfo, Failure},
15
15
  history::v1::{history_event::Attributes, *},
16
+ taskqueue::v1::TaskQueue,
16
17
  },
17
18
  HistoryInfo,
18
19
  };
@@ -38,6 +39,27 @@ pub struct TestHistoryBuilder {
38
39
  }
39
40
 
40
41
  impl TestHistoryBuilder {
42
+ pub fn from_history(events: Vec<HistoryEvent>) -> Self {
43
+ let find_matching_id = |etype: EventType| {
44
+ events
45
+ .iter()
46
+ .rev()
47
+ .find(|e| e.event_type() == etype)
48
+ .map(|e| e.event_id)
49
+ .unwrap_or_default()
50
+ };
51
+ Self {
52
+ current_event_id: events.last().map(|e| e.event_id).unwrap_or_default(),
53
+ workflow_task_scheduled_event_id: find_matching_id(EventType::WorkflowTaskScheduled),
54
+ final_workflow_task_started_event_id: find_matching_id(EventType::WorkflowTaskStarted),
55
+ previous_task_completed_id: find_matching_id(EventType::WorkflowTaskCompleted),
56
+ original_run_id: extract_original_run_id_from_events(&events)
57
+ .expect("Run id must be discoverable")
58
+ .to_string(),
59
+ events,
60
+ }
61
+ }
62
+
41
63
  /// Add an event by type with attributes. Bundles both into a [HistoryEvent] with an id that is
42
64
  /// incremented on each call to add.
43
65
  pub fn add(&mut self, event_type: EventType, attribs: Attributes) {
@@ -270,22 +292,21 @@ impl TestHistoryBuilder {
270
292
  activity_id: &str,
271
293
  payload: Option<Payload>,
272
294
  failure: Option<Failure>,
273
- complete_time: Option<Timestamp>,
295
+ detail_mutator: impl FnOnce(&mut LocalActivityMarkerData),
274
296
  ) {
297
+ let mut lamd = LocalActivityMarkerData {
298
+ seq,
299
+ attempt: 1,
300
+ activity_id: activity_id.to_string(),
301
+ activity_type: "some_act_type".to_string(),
302
+ complete_time: None,
303
+ backoff: None,
304
+ original_schedule_time: None,
305
+ };
306
+ detail_mutator(&mut lamd);
275
307
  let attrs = MarkerRecordedEventAttributes {
276
308
  marker_name: LOCAL_ACTIVITY_MARKER_NAME.to_string(),
277
- details: build_local_activity_marker_details(
278
- LocalActivityMarkerData {
279
- seq,
280
- attempt: 1,
281
- activity_id: activity_id.to_string(),
282
- activity_type: "some_act_type".to_string(),
283
- complete_time,
284
- backoff: None,
285
- original_schedule_time: None,
286
- },
287
- payload,
288
- ),
309
+ details: build_local_activity_marker_details(lamd, payload),
289
310
  workflow_task_completed_event_id: self.previous_task_completed_id,
290
311
  failure,
291
312
  ..Default::default()
@@ -299,7 +320,7 @@ impl TestHistoryBuilder {
299
320
  activity_id: &str,
300
321
  payload: Payload,
301
322
  ) {
302
- self.add_local_activity_marker(seq, activity_id, Some(payload), None, None);
323
+ self.add_local_activity_marker(seq, activity_id, Some(payload), None, |_| {});
303
324
  }
304
325
 
305
326
  pub fn add_local_activity_result_marker_with_time(
@@ -309,7 +330,9 @@ impl TestHistoryBuilder {
309
330
  payload: Payload,
310
331
  complete_time: Timestamp,
311
332
  ) {
312
- self.add_local_activity_marker(seq, activity_id, Some(payload), None, Some(complete_time));
333
+ self.add_local_activity_marker(seq, activity_id, Some(payload), None, |d| {
334
+ d.complete_time = Some(complete_time)
335
+ });
313
336
  }
314
337
 
315
338
  pub fn add_local_activity_fail_marker(
@@ -318,7 +341,7 @@ impl TestHistoryBuilder {
318
341
  activity_id: &str,
319
342
  failure: Failure,
320
343
  ) {
321
- self.add_local_activity_marker(seq, activity_id, None, Some(failure), None);
344
+ self.add_local_activity_marker(seq, activity_id, None, Some(failure), |_| {});
322
345
  }
323
346
 
324
347
  pub fn add_local_activity_cancel_marker(&mut self, seq: u32, activity_id: &str) {
@@ -336,7 +359,7 @@ impl TestHistoryBuilder {
336
359
  )),
337
360
  encoded_attributes: Default::default(),
338
361
  }),
339
- None,
362
+ |_| {},
340
363
  );
341
364
  }
342
365
 
@@ -450,6 +473,26 @@ impl TestHistoryBuilder {
450
473
  .unwrap()
451
474
  }
452
475
 
476
+ /// Alter the workflow type of the history
477
+ pub fn set_wf_type(&mut self, name: &str) {
478
+ if let Some(Attributes::WorkflowExecutionStartedEventAttributes(wes)) =
479
+ self.events.get_mut(0).and_then(|e| e.attributes.as_mut())
480
+ {
481
+ wes.workflow_type = Some(WorkflowType {
482
+ name: name.to_string(),
483
+ })
484
+ }
485
+ }
486
+
487
+ /// Alter some specific event. You can easily craft nonsense histories this way, use carefully.
488
+ pub fn modify_event(&mut self, event_id: i64, modifier: impl FnOnce(&mut HistoryEvent)) {
489
+ let he = self
490
+ .events
491
+ .get_mut((event_id - 1) as usize)
492
+ .expect("Event must be present");
493
+ modifier(he);
494
+ }
495
+
453
496
  fn build_and_push_event(&mut self, event_type: EventType, attribs: Attributes) {
454
497
  self.current_event_id += 1;
455
498
  let evt = HistoryEvent {
@@ -492,6 +535,10 @@ pub fn default_wes_attribs() -> WorkflowExecutionStartedEventAttributes {
492
535
  .try_into()
493
536
  .expect("5 secs is a valid duration"),
494
537
  ),
538
+ task_queue: Some(TaskQueue {
539
+ name: "q".to_string(),
540
+ kind: TaskQueueKind::Normal as i32,
541
+ }),
495
542
  ..Default::default()
496
543
  }
497
544
  }
@@ -1,7 +1,7 @@
1
1
  use crate::temporal::api::{
2
2
  common::v1::WorkflowType,
3
3
  enums::v1::{EventType, TaskQueueKind},
4
- history::v1::{history_event, History, HistoryEvent},
4
+ history::v1::{history_event, History, HistoryEvent, WorkflowExecutionStartedEventAttributes},
5
5
  taskqueue::v1::TaskQueue,
6
6
  workflowservice::v1::{GetWorkflowExecutionHistoryResponse, PollWorkflowTaskQueueResponse},
7
7
  };
@@ -18,6 +18,7 @@ pub struct HistoryInfo {
18
18
  events: Vec<HistoryEvent>,
19
19
  wf_task_count: usize,
20
20
  wf_type: String,
21
+ wf_exe_started_attrs: WorkflowExecutionStartedEventAttributes,
21
22
  }
22
23
 
23
24
  type Result<T, E = anyhow::Error> = std::result::Result<T, E>;
@@ -36,20 +37,18 @@ impl HistoryInfo {
36
37
  let mut workflow_task_started_event_id = 0;
37
38
  let mut wf_task_count = 0;
38
39
  let mut history = events.iter().peekable();
39
-
40
- let wf_type = match &events.get(0).unwrap().attributes {
40
+ let started_attrs = match &events.get(0).unwrap().attributes {
41
41
  Some(history_event::Attributes::WorkflowExecutionStartedEventAttributes(attrs)) => {
42
- attrs
43
- .workflow_type
44
- .as_ref()
45
- .ok_or_else(|| {
46
- anyhow!("No workflow type defined in execution started attributes")
47
- })?
48
- .name
49
- .clone()
42
+ attrs.clone()
50
43
  }
51
44
  _ => bail!("First event in history was not workflow execution started!"),
52
45
  };
46
+ let wf_type = started_attrs
47
+ .workflow_type
48
+ .as_ref()
49
+ .ok_or_else(|| anyhow!("No workflow type defined in execution started attributes"))?
50
+ .name
51
+ .clone();
53
52
 
54
53
  let mut events = vec![];
55
54
  while let Some(event) = history.next() {
@@ -87,6 +86,7 @@ impl HistoryInfo {
87
86
  events,
88
87
  wf_task_count,
89
88
  wf_type,
89
+ wf_exe_started_attrs: started_attrs,
90
90
  });
91
91
  }
92
92
  } else if next_event.is_some() && !next_is_failed_or_timeout_or_term {
@@ -108,6 +108,7 @@ impl HistoryInfo {
108
108
  events,
109
109
  wf_task_count,
110
110
  wf_type,
111
+ wf_exe_started_attrs: started_attrs,
111
112
  });
112
113
  }
113
114
  // No more events
@@ -135,16 +136,9 @@ impl HistoryInfo {
135
136
  &self.events
136
137
  }
137
138
 
138
- /// Attempt to extract run id from internal events. If the first event is not workflow execution
139
- /// started, it will panic.
139
+ /// Extract run id from the workflow execution started attributes.
140
140
  pub fn orig_run_id(&self) -> &str {
141
- if let Some(history_event::Attributes::WorkflowExecutionStartedEventAttributes(wes)) =
142
- &self.events[0].attributes
143
- {
144
- &wes.original_execution_run_id
145
- } else {
146
- panic!("First event is wrong type")
147
- }
141
+ &self.wf_exe_started_attrs.original_execution_run_id
148
142
  }
149
143
 
150
144
  /// Return total workflow task count in this history
@@ -155,7 +149,7 @@ impl HistoryInfo {
155
149
  /// Create a workflow task polling response containing all the events in this history and a
156
150
  /// randomly generated task token. Caller should attach a meaningful `workflow_execution` if
157
151
  /// needed.
158
- pub fn as_poll_wft_response(&self, task_q: impl Into<String>) -> PollWorkflowTaskQueueResponse {
152
+ pub fn as_poll_wft_response(&self) -> PollWorkflowTaskQueueResponse {
159
153
  let task_token: [u8; 16] = thread_rng().gen();
160
154
  PollWorkflowTaskQueueResponse {
161
155
  history: Some(History {
@@ -166,7 +160,13 @@ impl HistoryInfo {
166
160
  name: self.wf_type.clone(),
167
161
  }),
168
162
  workflow_execution_task_queue: Some(TaskQueue {
169
- name: task_q.into(),
163
+ name: self
164
+ .wf_exe_started_attrs
165
+ .task_queue
166
+ .as_ref()
167
+ .unwrap()
168
+ .name
169
+ .clone(),
170
170
  kind: TaskQueueKind::Normal as i32,
171
171
  }),
172
172
  previous_started_event_id: self.previous_started_event_id,