temporalio 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +180 -7
- data/bridge/Cargo.lock +208 -76
- data/bridge/Cargo.toml +5 -2
- data/bridge/sdk-core/Cargo.toml +1 -1
- data/bridge/sdk-core/README.md +20 -10
- data/bridge/sdk-core/client/Cargo.toml +1 -1
- data/bridge/sdk-core/client/src/lib.rs +227 -59
- data/bridge/sdk-core/client/src/metrics.rs +17 -8
- data/bridge/sdk-core/client/src/raw.rs +13 -12
- data/bridge/sdk-core/client/src/retry.rs +132 -43
- data/bridge/sdk-core/core/Cargo.toml +28 -15
- data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
- data/bridge/sdk-core/core/src/abstractions.rs +225 -36
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +217 -79
- data/bridge/sdk-core/core/src/core_tests/determinism.rs +165 -2
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +565 -34
- data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -90
- data/bridge/sdk-core/core/src/core_tests/workers.rs +3 -5
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +430 -67
- data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +106 -12
- data/bridge/sdk-core/core/src/internal_flags.rs +136 -0
- data/bridge/sdk-core/core/src/lib.rs +148 -34
- 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 +219 -140
- data/bridge/sdk-core/core/src/telemetry/mod.rs +326 -315
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +20 -14
- data/bridge/sdk-core/core/src/test_help/mod.rs +85 -21
- data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +112 -156
- data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +364 -128
- data/bridge/sdk-core/core/src/worker/activities.rs +263 -170
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +23 -3
- data/bridge/sdk-core/core/src/worker/client.rs +48 -6
- data/bridge/sdk-core/core/src/worker/mod.rs +186 -75
- data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +13 -24
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +879 -226
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +101 -48
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -12
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +90 -32
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -10
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +160 -83
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +36 -54
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +179 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +104 -157
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +8 -12
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +9 -13
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +10 -4
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +14 -11
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +395 -299
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +12 -20
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +33 -18
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +1032 -374
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +525 -392
- data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
- data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +125 -0
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -6
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +456 -681
- data/bridge/sdk-core/core-api/Cargo.toml +6 -4
- data/bridge/sdk-core/core-api/src/errors.rs +1 -34
- data/bridge/sdk-core/core-api/src/lib.rs +7 -45
- data/bridge/sdk-core/core-api/src/telemetry.rs +141 -0
- data/bridge/sdk-core/core-api/src/worker.rs +27 -1
- 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/src/lib.rs +18 -15
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +8 -3
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
- 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/enums/v1/cluster.proto → build/tools.go} +7 -18
- 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 +15 -26
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -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 -9
- 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 +10 -8
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +28 -2
- 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 +24 -19
- 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 +62 -26
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +24 -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/protocol/v1/message.proto +57 -0
- 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/sdk/v1/task_complete_metadata.proto +63 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
- 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 +111 -36
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +19 -5
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +9 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +9 -1
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +6 -0
- 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 +4 -3
- data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
- data/bridge/sdk-core/sdk/src/lib.rs +94 -25
- data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
- data/bridge/sdk-core/sdk/src/workflow_future.rs +10 -13
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +5 -2
- data/bridge/sdk-core/sdk-core-protos/build.rs +36 -2
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +164 -104
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +27 -23
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +252 -74
- data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
- data/bridge/sdk-core/test-utils/Cargo.toml +4 -1
- data/bridge/sdk-core/test-utils/src/canned_histories.rs +106 -296
- data/bridge/sdk-core/test-utils/src/histfetch.rs +1 -1
- data/bridge/sdk-core/test-utils/src/lib.rs +161 -50
- data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
- data/bridge/sdk-core/test-utils/src/workflows.rs +29 -0
- data/bridge/sdk-core/tests/fuzzy_workflow.rs +130 -0
- data/bridge/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
- data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +239 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +4 -60
- data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
- data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -69
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +151 -116
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +54 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +7 -28
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +115 -24
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -4
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +27 -18
- data/bridge/sdk-core/tests/main.rs +8 -16
- data/bridge/sdk-core/tests/runner.rs +75 -36
- data/bridge/sdk-core/tests/wf_input_replay.rs +32 -0
- data/bridge/src/connection.rs +117 -82
- data/bridge/src/lib.rs +356 -42
- data/bridge/src/runtime.rs +10 -3
- data/bridge/src/test_server.rs +153 -0
- data/bridge/src/worker.rs +133 -9
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
- data/lib/gen/temporal/api/command/v1/message_pb.rb +10 -16
- data/lib/gen/temporal/api/common/v1/message_pb.rb +5 -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 -3
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +5 -4
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +9 -1
- 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 +7 -10
- 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 +34 -25
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +2 -1
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +14 -51
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/api/protocol/v1/message_pb.rb +30 -0
- 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/sdk/v1/task_complete_metadata_pb.rb +23 -0
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
- data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +49 -0
- data/lib/gen/temporal/api/testservice/v1/service_pb.rb +21 -0
- data/lib/gen/temporal/api/update/v1/message_pb.rb +49 -3
- 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 +47 -20
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +13 -9
- data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +10 -6
- data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +13 -9
- data/lib/gen/temporal/sdk/core/common/common_pb.rb +7 -3
- data/lib/gen/temporal/sdk/core/core_interface_pb.rb +9 -3
- data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +7 -3
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +28 -21
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +32 -24
- data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +12 -5
- data/lib/temporalio/activity/context.rb +102 -0
- data/lib/temporalio/activity/info.rb +67 -0
- data/lib/temporalio/activity.rb +85 -0
- data/lib/temporalio/bridge/connect_options.rb +15 -0
- data/lib/temporalio/bridge/error.rb +8 -0
- data/lib/temporalio/bridge/retry_config.rb +24 -0
- data/lib/temporalio/bridge/tls_options.rb +19 -0
- data/lib/temporalio/bridge.rb +14 -0
- data/lib/{temporal → temporalio}/client/implementation.rb +57 -56
- data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
- data/lib/{temporal → temporalio}/client.rb +19 -32
- data/lib/temporalio/connection/retry_config.rb +44 -0
- data/lib/temporalio/connection/service.rb +20 -0
- data/lib/temporalio/connection/test_service.rb +92 -0
- data/lib/temporalio/connection/tls_options.rb +51 -0
- data/lib/temporalio/connection/workflow_service.rb +731 -0
- data/lib/temporalio/connection.rb +86 -0
- 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/temporalio/interceptor/activity_inbound.rb +22 -0
- data/lib/temporalio/interceptor/activity_outbound.rb +24 -0
- data/lib/{temporal → temporalio}/interceptor/chain.rb +7 -6
- data/lib/{temporal → temporalio}/interceptor/client.rb +27 -2
- data/lib/temporalio/interceptor.rb +22 -0
- 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 +17 -7
- data/lib/{temporal → temporalio}/retry_state.rb +1 -1
- data/lib/temporalio/runtime.rb +25 -0
- data/lib/temporalio/testing/time_skipping_handle.rb +32 -0
- data/lib/temporalio/testing/time_skipping_interceptor.rb +23 -0
- data/lib/temporalio/testing/workflow_environment.rb +112 -0
- data/lib/temporalio/testing.rb +175 -0
- data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
- data/lib/temporalio/version.rb +3 -0
- data/lib/temporalio/worker/activity_runner.rb +114 -0
- data/lib/temporalio/worker/activity_worker.rb +164 -0
- data/lib/temporalio/worker/reactor.rb +46 -0
- data/lib/temporalio/worker/runner.rb +63 -0
- data/lib/temporalio/worker/sync_worker.rb +124 -0
- data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
- data/lib/temporalio/worker.rb +204 -0
- data/lib/temporalio/workflow/async.rb +46 -0
- data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
- data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
- data/lib/temporalio/workflow/future.rb +138 -0
- data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
- data/lib/temporalio/workflow/info.rb +76 -0
- data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
- data/lib/temporalio.rb +12 -3
- data/temporalio.gemspec +11 -6
- metadata +137 -64
- data/bridge/sdk-core/Cargo.lock +0 -2606
- 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/bridge.so +0 -0
- 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/sdk/core/bridge/bridge_pb.rb +0 -222
- data/lib/temporal/bridge.rb +0 -14
- data/lib/temporal/connection.rb +0 -736
- 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
@@ -23,6 +23,9 @@ use std::os::unix::fs::OpenOptionsExt;
|
|
23
23
|
use std::process::Stdio;
|
24
24
|
|
25
25
|
/// Configuration for Temporalite.
|
26
|
+
/// Will be removed eventually as its successor, Temporal CLI matures.
|
27
|
+
/// We don't care for the duplication between this struct and [TemporalDevServerConfig] and prefer that over another
|
28
|
+
/// abstraction since the existence of this struct is temporary.
|
26
29
|
#[derive(Debug, Clone, derive_builder::Builder)]
|
27
30
|
pub struct TemporaliteConfig {
|
28
31
|
/// Required path to executable or download info.
|
@@ -59,7 +62,10 @@ impl TemporaliteConfig {
|
|
59
62
|
/// Start a Temporalite server with configurable stdout destination.
|
60
63
|
pub async fn start_server_with_output(&self, output: Stdio) -> anyhow::Result<EphemeralServer> {
|
61
64
|
// Get exe path
|
62
|
-
let exe_path = self
|
65
|
+
let exe_path = self
|
66
|
+
.exe
|
67
|
+
.get_or_download("temporalite", "temporalite")
|
68
|
+
.await?;
|
63
69
|
|
64
70
|
// Get free port if not already given
|
65
71
|
let port = self.port.unwrap_or_else(|| get_free_port(&self.ip));
|
@@ -77,6 +83,8 @@ impl TemporaliteConfig {
|
|
77
83
|
self.log.0.clone(),
|
78
84
|
"--log-level".to_owned(),
|
79
85
|
self.log.1.clone(),
|
86
|
+
"--dynamic-config-value".to_owned(),
|
87
|
+
"frontend.enableServerVersionCheck=false".to_owned(),
|
80
88
|
];
|
81
89
|
if let Some(db_filename) = &self.db_filename {
|
82
90
|
args.push("--filename".to_owned());
|
@@ -101,6 +109,86 @@ impl TemporaliteConfig {
|
|
101
109
|
}
|
102
110
|
}
|
103
111
|
|
112
|
+
/// Configuration for Temporal CLI dev server.
|
113
|
+
#[derive(Debug, Clone, derive_builder::Builder)]
|
114
|
+
pub struct TemporalDevServerConfig {
|
115
|
+
/// Required path to executable or download info.
|
116
|
+
pub exe: EphemeralExe,
|
117
|
+
/// Namespace to use.
|
118
|
+
#[builder(default = "\"default\".to_owned()")]
|
119
|
+
pub namespace: String,
|
120
|
+
/// IP to bind to.
|
121
|
+
#[builder(default = "\"127.0.0.1\".to_owned()")]
|
122
|
+
pub ip: String,
|
123
|
+
/// Port to use or obtains a free one if none given.
|
124
|
+
#[builder(default)]
|
125
|
+
pub port: Option<u16>,
|
126
|
+
/// Sqlite DB filename if persisting or non-persistent if none.
|
127
|
+
#[builder(default)]
|
128
|
+
pub db_filename: Option<String>,
|
129
|
+
/// Whether to enable the UI.
|
130
|
+
#[builder(default)]
|
131
|
+
pub ui: bool,
|
132
|
+
/// Log format and level
|
133
|
+
#[builder(default = "(\"pretty\".to_owned(), \"warn\".to_owned())")]
|
134
|
+
pub log: (String, String),
|
135
|
+
/// Additional arguments to Temporalite.
|
136
|
+
#[builder(default)]
|
137
|
+
pub extra_args: Vec<String>,
|
138
|
+
}
|
139
|
+
|
140
|
+
impl TemporalDevServerConfig {
|
141
|
+
/// Start a Temporal CLI dev server.
|
142
|
+
pub async fn start_server(&self) -> anyhow::Result<EphemeralServer> {
|
143
|
+
self.start_server_with_output(Stdio::inherit()).await
|
144
|
+
}
|
145
|
+
|
146
|
+
/// Start a Temporal CLI dev server with configurable stdout destination.
|
147
|
+
pub async fn start_server_with_output(&self, output: Stdio) -> anyhow::Result<EphemeralServer> {
|
148
|
+
// Get exe path
|
149
|
+
let exe_path = self.exe.get_or_download("cli", "temporal").await?;
|
150
|
+
|
151
|
+
// Get free port if not already given
|
152
|
+
let port = self.port.unwrap_or_else(|| get_free_port(&self.ip));
|
153
|
+
|
154
|
+
// Build arg set
|
155
|
+
let mut args = vec![
|
156
|
+
"server".to_owned(),
|
157
|
+
"start-dev".to_owned(),
|
158
|
+
"--port".to_owned(),
|
159
|
+
port.to_string(),
|
160
|
+
"--namespace".to_owned(),
|
161
|
+
self.namespace.clone(),
|
162
|
+
"--ip".to_owned(),
|
163
|
+
self.ip.clone(),
|
164
|
+
"--log-format".to_owned(),
|
165
|
+
self.log.0.clone(),
|
166
|
+
"--log-level".to_owned(),
|
167
|
+
self.log.1.clone(),
|
168
|
+
"--dynamic-config-value".to_owned(),
|
169
|
+
"frontend.enableServerVersionCheck=false".to_owned(),
|
170
|
+
];
|
171
|
+
if let Some(db_filename) = &self.db_filename {
|
172
|
+
args.push("--filename".to_owned());
|
173
|
+
args.push(db_filename.clone());
|
174
|
+
}
|
175
|
+
if !self.ui {
|
176
|
+
args.push("--headless".to_owned());
|
177
|
+
}
|
178
|
+
args.extend(self.extra_args.clone());
|
179
|
+
|
180
|
+
// Start
|
181
|
+
EphemeralServer::start(EphemeralServerConfig {
|
182
|
+
exe_path,
|
183
|
+
port,
|
184
|
+
args,
|
185
|
+
has_test_service: false,
|
186
|
+
output,
|
187
|
+
})
|
188
|
+
.await
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
104
192
|
/// Configuration for the test server.
|
105
193
|
#[derive(Debug, Clone, derive_builder::Builder)]
|
106
194
|
pub struct TestServerConfig {
|
@@ -123,7 +211,10 @@ impl TestServerConfig {
|
|
123
211
|
/// Start a test server with configurable stdout.
|
124
212
|
pub async fn start_server_with_output(&self, output: Stdio) -> anyhow::Result<EphemeralServer> {
|
125
213
|
// Get exe path
|
126
|
-
let exe_path = self
|
214
|
+
let exe_path = self
|
215
|
+
.exe
|
216
|
+
.get_or_download("temporal-test-server", "temporal-test-server")
|
217
|
+
.await?;
|
127
218
|
|
128
219
|
// Get free port if not already given
|
129
220
|
let port = self.port.unwrap_or_else(|| get_free_port("0.0.0.0"));
|
@@ -172,7 +263,7 @@ impl EphemeralServer {
|
|
172
263
|
.stdout(config.output)
|
173
264
|
.spawn()?;
|
174
265
|
let target = format!("127.0.0.1:{}", config.port);
|
175
|
-
let target_url = format!("http://{}"
|
266
|
+
let target_url = format!("http://{target}");
|
176
267
|
let success = Ok(EphemeralServer {
|
177
268
|
target,
|
178
269
|
has_test_service: config.has_test_service,
|
@@ -262,7 +353,7 @@ pub enum EphemeralExe {
|
|
262
353
|
#[derive(Debug, Clone)]
|
263
354
|
pub enum EphemeralExeVersion {
|
264
355
|
/// Use a default version for the given SDK name and version.
|
265
|
-
|
356
|
+
SDKDefault {
|
266
357
|
/// Name of the SDK to get the default for.
|
267
358
|
sdk_name: String,
|
268
359
|
/// Version of the SDK to get the default for.
|
@@ -280,7 +371,11 @@ struct DownloadInfo {
|
|
280
371
|
}
|
281
372
|
|
282
373
|
impl EphemeralExe {
|
283
|
-
async fn get_or_download(
|
374
|
+
async fn get_or_download(
|
375
|
+
&self,
|
376
|
+
artifact_name: &str,
|
377
|
+
downloaded_name_prefix: &str,
|
378
|
+
) -> anyhow::Result<PathBuf> {
|
284
379
|
match self {
|
285
380
|
EphemeralExe::ExistingPath(exe_path) => {
|
286
381
|
let path = PathBuf::from(exe_path);
|
@@ -301,12 +396,12 @@ impl EphemeralExe {
|
|
301
396
|
};
|
302
397
|
// Create dest file based on SDK name/version or fixed version
|
303
398
|
let dest = dest_dir.join(match version {
|
304
|
-
EphemeralExeVersion::
|
399
|
+
EphemeralExeVersion::SDKDefault {
|
305
400
|
sdk_name,
|
306
401
|
sdk_version,
|
307
|
-
} => format!("{}-{}-{}{}"
|
402
|
+
} => format!("{downloaded_name_prefix}-{sdk_name}-{sdk_version}{out_ext}"),
|
308
403
|
EphemeralExeVersion::Fixed(version) => {
|
309
|
-
format!("{}-{}{}"
|
404
|
+
format!("{downloaded_name_prefix}-{version}{out_ext}")
|
310
405
|
}
|
311
406
|
});
|
312
407
|
debug!(
|
@@ -327,7 +422,7 @@ impl EphemeralExe {
|
|
327
422
|
};
|
328
423
|
let mut get_info_params = vec![("arch", arch), ("platform", platform)];
|
329
424
|
let version_name = match version {
|
330
|
-
EphemeralExeVersion::
|
425
|
+
EphemeralExeVersion::SDKDefault {
|
331
426
|
sdk_name,
|
332
427
|
sdk_version,
|
333
428
|
} => {
|
@@ -340,8 +435,7 @@ impl EphemeralExe {
|
|
340
435
|
let client = reqwest::Client::new();
|
341
436
|
let info: DownloadInfo = client
|
342
437
|
.get(format!(
|
343
|
-
"https://temporal.download/{}/{}"
|
344
|
-
artifact_name, version_name
|
438
|
+
"https://temporal.download/{artifact_name}/{version_name}"
|
345
439
|
))
|
346
440
|
.query(&get_info_params)
|
347
441
|
.send()
|
@@ -371,7 +465,7 @@ impl EphemeralExe {
|
|
371
465
|
fn get_free_port(bind_ip: &str) -> u16 {
|
372
466
|
// Can just ask OS to give us a port then close socket. OS's don't give that
|
373
467
|
// port back to anyone else anytime soon.
|
374
|
-
std::net::TcpListener::bind(format!("{}:0"
|
468
|
+
std::net::TcpListener::bind(format!("{bind_ip}:0"))
|
375
469
|
.unwrap()
|
376
470
|
.local_addr()
|
377
471
|
.unwrap()
|
@@ -0,0 +1,136 @@
|
|
1
|
+
//! Utilities for and tracking of internal versions which alter history in incompatible ways
|
2
|
+
//! so that we can use older code paths for workflows executed on older core versions.
|
3
|
+
|
4
|
+
use std::collections::{BTreeSet, HashSet};
|
5
|
+
use temporal_sdk_core_protos::temporal::api::{
|
6
|
+
history::v1::WorkflowTaskCompletedEventAttributes, sdk::v1::WorkflowTaskCompletedMetadata,
|
7
|
+
workflowservice::v1::get_system_info_response,
|
8
|
+
};
|
9
|
+
|
10
|
+
/// This enumeration contains internal flags that may result in incompatible history changes with
|
11
|
+
/// older workflows, or other breaking changes.
|
12
|
+
///
|
13
|
+
/// When a flag has existed long enough the version it was introduced in is no longer supported, it
|
14
|
+
/// may be removed from the enum. *Importantly*, all variants must be given explicit values, such
|
15
|
+
/// that removing older variants does not create any change in existing values. Removed flag
|
16
|
+
/// variants must be reserved forever (a-la protobuf), and should be called out in a comment.
|
17
|
+
#[repr(u32)]
|
18
|
+
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Clone, Debug)]
|
19
|
+
pub(crate) enum CoreInternalFlags {
|
20
|
+
/// In this flag, additional checks were added to a number of state machines to ensure that
|
21
|
+
/// the ID and type of activities, local activities, and child workflows match during replay.
|
22
|
+
IdAndTypeDeterminismChecks = 1,
|
23
|
+
/// We received a value higher than this code can understand.
|
24
|
+
TooHigh = u32::MAX,
|
25
|
+
}
|
26
|
+
|
27
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
28
|
+
pub(crate) struct InternalFlags {
|
29
|
+
enabled: bool,
|
30
|
+
core: BTreeSet<CoreInternalFlags>,
|
31
|
+
lang: BTreeSet<u32>,
|
32
|
+
core_since_last_complete: HashSet<CoreInternalFlags>,
|
33
|
+
lang_since_last_complete: HashSet<u32>,
|
34
|
+
}
|
35
|
+
|
36
|
+
impl InternalFlags {
|
37
|
+
pub fn new(server_capabilities: &get_system_info_response::Capabilities) -> Self {
|
38
|
+
Self {
|
39
|
+
enabled: server_capabilities.sdk_metadata,
|
40
|
+
core: Default::default(),
|
41
|
+
lang: Default::default(),
|
42
|
+
core_since_last_complete: Default::default(),
|
43
|
+
lang_since_last_complete: Default::default(),
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
pub fn add_from_complete(&mut self, e: &WorkflowTaskCompletedEventAttributes) {
|
48
|
+
if !self.enabled {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
if let Some(metadata) = e.sdk_metadata.as_ref() {
|
53
|
+
self.core.extend(
|
54
|
+
metadata
|
55
|
+
.core_used_flags
|
56
|
+
.iter()
|
57
|
+
.map(|u| CoreInternalFlags::from_u32(*u)),
|
58
|
+
);
|
59
|
+
self.lang.extend(metadata.lang_used_flags.iter());
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
pub fn add_lang_used(&mut self, flags: impl IntoIterator<Item = u32>) {
|
64
|
+
if !self.enabled {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
self.lang_since_last_complete.extend(flags.into_iter());
|
69
|
+
}
|
70
|
+
|
71
|
+
/// Returns true if this flag may currently be used. If `should_record` is true, always returns
|
72
|
+
/// true and records the flag as being used, for taking later via
|
73
|
+
/// [Self::gather_for_wft_complete].
|
74
|
+
pub fn try_use(&mut self, core_patch: CoreInternalFlags, should_record: bool) -> bool {
|
75
|
+
if !self.enabled {
|
76
|
+
// If the server does not support the metadata field, we must assume
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
|
80
|
+
if should_record {
|
81
|
+
self.core_since_last_complete.insert(core_patch);
|
82
|
+
true
|
83
|
+
} else {
|
84
|
+
self.core.contains(&core_patch)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
/// Wipes the recorded flags used during the current WFT and returns a partially filled
|
89
|
+
/// sdk metadata message that can be combined with any existing data before sending the WFT
|
90
|
+
/// complete
|
91
|
+
pub fn gather_for_wft_complete(&mut self) -> WorkflowTaskCompletedMetadata {
|
92
|
+
WorkflowTaskCompletedMetadata {
|
93
|
+
core_used_flags: self
|
94
|
+
.core_since_last_complete
|
95
|
+
.drain()
|
96
|
+
.map(|p| p as u32)
|
97
|
+
.collect(),
|
98
|
+
lang_used_flags: self.lang_since_last_complete.drain().collect(),
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
pub fn all_lang(&self) -> &BTreeSet<u32> {
|
103
|
+
&self.lang
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
impl CoreInternalFlags {
|
108
|
+
fn from_u32(v: u32) -> Self {
|
109
|
+
match v {
|
110
|
+
1 => Self::IdAndTypeDeterminismChecks,
|
111
|
+
_ => Self::TooHigh,
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
#[cfg(test)]
|
117
|
+
mod tests {
|
118
|
+
use super::*;
|
119
|
+
use temporal_sdk_core_protos::temporal::api::workflowservice::v1::get_system_info_response::Capabilities;
|
120
|
+
|
121
|
+
#[test]
|
122
|
+
fn disabled_in_capabilities_disables() {
|
123
|
+
let mut f = InternalFlags::new(&Capabilities::default());
|
124
|
+
f.add_lang_used([1]);
|
125
|
+
f.add_from_complete(&WorkflowTaskCompletedEventAttributes {
|
126
|
+
sdk_metadata: Some(WorkflowTaskCompletedMetadata {
|
127
|
+
core_used_flags: vec![1],
|
128
|
+
lang_used_flags: vec![],
|
129
|
+
}),
|
130
|
+
..Default::default()
|
131
|
+
});
|
132
|
+
let gathered = f.gather_for_wft_complete();
|
133
|
+
assert_matches!(gathered.core_used_flags.as_slice(), &[]);
|
134
|
+
assert_matches!(gathered.lang_used_flags.as_slice(), &[]);
|
135
|
+
}
|
136
|
+
}
|
@@ -13,12 +13,12 @@ extern crate core;
|
|
13
13
|
|
14
14
|
mod abstractions;
|
15
15
|
pub mod ephemeral_server;
|
16
|
-
mod
|
16
|
+
mod internal_flags;
|
17
17
|
mod pollers;
|
18
18
|
mod protosext;
|
19
19
|
pub mod replay;
|
20
20
|
pub(crate) mod retry_logic;
|
21
|
-
pub
|
21
|
+
pub mod telemetry;
|
22
22
|
mod worker;
|
23
23
|
|
24
24
|
#[cfg(test)]
|
@@ -33,44 +33,49 @@ pub use pollers::{
|
|
33
33
|
Client, ClientOptions, ClientOptionsBuilder, ClientTlsConfig, RetryClient, RetryConfig,
|
34
34
|
TlsConfig, WorkflowClientTrait,
|
35
35
|
};
|
36
|
-
pub use telemetry::{
|
37
|
-
fetch_global_buffered_logs, telemetry_init, Logger, MetricTemporality, MetricsExporter,
|
38
|
-
OtelCollectorOptions, TelemetryOptions, TelemetryOptionsBuilder, TraceExporter,
|
39
|
-
};
|
40
36
|
pub use temporal_sdk_core_api as api;
|
41
37
|
pub use temporal_sdk_core_protos as protos;
|
42
38
|
pub use temporal_sdk_core_protos::TaskToken;
|
43
39
|
pub use url::Url;
|
40
|
+
#[cfg(feature = "save_wf_inputs")]
|
41
|
+
pub use worker::replay_wf_state_inputs;
|
44
42
|
pub use worker::{Worker, WorkerConfig, WorkerConfigBuilder};
|
45
43
|
|
46
44
|
use crate::{
|
47
|
-
replay::
|
48
|
-
telemetry::
|
45
|
+
replay::{mock_client_from_histories, Historator, HistoryForReplay},
|
46
|
+
telemetry::{
|
47
|
+
metrics::{MetricsContext, TemporalMeter},
|
48
|
+
remove_trace_subscriber_for_current_thread, set_trace_subscriber_for_current_thread,
|
49
|
+
telemetry_init, TelemetryInstance,
|
50
|
+
},
|
49
51
|
worker::client::WorkerClientBag,
|
50
52
|
};
|
53
|
+
use futures::Stream;
|
51
54
|
use std::sync::Arc;
|
52
55
|
use temporal_client::{ConfiguredClient, TemporalServiceClientWithMetrics};
|
53
56
|
use temporal_sdk_core_api::{
|
54
57
|
errors::{CompleteActivityError, PollActivityError, PollWfError},
|
55
|
-
|
58
|
+
telemetry::TelemetryOptions,
|
59
|
+
Worker as WorkerTrait,
|
56
60
|
};
|
57
|
-
use temporal_sdk_core_protos::
|
58
|
-
|
59
|
-
lazy_static::lazy_static! {
|
60
|
-
/// A process-wide unique string, which will be different on every startup
|
61
|
-
static ref PROCCESS_UNIQ_ID: String = {
|
62
|
-
uuid::Uuid::new_v4().simple().to_string()
|
63
|
-
};
|
64
|
-
}
|
61
|
+
use temporal_sdk_core_protos::coresdk::ActivityHeartbeat;
|
65
62
|
|
66
63
|
/// Initialize a worker bound to a task queue.
|
67
64
|
///
|
68
|
-
///
|
65
|
+
/// You will need to have already initialized a [CoreRuntime] which will be used for this worker.
|
66
|
+
/// After the worker is initialized, you should use [CoreRuntime::tokio_handle] to run the worker's
|
67
|
+
/// async functions.
|
68
|
+
///
|
69
|
+
/// Lang implementations may pass in a [ConfiguredClient] directly (or a
|
69
70
|
/// [RetryClient] wrapping one, or a handful of other variants of the same idea). When they do so,
|
70
71
|
/// this function will always overwrite the client retry configuration, force the client to use the
|
71
72
|
/// namespace defined in the worker config, and set the client identity appropriately. IE: Use
|
72
73
|
/// [ClientOptions::connect_no_namespace], not [ClientOptions::connect].
|
73
|
-
pub fn init_worker<CT>(
|
74
|
+
pub fn init_worker<CT>(
|
75
|
+
runtime: &CoreRuntime,
|
76
|
+
worker_config: WorkerConfig,
|
77
|
+
client: CT,
|
78
|
+
) -> Result<Worker, anyhow::Error>
|
74
79
|
where
|
75
80
|
CT: Into<sealed::AnyClient>,
|
76
81
|
{
|
@@ -96,18 +101,27 @@ where
|
|
96
101
|
worker_config.use_worker_versioning,
|
97
102
|
));
|
98
103
|
|
99
|
-
|
100
|
-
|
101
|
-
|
104
|
+
Ok(Worker::new(
|
105
|
+
worker_config,
|
106
|
+
sticky_q,
|
107
|
+
client_bag,
|
108
|
+
Some(&runtime.telemetry),
|
109
|
+
))
|
102
110
|
}
|
103
111
|
|
104
112
|
/// Create a worker for replaying a specific history. It will auto-shutdown as soon as the history
|
105
|
-
/// has finished being replayed.
|
106
|
-
///
|
107
|
-
|
113
|
+
/// has finished being replayed.
|
114
|
+
///
|
115
|
+
/// You do not necessarily need a [CoreRuntime] for replay workers, but it's advisable to create
|
116
|
+
/// one and use it to run the replay worker's async functions the same way you would for a normal
|
117
|
+
/// worker.
|
118
|
+
pub fn init_replay_worker<I>(
|
108
119
|
mut config: WorkerConfig,
|
109
|
-
|
110
|
-
) -> Result<Worker, anyhow::Error>
|
120
|
+
histories: I,
|
121
|
+
) -> Result<Worker, anyhow::Error>
|
122
|
+
where
|
123
|
+
I: Stream<Item = HistoryForReplay> + Send + 'static,
|
124
|
+
{
|
111
125
|
info!(
|
112
126
|
task_queue = config.task_queue.as_str(),
|
113
127
|
"Registering replay worker"
|
@@ -115,15 +129,18 @@ pub fn init_replay_worker(
|
|
115
129
|
config.max_cached_workflows = 1;
|
116
130
|
config.max_concurrent_wft_polls = 1;
|
117
131
|
config.no_remote_activities = true;
|
118
|
-
|
119
|
-
let
|
120
|
-
let
|
121
|
-
let
|
122
|
-
let mut worker = Worker::new(config, None, Arc::new(client),
|
123
|
-
worker.
|
132
|
+
let historator = Historator::new(histories);
|
133
|
+
let post_activate = historator.get_post_activate_hook();
|
134
|
+
let shutdown_tok = historator.get_shutdown_setter();
|
135
|
+
let client = mock_client_from_histories(historator);
|
136
|
+
let mut worker = Worker::new(config, None, Arc::new(client), None);
|
137
|
+
worker.set_post_activate_hook(post_activate);
|
138
|
+
shutdown_tok(worker.shutdown_token());
|
124
139
|
Ok(worker)
|
125
140
|
}
|
126
141
|
|
142
|
+
/// Creates a unique sticky queue name for a worker, iff the config allows for 1 or more cached
|
143
|
+
/// workflows.
|
127
144
|
pub(crate) fn sticky_q_name_for_worker(
|
128
145
|
process_identity: &str,
|
129
146
|
config: &WorkerConfig,
|
@@ -131,7 +148,9 @@ pub(crate) fn sticky_q_name_for_worker(
|
|
131
148
|
if config.max_cached_workflows > 0 {
|
132
149
|
Some(format!(
|
133
150
|
"{}-{}-{}",
|
134
|
-
&process_identity,
|
151
|
+
&process_identity,
|
152
|
+
&config.task_queue,
|
153
|
+
uuid::Uuid::new_v4().simple()
|
135
154
|
))
|
136
155
|
} else {
|
137
156
|
None
|
@@ -173,3 +192,98 @@ mod sealed {
|
|
173
192
|
}
|
174
193
|
}
|
175
194
|
}
|
195
|
+
|
196
|
+
/// Holds shared state/components needed to back instances of workers and clients. More than one
|
197
|
+
/// may be instantiated, but typically only one is needed. More than one runtime instance may be
|
198
|
+
/// useful if multiple different telemetry settings are required.
|
199
|
+
pub struct CoreRuntime {
|
200
|
+
telemetry: TelemetryInstance,
|
201
|
+
runtime: Option<tokio::runtime::Runtime>,
|
202
|
+
runtime_handle: tokio::runtime::Handle,
|
203
|
+
}
|
204
|
+
|
205
|
+
impl CoreRuntime {
|
206
|
+
/// Create a new core runtime with the provided telemetry options and tokio runtime builder.
|
207
|
+
/// Also initialize telemetry for the thread this is being called on.
|
208
|
+
///
|
209
|
+
/// Note that this function will call the [tokio::runtime::Builder::enable_all] builder option
|
210
|
+
/// on the Tokio runtime builder, and will call [tokio::runtime::Builder::on_thread_start] to
|
211
|
+
/// ensure telemetry subscribers are set on every tokio thread.
|
212
|
+
///
|
213
|
+
/// **Important**: You need to call this *before* calling any async functions on workers or
|
214
|
+
/// clients, otherwise the tracing subscribers will not be properly attached.
|
215
|
+
///
|
216
|
+
/// # Panics
|
217
|
+
/// If a tokio runtime has already been initialized. To re-use an existing runtime, call
|
218
|
+
/// [CoreRuntime::new_assume_tokio].
|
219
|
+
pub fn new(
|
220
|
+
telemetry_options: TelemetryOptions,
|
221
|
+
mut tokio_builder: tokio::runtime::Builder,
|
222
|
+
) -> Result<Self, anyhow::Error> {
|
223
|
+
let telemetry = telemetry_init(telemetry_options)?;
|
224
|
+
let subscriber = telemetry.trace_subscriber();
|
225
|
+
let runtime = tokio_builder
|
226
|
+
.enable_all()
|
227
|
+
.on_thread_start(move || {
|
228
|
+
set_trace_subscriber_for_current_thread(subscriber.clone());
|
229
|
+
})
|
230
|
+
.build()?;
|
231
|
+
let _rg = runtime.enter();
|
232
|
+
let mut me = Self::new_assume_tokio_initialized_telem(telemetry);
|
233
|
+
me.runtime = Some(runtime);
|
234
|
+
Ok(me)
|
235
|
+
}
|
236
|
+
|
237
|
+
/// Initialize telemetry for the thread this is being called on, assuming a tokio runtime is
|
238
|
+
/// already active and this call exists in its context. See [Self::new] for more.
|
239
|
+
///
|
240
|
+
/// # Panics
|
241
|
+
/// If there is no currently active Tokio runtime
|
242
|
+
pub fn new_assume_tokio(telemetry_options: TelemetryOptions) -> Result<Self, anyhow::Error> {
|
243
|
+
let telemetry = telemetry_init(telemetry_options)?;
|
244
|
+
Ok(Self::new_assume_tokio_initialized_telem(telemetry))
|
245
|
+
}
|
246
|
+
|
247
|
+
/// Construct a runtime from an already-initialized telemetry instance, assuming a tokio runtime
|
248
|
+
/// is already active and this call exists in its context. See [Self::new] for more.
|
249
|
+
///
|
250
|
+
/// # Panics
|
251
|
+
/// If there is no currently active Tokio runtime
|
252
|
+
pub fn new_assume_tokio_initialized_telem(telemetry: TelemetryInstance) -> Self {
|
253
|
+
let runtime_handle = tokio::runtime::Handle::current();
|
254
|
+
set_trace_subscriber_for_current_thread(telemetry.trace_subscriber());
|
255
|
+
Self {
|
256
|
+
telemetry,
|
257
|
+
runtime: None,
|
258
|
+
runtime_handle,
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
/// Get a handle to the tokio runtime used by this Core runtime.
|
263
|
+
pub fn tokio_handle(&self) -> tokio::runtime::Handle {
|
264
|
+
self.runtime_handle.clone()
|
265
|
+
}
|
266
|
+
|
267
|
+
/// Returns the metric meter used for recording metrics, if they were enabled.
|
268
|
+
pub fn metric_meter(&self) -> Option<TemporalMeter> {
|
269
|
+
self.telemetry.get_metric_meter()
|
270
|
+
}
|
271
|
+
|
272
|
+
/// Return the trace subscriber associated with the telemetry options/instance. Can be used
|
273
|
+
/// to manually set the default for a thread or globally using the `tracing` crate, or with
|
274
|
+
/// [set_trace_subscriber_for_current_thread]
|
275
|
+
pub fn trace_subscriber(&self) -> Arc<dyn tracing::Subscriber + Send + Sync> {
|
276
|
+
self.telemetry.trace_subscriber()
|
277
|
+
}
|
278
|
+
|
279
|
+
/// Return a reference to the owned [TelemetryInstance]
|
280
|
+
pub fn telemetry(&self) -> &TelemetryInstance {
|
281
|
+
&self.telemetry
|
282
|
+
}
|
283
|
+
}
|
284
|
+
|
285
|
+
impl Drop for CoreRuntime {
|
286
|
+
fn drop(&mut self) {
|
287
|
+
remove_trace_subscriber_for_current_thread();
|
288
|
+
}
|
289
|
+
}
|
@@ -274,7 +274,7 @@ impl TryFrom<activity_execution_result::Status> for LocalActivityExecutionResult
|
|
274
274
|
Status::Failed(f)
|
275
275
|
if f.failure
|
276
276
|
.as_ref()
|
277
|
-
.map(|fail| fail.is_timeout())
|
277
|
+
.map(|fail| fail.is_timeout().is_some())
|
278
278
|
.unwrap_or_default() =>
|
279
279
|
{
|
280
280
|
Ok(LocalActivityExecutionResult::TimedOut(f))
|