temporalio 0.0.0 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +301 -0
- data/bridge/Cargo.lock +2888 -0
- data/bridge/Cargo.toml +27 -0
- data/bridge/sdk-core/ARCHITECTURE.md +76 -0
- data/bridge/sdk-core/Cargo.lock +2606 -0
- data/bridge/sdk-core/Cargo.toml +2 -0
- data/bridge/sdk-core/LICENSE.txt +23 -0
- data/bridge/sdk-core/README.md +104 -0
- data/bridge/sdk-core/arch_docs/diagrams/README.md +10 -0
- data/bridge/sdk-core/arch_docs/diagrams/sticky_queues.puml +40 -0
- data/bridge/sdk-core/arch_docs/diagrams/workflow_internals.svg +1 -0
- data/bridge/sdk-core/arch_docs/sticky_queues.md +51 -0
- data/bridge/sdk-core/client/Cargo.toml +40 -0
- data/bridge/sdk-core/client/LICENSE.txt +23 -0
- data/bridge/sdk-core/client/src/lib.rs +1286 -0
- data/bridge/sdk-core/client/src/metrics.rs +165 -0
- data/bridge/sdk-core/client/src/raw.rs +932 -0
- data/bridge/sdk-core/client/src/retry.rs +751 -0
- data/bridge/sdk-core/client/src/workflow_handle/mod.rs +185 -0
- data/bridge/sdk-core/core/Cargo.toml +116 -0
- data/bridge/sdk-core/core/LICENSE.txt +23 -0
- data/bridge/sdk-core/core/benches/workflow_replay.rs +76 -0
- data/bridge/sdk-core/core/src/abstractions.rs +166 -0
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +1014 -0
- data/bridge/sdk-core/core/src/core_tests/child_workflows.rs +221 -0
- data/bridge/sdk-core/core/src/core_tests/determinism.rs +107 -0
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +925 -0
- data/bridge/sdk-core/core/src/core_tests/mod.rs +100 -0
- data/bridge/sdk-core/core/src/core_tests/queries.rs +894 -0
- data/bridge/sdk-core/core/src/core_tests/replay_flag.rs +65 -0
- data/bridge/sdk-core/core/src/core_tests/workers.rs +259 -0
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +124 -0
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +2090 -0
- data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +515 -0
- data/bridge/sdk-core/core/src/lib.rs +282 -0
- data/bridge/sdk-core/core/src/pollers/mod.rs +54 -0
- data/bridge/sdk-core/core/src/pollers/poll_buffer.rs +297 -0
- data/bridge/sdk-core/core/src/protosext/mod.rs +428 -0
- data/bridge/sdk-core/core/src/replay/mod.rs +215 -0
- data/bridge/sdk-core/core/src/retry_logic.rs +202 -0
- data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +428 -0
- data/bridge/sdk-core/core/src/telemetry/mod.rs +407 -0
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +78 -0
- data/bridge/sdk-core/core/src/test_help/mod.rs +889 -0
- data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +580 -0
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +1048 -0
- data/bridge/sdk-core/core/src/worker/activities.rs +481 -0
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +87 -0
- data/bridge/sdk-core/core/src/worker/client.rs +373 -0
- data/bridge/sdk-core/core/src/worker/mod.rs +570 -0
- data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +37 -0
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +101 -0
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +532 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +907 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +294 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +167 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +858 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +136 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +157 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +129 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +1450 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +316 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +178 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +708 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +439 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +435 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +175 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +242 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +96 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +1200 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +272 -0
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +198 -0
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +655 -0
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +1200 -0
- data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +145 -0
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +88 -0
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +985 -0
- data/bridge/sdk-core/core-api/Cargo.toml +32 -0
- data/bridge/sdk-core/core-api/LICENSE.txt +23 -0
- data/bridge/sdk-core/core-api/src/errors.rs +95 -0
- data/bridge/sdk-core/core-api/src/lib.rs +109 -0
- data/bridge/sdk-core/core-api/src/telemetry.rs +147 -0
- data/bridge/sdk-core/core-api/src/worker.rs +148 -0
- data/bridge/sdk-core/etc/deps.svg +162 -0
- data/bridge/sdk-core/etc/dynamic-config.yaml +2 -0
- data/bridge/sdk-core/etc/otel-collector-config.yaml +36 -0
- data/bridge/sdk-core/etc/prometheus.yaml +6 -0
- data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
- data/bridge/sdk-core/fsm/Cargo.toml +18 -0
- data/bridge/sdk-core/fsm/LICENSE.txt +23 -0
- data/bridge/sdk-core/fsm/README.md +3 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +27 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/LICENSE.txt +23 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +647 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/progress.rs +8 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.rs +18 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +12 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dynamic_dest_pass.rs +41 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.rs +14 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.stderr +11 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_arg_pass.rs +32 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_pass.rs +31 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/medium_complex_pass.rs +46 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.rs +29 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +12 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/simple_pass.rs +32 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.rs +18 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.stderr +5 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.rs +11 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.stderr +5 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.rs +11 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.stderr +5 -0
- data/bridge/sdk-core/fsm/rustfsm_trait/Cargo.toml +14 -0
- data/bridge/sdk-core/fsm/rustfsm_trait/LICENSE.txt +23 -0
- data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +249 -0
- data/bridge/sdk-core/fsm/src/lib.rs +2 -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/histories/fail_wf_task.bin +0 -0
- data/bridge/sdk-core/histories/timer_workflow_history.bin +0 -0
- data/bridge/sdk-core/integ-with-otel.sh +7 -0
- data/bridge/sdk-core/protos/api_upstream/README.md +9 -0
- data/bridge/sdk-core/protos/api_upstream/api-linter.yaml +40 -0
- data/bridge/sdk-core/protos/api_upstream/buf.yaml +9 -0
- 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/build/tools.go +29 -0
- data/bridge/sdk-core/protos/api_upstream/dependencies/gogoproto/gogo.proto +141 -0
- data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +89 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +260 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +112 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +47 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +57 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +56 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +170 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +118 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/interaction_type.proto +39 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +51 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +50 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +41 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +60 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +59 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +40 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +122 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +108 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +114 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +56 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +758 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +87 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +97 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +121 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +80 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +61 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +55 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +379 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +108 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +59 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +146 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +1168 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +415 -0
- data/bridge/sdk-core/protos/grpc/health/v1/health.proto +63 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +79 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +77 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +15 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +30 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +263 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +304 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +29 -0
- data/bridge/sdk-core/protos/testsrv_upstream/api-linter.yaml +38 -0
- data/bridge/sdk-core/protos/testsrv_upstream/buf.yaml +13 -0
- data/bridge/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +141 -0
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +63 -0
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +90 -0
- data/bridge/sdk-core/rustfmt.toml +1 -0
- data/bridge/sdk-core/sdk/Cargo.toml +47 -0
- data/bridge/sdk-core/sdk/LICENSE.txt +23 -0
- data/bridge/sdk-core/sdk/src/activity_context.rs +230 -0
- data/bridge/sdk-core/sdk/src/app_data.rs +37 -0
- data/bridge/sdk-core/sdk/src/interceptors.rs +50 -0
- data/bridge/sdk-core/sdk/src/lib.rs +794 -0
- data/bridge/sdk-core/sdk/src/payload_converter.rs +11 -0
- data/bridge/sdk-core/sdk/src/workflow_context/options.rs +295 -0
- data/bridge/sdk-core/sdk/src/workflow_context.rs +694 -0
- data/bridge/sdk-core/sdk/src/workflow_future.rs +499 -0
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +30 -0
- data/bridge/sdk-core/sdk-core-protos/LICENSE.txt +23 -0
- data/bridge/sdk-core/sdk-core-protos/build.rs +107 -0
- data/bridge/sdk-core/sdk-core-protos/src/constants.rs +7 -0
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +544 -0
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +230 -0
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +1970 -0
- data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
- data/bridge/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
- data/bridge/sdk-core/test-utils/Cargo.toml +36 -0
- data/bridge/sdk-core/test-utils/src/canned_histories.rs +1579 -0
- data/bridge/sdk-core/test-utils/src/histfetch.rs +28 -0
- data/bridge/sdk-core/test-utils/src/lib.rs +650 -0
- data/bridge/sdk-core/tests/integ_tests/client_tests.rs +36 -0
- data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +128 -0
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +221 -0
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +37 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +133 -0
- data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +437 -0
- data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +93 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +878 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +61 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +59 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +58 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +50 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +60 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +54 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +788 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +53 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +113 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +223 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +93 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +167 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +99 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +131 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +75 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +597 -0
- data/bridge/sdk-core/tests/load_tests.rs +191 -0
- data/bridge/sdk-core/tests/main.rs +113 -0
- data/bridge/sdk-core/tests/runner.rs +93 -0
- data/bridge/src/connection.rs +186 -0
- data/bridge/src/lib.rs +239 -0
- data/bridge/src/runtime.rs +54 -0
- data/bridge/src/worker.rs +124 -0
- data/ext/Rakefile +9 -0
- data/lib/bridge.so +0 -0
- data/lib/gen/dependencies/gogoproto/gogo_pb.rb +14 -0
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +50 -0
- data/lib/gen/temporal/api/command/v1/message_pb.rb +174 -0
- data/lib/gen/temporal/api/common/v1/message_pb.rb +69 -0
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +33 -0
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +39 -0
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +42 -0
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +68 -0
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +77 -0
- data/lib/gen/temporal/api/enums/v1/interaction_type_pb.rb +25 -0
- data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +37 -0
- data/lib/gen/temporal/api/enums/v1/query_pb.rb +31 -0
- data/lib/gen/temporal/api/enums/v1/reset_pb.rb +24 -0
- data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +28 -0
- data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +30 -0
- data/lib/gen/temporal/api/enums/v1/update_pb.rb +23 -0
- data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +89 -0
- data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +84 -0
- data/lib/gen/temporal/api/failure/v1/message_pb.rb +83 -0
- data/lib/gen/temporal/api/filter/v1/message_pb.rb +40 -0
- data/lib/gen/temporal/api/history/v1/message_pb.rb +490 -0
- data/lib/gen/temporal/api/interaction/v1/message_pb.rb +49 -0
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +63 -0
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +85 -0
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +20 -0
- data/lib/gen/temporal/api/query/v1/message_pb.rb +38 -0
- data/lib/gen/temporal/api/replication/v1/message_pb.rb +37 -0
- data/lib/gen/temporal/api/schedule/v1/message_pb.rb +149 -0
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +73 -0
- data/lib/gen/temporal/api/version/v1/message_pb.rb +41 -0
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +111 -0
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +788 -0
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +20 -0
- data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +58 -0
- data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +57 -0
- data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +222 -0
- data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +57 -0
- data/lib/gen/temporal/sdk/core/common/common_pb.rb +22 -0
- data/lib/gen/temporal/sdk/core/core_interface_pb.rb +34 -0
- data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +27 -0
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +165 -0
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +196 -0
- data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +34 -0
- data/lib/temporalio/activity/context.rb +97 -0
- data/lib/temporalio/activity/info.rb +67 -0
- data/lib/temporalio/activity.rb +85 -0
- data/lib/temporalio/bridge/error.rb +8 -0
- data/lib/temporalio/bridge.rb +14 -0
- data/lib/temporalio/client/implementation.rb +340 -0
- data/lib/temporalio/client/workflow_handle.rb +243 -0
- data/lib/temporalio/client.rb +131 -0
- data/lib/temporalio/connection.rb +751 -0
- data/lib/temporalio/data_converter.rb +191 -0
- data/lib/temporalio/error/failure.rb +194 -0
- data/lib/temporalio/error/workflow_failure.rb +19 -0
- data/lib/temporalio/errors.rb +40 -0
- data/lib/temporalio/failure_converter/base.rb +26 -0
- data/lib/temporalio/failure_converter/basic.rb +319 -0
- data/lib/temporalio/failure_converter.rb +7 -0
- data/lib/temporalio/interceptor/chain.rb +28 -0
- data/lib/temporalio/interceptor/client.rb +123 -0
- data/lib/temporalio/payload_codec/base.rb +32 -0
- data/lib/temporalio/payload_converter/base.rb +24 -0
- data/lib/temporalio/payload_converter/bytes.rb +27 -0
- data/lib/temporalio/payload_converter/composite.rb +49 -0
- data/lib/temporalio/payload_converter/encoding_base.rb +35 -0
- data/lib/temporalio/payload_converter/json.rb +26 -0
- data/lib/temporalio/payload_converter/nil.rb +26 -0
- data/lib/temporalio/payload_converter.rb +14 -0
- data/lib/temporalio/retry_policy.rb +82 -0
- data/lib/temporalio/retry_state.rb +35 -0
- data/lib/temporalio/runtime.rb +25 -0
- data/lib/temporalio/timeout_type.rb +29 -0
- data/lib/temporalio/version.rb +3 -0
- data/lib/temporalio/worker/activity_runner.rb +92 -0
- data/lib/temporalio/worker/activity_worker.rb +138 -0
- data/lib/temporalio/worker/reactor.rb +46 -0
- data/lib/temporalio/worker/runner.rb +63 -0
- data/lib/temporalio/worker/sync_worker.rb +88 -0
- data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
- data/lib/temporalio/worker.rb +198 -0
- data/lib/temporalio/workflow/execution_info.rb +54 -0
- data/lib/temporalio/workflow/execution_status.rb +36 -0
- data/lib/temporalio/workflow/id_reuse_policy.rb +36 -0
- data/lib/temporalio/workflow/query_reject_condition.rb +33 -0
- data/lib/temporalio.rb +12 -1
- data/lib/thermite_patch.rb +23 -0
- data/temporalio.gemspec +45 -0
- metadata +566 -9
- data/lib/temporal/version.rb +0 -3
- data/lib/temporal.rb +0 -4
- data/temporal.gemspec +0 -20
@@ -0,0 +1,282 @@
|
|
1
|
+
#![warn(missing_docs)] // error if there are missing docs
|
2
|
+
#![allow(clippy::upper_case_acronyms)]
|
3
|
+
|
4
|
+
//! This crate provides a basis for creating new Temporal SDKs without completely starting from
|
5
|
+
//! scratch
|
6
|
+
|
7
|
+
#[cfg(test)]
|
8
|
+
#[macro_use]
|
9
|
+
pub extern crate assert_matches;
|
10
|
+
#[macro_use]
|
11
|
+
extern crate tracing;
|
12
|
+
extern crate core;
|
13
|
+
|
14
|
+
mod abstractions;
|
15
|
+
pub mod ephemeral_server;
|
16
|
+
mod pollers;
|
17
|
+
mod protosext;
|
18
|
+
pub mod replay;
|
19
|
+
pub(crate) mod retry_logic;
|
20
|
+
pub mod telemetry;
|
21
|
+
mod worker;
|
22
|
+
|
23
|
+
#[cfg(test)]
|
24
|
+
mod core_tests;
|
25
|
+
#[cfg(test)]
|
26
|
+
#[macro_use]
|
27
|
+
mod test_help;
|
28
|
+
|
29
|
+
pub(crate) use temporal_sdk_core_api::errors;
|
30
|
+
|
31
|
+
pub use pollers::{
|
32
|
+
Client, ClientOptions, ClientOptionsBuilder, ClientTlsConfig, RetryClient, RetryConfig,
|
33
|
+
TlsConfig, WorkflowClientTrait,
|
34
|
+
};
|
35
|
+
pub use temporal_sdk_core_api as api;
|
36
|
+
pub use temporal_sdk_core_protos as protos;
|
37
|
+
pub use temporal_sdk_core_protos::TaskToken;
|
38
|
+
pub use url::Url;
|
39
|
+
pub use worker::{Worker, WorkerConfig, WorkerConfigBuilder};
|
40
|
+
|
41
|
+
use crate::{
|
42
|
+
replay::{mock_client_from_histories, Historator, HistoryForReplay},
|
43
|
+
telemetry::{
|
44
|
+
metrics::MetricsContext, remove_trace_subscriber_for_current_thread,
|
45
|
+
set_trace_subscriber_for_current_thread, telemetry_init, TelemetryInstance,
|
46
|
+
},
|
47
|
+
worker::client::WorkerClientBag,
|
48
|
+
};
|
49
|
+
use futures::Stream;
|
50
|
+
use std::sync::Arc;
|
51
|
+
use temporal_client::{ConfiguredClient, TemporalServiceClientWithMetrics};
|
52
|
+
use temporal_sdk_core_api::{
|
53
|
+
errors::{CompleteActivityError, PollActivityError, PollWfError},
|
54
|
+
telemetry::{CoreTelemetry, TelemetryOptions},
|
55
|
+
Worker as WorkerTrait,
|
56
|
+
};
|
57
|
+
use temporal_sdk_core_protos::coresdk::ActivityHeartbeat;
|
58
|
+
|
59
|
+
/// Initialize a worker bound to a task queue.
|
60
|
+
///
|
61
|
+
/// You will need to have already initialized a [CoreRuntime] which will be used for this worker.
|
62
|
+
/// After the worker is initialized, you should use [CoreRuntime::tokio_handle] to run the worker's
|
63
|
+
/// async functions.
|
64
|
+
///
|
65
|
+
/// Lang implementations may pass in a [temporal_client::ConfiguredClient] directly (or a
|
66
|
+
/// [RetryClient] wrapping one, or a handful of other variants of the same idea). When they do so,
|
67
|
+
/// this function will always overwrite the client retry configuration, force the client to use the
|
68
|
+
/// namespace defined in the worker config, and set the client identity appropriately. IE: Use
|
69
|
+
/// [ClientOptions::connect_no_namespace], not [ClientOptions::connect].
|
70
|
+
pub fn init_worker<CT>(
|
71
|
+
runtime: &CoreRuntime,
|
72
|
+
worker_config: WorkerConfig,
|
73
|
+
client: CT,
|
74
|
+
) -> Result<Worker, anyhow::Error>
|
75
|
+
where
|
76
|
+
CT: Into<sealed::AnyClient>,
|
77
|
+
{
|
78
|
+
let client = {
|
79
|
+
let ll = client.into().into_inner();
|
80
|
+
let mut client = Client::new(*ll, worker_config.namespace.clone());
|
81
|
+
client.set_worker_build_id(worker_config.worker_build_id.clone());
|
82
|
+
if let Some(ref id_override) = worker_config.client_identity_override {
|
83
|
+
client.options_mut().identity = id_override.clone();
|
84
|
+
}
|
85
|
+
RetryClient::new(client, RetryConfig::default())
|
86
|
+
};
|
87
|
+
if client.namespace() != worker_config.namespace {
|
88
|
+
panic!("Passed in client is not bound to the same namespace as the worker");
|
89
|
+
}
|
90
|
+
let client_ident = client.get_options().identity.clone();
|
91
|
+
let sticky_q = sticky_q_name_for_worker(&client_ident, &worker_config);
|
92
|
+
let client_bag = Arc::new(WorkerClientBag::new(
|
93
|
+
client,
|
94
|
+
worker_config.namespace.clone(),
|
95
|
+
client_ident,
|
96
|
+
worker_config.worker_build_id.clone(),
|
97
|
+
worker_config.use_worker_versioning,
|
98
|
+
));
|
99
|
+
|
100
|
+
let metrics = MetricsContext::top_level(worker_config.namespace.clone(), &runtime.telemetry)
|
101
|
+
.with_task_q(worker_config.task_queue.clone());
|
102
|
+
Ok(Worker::new(worker_config, sticky_q, client_bag, metrics))
|
103
|
+
}
|
104
|
+
|
105
|
+
/// Create a worker for replaying a specific history. It will auto-shutdown as soon as the history
|
106
|
+
/// has finished being replayed.
|
107
|
+
///
|
108
|
+
/// You do not necessarily need a [CoreRuntime] for replay workers, but it's advisable to create
|
109
|
+
/// one and use it to run the replay worker's async functions the same way you would for a normal
|
110
|
+
/// worker.
|
111
|
+
pub fn init_replay_worker<I>(
|
112
|
+
mut config: WorkerConfig,
|
113
|
+
histories: I,
|
114
|
+
) -> Result<Worker, anyhow::Error>
|
115
|
+
where
|
116
|
+
I: Stream<Item = HistoryForReplay> + Send + 'static,
|
117
|
+
{
|
118
|
+
info!(
|
119
|
+
task_queue = config.task_queue.as_str(),
|
120
|
+
"Registering replay worker"
|
121
|
+
);
|
122
|
+
config.max_cached_workflows = 1;
|
123
|
+
config.max_concurrent_wft_polls = 1;
|
124
|
+
config.no_remote_activities = true;
|
125
|
+
let historator = Historator::new(histories);
|
126
|
+
let post_activate = historator.get_post_activate_hook();
|
127
|
+
let shutdown_tok = historator.get_shutdown_setter();
|
128
|
+
let client = mock_client_from_histories(historator);
|
129
|
+
let mut worker = Worker::new(config, None, Arc::new(client), MetricsContext::no_op());
|
130
|
+
worker.set_post_activate_hook(post_activate);
|
131
|
+
shutdown_tok(worker.shutdown_token());
|
132
|
+
Ok(worker)
|
133
|
+
}
|
134
|
+
|
135
|
+
/// Creates a unique sticky queue name for a worker, iff the config allows for 1 or more cached
|
136
|
+
/// workflows.
|
137
|
+
pub(crate) fn sticky_q_name_for_worker(
|
138
|
+
process_identity: &str,
|
139
|
+
config: &WorkerConfig,
|
140
|
+
) -> Option<String> {
|
141
|
+
if config.max_cached_workflows > 0 {
|
142
|
+
Some(format!(
|
143
|
+
"{}-{}-{}",
|
144
|
+
&process_identity,
|
145
|
+
&config.task_queue,
|
146
|
+
uuid::Uuid::new_v4().simple()
|
147
|
+
))
|
148
|
+
} else {
|
149
|
+
None
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
mod sealed {
|
154
|
+
use super::*;
|
155
|
+
|
156
|
+
/// Allows passing different kinds of clients into things that want to be flexible. Motivating
|
157
|
+
/// use-case was worker initialization.
|
158
|
+
///
|
159
|
+
/// Needs to exist in this crate to avoid blanket impl conflicts.
|
160
|
+
pub struct AnyClient(Box<ConfiguredClient<TemporalServiceClientWithMetrics>>);
|
161
|
+
impl AnyClient {
|
162
|
+
pub(crate) fn into_inner(self) -> Box<ConfiguredClient<TemporalServiceClientWithMetrics>> {
|
163
|
+
self.0
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
impl From<RetryClient<ConfiguredClient<TemporalServiceClientWithMetrics>>> for AnyClient {
|
168
|
+
fn from(c: RetryClient<ConfiguredClient<TemporalServiceClientWithMetrics>>) -> Self {
|
169
|
+
Self(Box::new(c.into_inner()))
|
170
|
+
}
|
171
|
+
}
|
172
|
+
impl From<RetryClient<Client>> for AnyClient {
|
173
|
+
fn from(c: RetryClient<Client>) -> Self {
|
174
|
+
Self(Box::new(c.into_inner().into_inner()))
|
175
|
+
}
|
176
|
+
}
|
177
|
+
impl From<Arc<RetryClient<Client>>> for AnyClient {
|
178
|
+
fn from(c: Arc<RetryClient<Client>>) -> Self {
|
179
|
+
Self(Box::new(c.get_client().inner().clone()))
|
180
|
+
}
|
181
|
+
}
|
182
|
+
impl From<ConfiguredClient<TemporalServiceClientWithMetrics>> for AnyClient {
|
183
|
+
fn from(c: ConfiguredClient<TemporalServiceClientWithMetrics>) -> Self {
|
184
|
+
Self(Box::new(c))
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
/// Holds shared state/components needed to back instances of workers and clients. More than one
|
190
|
+
/// may be instantiated, but typically only one is needed. More than one runtime instance may be
|
191
|
+
/// useful if multiple different telemetry settings are required.
|
192
|
+
pub struct CoreRuntime {
|
193
|
+
telemetry: TelemetryInstance,
|
194
|
+
runtime: Option<tokio::runtime::Runtime>,
|
195
|
+
runtime_handle: tokio::runtime::Handle,
|
196
|
+
}
|
197
|
+
|
198
|
+
impl CoreRuntime {
|
199
|
+
/// Create a new core runtime with the provided telemetry options and tokio runtime builder.
|
200
|
+
/// Also initialize telemetry for the thread this is being called on.
|
201
|
+
///
|
202
|
+
/// Note that this function will call the [tokio::runtime::Builder::enable_all] builder option
|
203
|
+
/// on the Tokio runtime builder, and will call [tokio::runtime::Builder::on_thread_start] to
|
204
|
+
/// ensure telemetry subscribers are set on every tokio thread.
|
205
|
+
///
|
206
|
+
/// **Important**: You need to call this *before* calling any async functions on workers or
|
207
|
+
/// clients, otherwise the tracing subscribers will not be properly attached.
|
208
|
+
///
|
209
|
+
/// # Panics
|
210
|
+
/// If a tokio runtime has already been initialized. To re-use an existing runtime, call
|
211
|
+
/// [CoreRuntime::new_assume_tokio].
|
212
|
+
pub fn new(
|
213
|
+
telemetry_options: TelemetryOptions,
|
214
|
+
mut tokio_builder: tokio::runtime::Builder,
|
215
|
+
) -> Result<Self, anyhow::Error> {
|
216
|
+
let telemetry = telemetry_init(telemetry_options)?;
|
217
|
+
let subscriber = telemetry.trace_subscriber();
|
218
|
+
let runtime = tokio_builder
|
219
|
+
.enable_all()
|
220
|
+
.on_thread_start(move || {
|
221
|
+
set_trace_subscriber_for_current_thread(subscriber.clone());
|
222
|
+
})
|
223
|
+
.build()?;
|
224
|
+
let _rg = runtime.enter();
|
225
|
+
let mut me = Self::new_assume_tokio_initialized_telem(telemetry);
|
226
|
+
me.runtime = Some(runtime);
|
227
|
+
Ok(me)
|
228
|
+
}
|
229
|
+
|
230
|
+
/// Initialize telemetry for the thread this is being called on, assuming a tokio runtime is
|
231
|
+
/// already active and this call exists in its context. See [Self::new] for more.
|
232
|
+
///
|
233
|
+
/// # Panics
|
234
|
+
/// If there is no currently active Tokio runtime
|
235
|
+
pub fn new_assume_tokio(telemetry_options: TelemetryOptions) -> Result<Self, anyhow::Error> {
|
236
|
+
let telemetry = telemetry_init(telemetry_options)?;
|
237
|
+
Ok(Self::new_assume_tokio_initialized_telem(telemetry))
|
238
|
+
}
|
239
|
+
|
240
|
+
/// Construct a runtime from an already-initialized telemetry instance, assuming a tokio runtime
|
241
|
+
/// is already active and this call exists in its context. See [Self::new] for more.
|
242
|
+
///
|
243
|
+
/// # Panics
|
244
|
+
/// If there is no currently active Tokio runtime
|
245
|
+
pub fn new_assume_tokio_initialized_telem(telemetry: TelemetryInstance) -> Self {
|
246
|
+
let runtime_handle = tokio::runtime::Handle::current();
|
247
|
+
set_trace_subscriber_for_current_thread(telemetry.trace_subscriber());
|
248
|
+
Self {
|
249
|
+
telemetry,
|
250
|
+
runtime: None,
|
251
|
+
runtime_handle,
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
/// Get a handle to the tokio runtime used by this Core runtime.
|
256
|
+
pub fn tokio_handle(&self) -> tokio::runtime::Handle {
|
257
|
+
self.runtime_handle.clone()
|
258
|
+
}
|
259
|
+
|
260
|
+
/// Returns the metric meter used for recording metrics, if they were enabled.
|
261
|
+
pub fn metric_meter(&self) -> Option<&opentelemetry::metrics::Meter> {
|
262
|
+
self.telemetry.get_metric_meter()
|
263
|
+
}
|
264
|
+
|
265
|
+
/// Return the trace subscriber associated with the telemetry options/instance. Can be used
|
266
|
+
/// to manually set the default for a thread or globally using the `tracing` crate, or with
|
267
|
+
/// [set_trace_subscriber_for_current_thread]
|
268
|
+
pub fn trace_subscriber(&self) -> Arc<dyn tracing::Subscriber + Send + Sync> {
|
269
|
+
self.telemetry.trace_subscriber()
|
270
|
+
}
|
271
|
+
|
272
|
+
/// Return a reference to the owned [TelemetryInstance]
|
273
|
+
pub fn telemetry(&self) -> &TelemetryInstance {
|
274
|
+
&self.telemetry
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
impl Drop for CoreRuntime {
|
279
|
+
fn drop(&mut self) {
|
280
|
+
remove_trace_subscriber_for_current_thread();
|
281
|
+
}
|
282
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
mod poll_buffer;
|
2
|
+
|
3
|
+
pub(crate) use poll_buffer::{
|
4
|
+
new_activity_task_buffer, new_workflow_task_buffer, WorkflowTaskPoller,
|
5
|
+
};
|
6
|
+
pub use temporal_client::{
|
7
|
+
Client, ClientOptions, ClientOptionsBuilder, ClientTlsConfig, RetryClient, RetryConfig,
|
8
|
+
TlsConfig, WorkflowClientTrait,
|
9
|
+
};
|
10
|
+
use temporal_sdk_core_protos::temporal::api::workflowservice::v1::{
|
11
|
+
PollActivityTaskQueueResponse, PollWorkflowTaskQueueResponse,
|
12
|
+
};
|
13
|
+
|
14
|
+
#[cfg(test)]
|
15
|
+
use futures::Future;
|
16
|
+
|
17
|
+
pub type Result<T, E = tonic::Status> = std::result::Result<T, E>;
|
18
|
+
|
19
|
+
/// A trait for things that poll the server. Hides complexity of concurrent polling or polling
|
20
|
+
/// on sticky/nonsticky queues simultaneously.
|
21
|
+
#[cfg_attr(test, mockall::automock)]
|
22
|
+
#[cfg_attr(test, allow(unused))]
|
23
|
+
#[async_trait::async_trait]
|
24
|
+
pub trait Poller<PollResult>
|
25
|
+
where
|
26
|
+
PollResult: Send + Sync + 'static,
|
27
|
+
{
|
28
|
+
async fn poll(&self) -> Option<Result<PollResult>>;
|
29
|
+
fn notify_shutdown(&self);
|
30
|
+
async fn shutdown(self);
|
31
|
+
/// Need a separate shutdown to be able to consume boxes :(
|
32
|
+
async fn shutdown_box(self: Box<Self>);
|
33
|
+
}
|
34
|
+
pub type BoxedPoller<T> = Box<dyn Poller<T> + Send + Sync + 'static>;
|
35
|
+
pub type BoxedWFPoller = BoxedPoller<PollWorkflowTaskQueueResponse>;
|
36
|
+
pub type BoxedActPoller = BoxedPoller<PollActivityTaskQueueResponse>;
|
37
|
+
|
38
|
+
#[cfg(test)]
|
39
|
+
mockall::mock! {
|
40
|
+
pub ManualPoller<T: Send + Sync + 'static> {}
|
41
|
+
#[allow(unused)]
|
42
|
+
impl<T: Send + Sync + 'static> Poller<T> for ManualPoller<T> {
|
43
|
+
fn poll<'a, 'b>(&self)
|
44
|
+
-> impl Future<Output = Option<Result<T>>> + Send + 'b
|
45
|
+
where 'a: 'b, Self: 'b;
|
46
|
+
fn notify_shutdown(&self);
|
47
|
+
fn shutdown<'a>(self)
|
48
|
+
-> impl Future<Output = ()> + Send + 'a
|
49
|
+
where Self: 'a;
|
50
|
+
fn shutdown_box<'a>(self: Box<Self>)
|
51
|
+
-> impl Future<Output = ()> + Send + 'a
|
52
|
+
where Self: 'a;
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,297 @@
|
|
1
|
+
use crate::{
|
2
|
+
pollers::{self, Poller},
|
3
|
+
worker::client::WorkerClient,
|
4
|
+
};
|
5
|
+
use futures::{prelude::stream::FuturesUnordered, StreamExt};
|
6
|
+
use std::{
|
7
|
+
fmt::Debug,
|
8
|
+
future::Future,
|
9
|
+
sync::{
|
10
|
+
atomic::{AtomicUsize, Ordering},
|
11
|
+
Arc,
|
12
|
+
},
|
13
|
+
};
|
14
|
+
use temporal_sdk_core_protos::temporal::api::workflowservice::v1::{
|
15
|
+
PollActivityTaskQueueResponse, PollWorkflowTaskQueueResponse,
|
16
|
+
};
|
17
|
+
use tokio::{
|
18
|
+
sync::{
|
19
|
+
mpsc::{channel, Receiver},
|
20
|
+
Mutex, Semaphore,
|
21
|
+
},
|
22
|
+
task::JoinHandle,
|
23
|
+
};
|
24
|
+
use tokio_util::sync::CancellationToken;
|
25
|
+
|
26
|
+
pub struct LongPollBuffer<T> {
|
27
|
+
buffered_polls: Mutex<Receiver<pollers::Result<T>>>,
|
28
|
+
shutdown: CancellationToken,
|
29
|
+
/// This semaphore exists to ensure that we only poll server as many times as core actually
|
30
|
+
/// *asked* it to be polled - otherwise we might spin and buffer polls constantly. This also
|
31
|
+
/// means unit tests can continue to function in a predictable manner when calling mocks.
|
32
|
+
polls_requested: Arc<Semaphore>,
|
33
|
+
join_handles: FuturesUnordered<JoinHandle<()>>,
|
34
|
+
/// Called every time the number of pollers is changed
|
35
|
+
num_pollers_changed: Option<Box<dyn Fn(usize) + Send + Sync>>,
|
36
|
+
active_pollers: Arc<AtomicUsize>,
|
37
|
+
}
|
38
|
+
|
39
|
+
struct ActiveCounter<'a>(&'a AtomicUsize);
|
40
|
+
impl<'a> ActiveCounter<'a> {
|
41
|
+
fn new(a: &'a AtomicUsize) -> Self {
|
42
|
+
a.fetch_add(1, Ordering::Relaxed);
|
43
|
+
Self(a)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
impl Drop for ActiveCounter<'_> {
|
47
|
+
fn drop(&mut self) {
|
48
|
+
self.0.fetch_sub(1, Ordering::Relaxed);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
impl<T> LongPollBuffer<T>
|
53
|
+
where
|
54
|
+
T: Send + Debug + 'static,
|
55
|
+
{
|
56
|
+
pub fn new<FT>(
|
57
|
+
poll_fn: impl Fn() -> FT + Send + Sync + 'static,
|
58
|
+
max_pollers: usize,
|
59
|
+
buffer_size: usize,
|
60
|
+
shutdown: CancellationToken,
|
61
|
+
) -> Self
|
62
|
+
where
|
63
|
+
FT: Future<Output = pollers::Result<T>> + Send,
|
64
|
+
{
|
65
|
+
let (tx, rx) = channel(buffer_size);
|
66
|
+
let polls_requested = Arc::new(Semaphore::new(0));
|
67
|
+
let active_pollers = Arc::new(AtomicUsize::new(0));
|
68
|
+
let join_handles = FuturesUnordered::new();
|
69
|
+
let pf = Arc::new(poll_fn);
|
70
|
+
for _ in 0..max_pollers {
|
71
|
+
let tx = tx.clone();
|
72
|
+
let pf = pf.clone();
|
73
|
+
let shutdown = shutdown.clone();
|
74
|
+
let polls_requested = polls_requested.clone();
|
75
|
+
let ap = active_pollers.clone();
|
76
|
+
let jh = tokio::spawn(async move {
|
77
|
+
loop {
|
78
|
+
if shutdown.is_cancelled() {
|
79
|
+
break;
|
80
|
+
}
|
81
|
+
let sp = tokio::select! {
|
82
|
+
sp = polls_requested.acquire() => sp.expect("Polls semaphore not dropped"),
|
83
|
+
_ = shutdown.cancelled() => continue,
|
84
|
+
};
|
85
|
+
let _active_guard = ActiveCounter::new(ap.as_ref());
|
86
|
+
let r = tokio::select! {
|
87
|
+
r = pf() => r,
|
88
|
+
_ = shutdown.cancelled() => continue,
|
89
|
+
};
|
90
|
+
sp.forget();
|
91
|
+
let _ = tx.send(r).await;
|
92
|
+
}
|
93
|
+
});
|
94
|
+
join_handles.push(jh);
|
95
|
+
}
|
96
|
+
Self {
|
97
|
+
buffered_polls: Mutex::new(rx),
|
98
|
+
shutdown,
|
99
|
+
polls_requested,
|
100
|
+
join_handles,
|
101
|
+
num_pollers_changed: None,
|
102
|
+
active_pollers,
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
/// Set a function that will be called every time the number of pollers changes.
|
107
|
+
/// TODO: Currently a bit weird, will make more sense once we implement dynamic poller scaling.
|
108
|
+
pub fn set_num_pollers_handler(&mut self, handler: impl Fn(usize) + Send + Sync + 'static) {
|
109
|
+
self.num_pollers_changed = Some(Box::new(handler));
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
#[async_trait::async_trait]
|
114
|
+
impl<T> Poller<T> for LongPollBuffer<T>
|
115
|
+
where
|
116
|
+
T: Send + Sync + Debug + 'static,
|
117
|
+
{
|
118
|
+
/// Poll the buffer. Adds one permit to the polling pool - the point of this being that the
|
119
|
+
/// buffer may support many concurrent pollers, but there is no reason to have them poll unless
|
120
|
+
/// enough polls have actually been requested. Calling this function adds a permit that any
|
121
|
+
/// concurrent poller may fulfill.
|
122
|
+
///
|
123
|
+
/// EX: If this function is only ever called serially and always `await`ed, there will be no
|
124
|
+
/// concurrent polling. If it is called many times and the futures are awaited concurrently,
|
125
|
+
/// then polling will happen concurrently.
|
126
|
+
///
|
127
|
+
/// Returns `None` if the poll buffer has been shut down
|
128
|
+
#[instrument(name = "long_poll", level = "trace", skip(self))]
|
129
|
+
async fn poll(&self) -> Option<pollers::Result<T>> {
|
130
|
+
self.polls_requested.add_permits(1);
|
131
|
+
if let Some(fun) = self.num_pollers_changed.as_ref() {
|
132
|
+
fun(self.active_pollers.load(Ordering::Relaxed));
|
133
|
+
}
|
134
|
+
|
135
|
+
let mut locked = self.buffered_polls.lock().await;
|
136
|
+
let res = (*locked).recv().await;
|
137
|
+
|
138
|
+
if let Some(fun) = self.num_pollers_changed.as_ref() {
|
139
|
+
fun(self.active_pollers.load(Ordering::Relaxed));
|
140
|
+
}
|
141
|
+
|
142
|
+
res
|
143
|
+
}
|
144
|
+
|
145
|
+
fn notify_shutdown(&self) {
|
146
|
+
self.shutdown.cancel();
|
147
|
+
}
|
148
|
+
|
149
|
+
async fn shutdown(mut self) {
|
150
|
+
self.notify_shutdown();
|
151
|
+
while self.join_handles.next().await.is_some() {}
|
152
|
+
}
|
153
|
+
|
154
|
+
async fn shutdown_box(self: Box<Self>) {
|
155
|
+
let this = *self;
|
156
|
+
this.shutdown().await;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
/// A poller capable of polling on a sticky and a nonsticky queue simultaneously for workflow tasks.
|
161
|
+
#[derive(derive_more::Constructor)]
|
162
|
+
pub struct WorkflowTaskPoller {
|
163
|
+
normal_poller: PollWorkflowTaskBuffer,
|
164
|
+
sticky_poller: Option<PollWorkflowTaskBuffer>,
|
165
|
+
}
|
166
|
+
|
167
|
+
#[async_trait::async_trait]
|
168
|
+
impl Poller<PollWorkflowTaskQueueResponse> for WorkflowTaskPoller {
|
169
|
+
async fn poll(&self) -> Option<pollers::Result<PollWorkflowTaskQueueResponse>> {
|
170
|
+
if let Some(sq) = self.sticky_poller.as_ref() {
|
171
|
+
tokio::select! {
|
172
|
+
r = self.normal_poller.poll() => r,
|
173
|
+
r = sq.poll() => r,
|
174
|
+
}
|
175
|
+
} else {
|
176
|
+
self.normal_poller.poll().await
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
fn notify_shutdown(&self) {
|
181
|
+
self.normal_poller.notify_shutdown();
|
182
|
+
if let Some(sq) = self.sticky_poller.as_ref() {
|
183
|
+
sq.notify_shutdown();
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
async fn shutdown(mut self) {
|
188
|
+
self.normal_poller.shutdown().await;
|
189
|
+
if let Some(sq) = self.sticky_poller {
|
190
|
+
sq.shutdown().await;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
async fn shutdown_box(self: Box<Self>) {
|
195
|
+
let this = *self;
|
196
|
+
this.shutdown().await;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
|
200
|
+
pub type PollWorkflowTaskBuffer = LongPollBuffer<PollWorkflowTaskQueueResponse>;
|
201
|
+
pub(crate) fn new_workflow_task_buffer(
|
202
|
+
client: Arc<dyn WorkerClient>,
|
203
|
+
task_queue: String,
|
204
|
+
is_sticky: bool,
|
205
|
+
concurrent_pollers: usize,
|
206
|
+
buffer_size: usize,
|
207
|
+
shutdown: CancellationToken,
|
208
|
+
) -> PollWorkflowTaskBuffer {
|
209
|
+
LongPollBuffer::new(
|
210
|
+
move || {
|
211
|
+
let client = client.clone();
|
212
|
+
let task_queue = task_queue.clone();
|
213
|
+
async move { client.poll_workflow_task(task_queue, is_sticky).await }
|
214
|
+
},
|
215
|
+
concurrent_pollers,
|
216
|
+
buffer_size,
|
217
|
+
shutdown,
|
218
|
+
)
|
219
|
+
}
|
220
|
+
|
221
|
+
pub type PollActivityTaskBuffer = LongPollBuffer<PollActivityTaskQueueResponse>;
|
222
|
+
pub(crate) fn new_activity_task_buffer(
|
223
|
+
client: Arc<dyn WorkerClient>,
|
224
|
+
task_queue: String,
|
225
|
+
concurrent_pollers: usize,
|
226
|
+
buffer_size: usize,
|
227
|
+
max_tps: Option<f64>,
|
228
|
+
shutdown: CancellationToken,
|
229
|
+
) -> PollActivityTaskBuffer {
|
230
|
+
LongPollBuffer::new(
|
231
|
+
move || {
|
232
|
+
let client = client.clone();
|
233
|
+
let task_queue = task_queue.clone();
|
234
|
+
async move { client.poll_activity_task(task_queue, max_tps).await }
|
235
|
+
},
|
236
|
+
concurrent_pollers,
|
237
|
+
buffer_size,
|
238
|
+
shutdown,
|
239
|
+
)
|
240
|
+
}
|
241
|
+
|
242
|
+
#[cfg(test)]
|
243
|
+
mod tests {
|
244
|
+
use super::*;
|
245
|
+
use crate::worker::client::mocks::mock_manual_workflow_client;
|
246
|
+
use futures::FutureExt;
|
247
|
+
use std::time::Duration;
|
248
|
+
use tokio::{select, sync::mpsc::channel};
|
249
|
+
|
250
|
+
#[tokio::test]
|
251
|
+
async fn only_polls_once_with_1_poller() {
|
252
|
+
let mut mock_client = mock_manual_workflow_client();
|
253
|
+
mock_client
|
254
|
+
.expect_poll_workflow_task()
|
255
|
+
.times(2)
|
256
|
+
.returning(move |_, _| {
|
257
|
+
async {
|
258
|
+
tokio::time::sleep(Duration::from_millis(100)).await;
|
259
|
+
Ok(Default::default())
|
260
|
+
}
|
261
|
+
.boxed()
|
262
|
+
});
|
263
|
+
|
264
|
+
let pb = new_workflow_task_buffer(
|
265
|
+
Arc::new(mock_client),
|
266
|
+
"someq".to_string(),
|
267
|
+
false,
|
268
|
+
1,
|
269
|
+
1,
|
270
|
+
CancellationToken::new(),
|
271
|
+
);
|
272
|
+
|
273
|
+
// Poll a bunch of times, "interrupting" it each time, we should only actually have polled
|
274
|
+
// once since the poll takes a while
|
275
|
+
let (interrupter_tx, mut interrupter_rx) = channel(50);
|
276
|
+
for _ in 0..10 {
|
277
|
+
interrupter_tx.send(()).await.unwrap();
|
278
|
+
}
|
279
|
+
|
280
|
+
// We should never get anything out since we interrupted 100% of polls
|
281
|
+
let mut last_val = false;
|
282
|
+
for _ in 0..10 {
|
283
|
+
select! {
|
284
|
+
_ = interrupter_rx.recv() => {
|
285
|
+
last_val = true;
|
286
|
+
}
|
287
|
+
_ = pb.poll() => {
|
288
|
+
}
|
289
|
+
}
|
290
|
+
}
|
291
|
+
assert!(last_val);
|
292
|
+
// Now we grab the buffered poll response, the poll task will go again but we don't grab it,
|
293
|
+
// therefore we will have only polled twice.
|
294
|
+
pb.poll().await.unwrap().unwrap();
|
295
|
+
pb.shutdown().await;
|
296
|
+
}
|
297
|
+
}
|