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,1048 @@
|
|
1
|
+
use crate::{
|
2
|
+
abstractions::{MeteredSemaphore, OwnedMeteredSemPermit},
|
3
|
+
protosext::ValidScheduleLA,
|
4
|
+
retry_logic::RetryPolicyExt,
|
5
|
+
MetricsContext, TaskToken,
|
6
|
+
};
|
7
|
+
use parking_lot::Mutex;
|
8
|
+
use std::{
|
9
|
+
collections::HashMap,
|
10
|
+
fmt::{Debug, Formatter},
|
11
|
+
time::{Duration, Instant, SystemTime},
|
12
|
+
};
|
13
|
+
use temporal_sdk_core_protos::{
|
14
|
+
coresdk::{
|
15
|
+
activity_result::{Cancellation, Failure as ActFail, Success},
|
16
|
+
activity_task::{activity_task, ActivityCancelReason, ActivityTask, Cancel, Start},
|
17
|
+
},
|
18
|
+
temporal::api::{common::v1::WorkflowExecution, enums::v1::TimeoutType},
|
19
|
+
};
|
20
|
+
use tokio::{
|
21
|
+
sync::{
|
22
|
+
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
23
|
+
Notify,
|
24
|
+
},
|
25
|
+
task::JoinHandle,
|
26
|
+
time::sleep,
|
27
|
+
};
|
28
|
+
use tokio_util::sync::CancellationToken;
|
29
|
+
|
30
|
+
#[allow(clippy::large_enum_variant)] // Timeouts are relatively rare
|
31
|
+
#[derive(Debug)]
|
32
|
+
pub(crate) enum DispatchOrTimeoutLA {
|
33
|
+
/// Send the activity task to lang
|
34
|
+
Dispatch(ActivityTask),
|
35
|
+
/// Notify the machines (and maybe lang) that this LA has timed out
|
36
|
+
Timeout {
|
37
|
+
run_id: String,
|
38
|
+
resolution: LocalActivityResolution,
|
39
|
+
task: Option<ActivityTask>,
|
40
|
+
},
|
41
|
+
}
|
42
|
+
|
43
|
+
#[derive(Debug)]
|
44
|
+
pub(crate) struct LocalInFlightActInfo {
|
45
|
+
pub la_info: NewLocalAct,
|
46
|
+
pub dispatch_time: Instant,
|
47
|
+
pub attempt: u32,
|
48
|
+
_permit: OwnedMeteredSemPermit,
|
49
|
+
}
|
50
|
+
|
51
|
+
#[derive(Debug, Clone)]
|
52
|
+
pub(crate) enum LocalActivityExecutionResult {
|
53
|
+
Completed(Success),
|
54
|
+
Failed(ActFail),
|
55
|
+
TimedOut(ActFail),
|
56
|
+
Cancelled(Cancellation),
|
57
|
+
}
|
58
|
+
impl LocalActivityExecutionResult {
|
59
|
+
pub(crate) fn empty_cancel() -> Self {
|
60
|
+
Self::Cancelled(Cancellation::from_details(None))
|
61
|
+
}
|
62
|
+
pub(crate) fn timeout(tt: TimeoutType) -> Self {
|
63
|
+
Self::TimedOut(ActFail::timeout(tt))
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
#[derive(Debug, Clone)]
|
68
|
+
pub(crate) struct LocalActivityResolution {
|
69
|
+
pub seq: u32,
|
70
|
+
pub result: LocalActivityExecutionResult,
|
71
|
+
pub runtime: Duration,
|
72
|
+
pub attempt: u32,
|
73
|
+
pub backoff: Option<prost_types::Duration>,
|
74
|
+
pub original_schedule_time: Option<SystemTime>,
|
75
|
+
}
|
76
|
+
|
77
|
+
#[derive(Clone)]
|
78
|
+
pub(crate) struct NewLocalAct {
|
79
|
+
pub schedule_cmd: ValidScheduleLA,
|
80
|
+
pub workflow_type: String,
|
81
|
+
pub workflow_exec_info: WorkflowExecution,
|
82
|
+
pub schedule_time: SystemTime,
|
83
|
+
}
|
84
|
+
impl Debug for NewLocalAct {
|
85
|
+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
86
|
+
write!(
|
87
|
+
f,
|
88
|
+
"LocalActivity({}, {})",
|
89
|
+
self.schedule_cmd.seq, self.schedule_cmd.activity_type
|
90
|
+
)
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
#[derive(Debug, derive_more::From)]
|
95
|
+
#[allow(clippy::large_enum_variant)]
|
96
|
+
pub(crate) enum LocalActRequest {
|
97
|
+
New(NewLocalAct),
|
98
|
+
Cancel(ExecutingLAId),
|
99
|
+
}
|
100
|
+
|
101
|
+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
102
|
+
pub(crate) struct ExecutingLAId {
|
103
|
+
pub run_id: String,
|
104
|
+
pub seq_num: u32,
|
105
|
+
}
|
106
|
+
|
107
|
+
pub(crate) struct LocalActivityManager {
|
108
|
+
/// Just so we can provide activity tasks the same namespace as the worker
|
109
|
+
namespace: String,
|
110
|
+
/// Constrains number of currently executing local activities
|
111
|
+
semaphore: MeteredSemaphore,
|
112
|
+
/// Sink for new activity execution requests
|
113
|
+
act_req_tx: UnboundedSender<NewOrRetry>,
|
114
|
+
/// Cancels need a different queue since they should be taken first, and don't take a permit
|
115
|
+
cancels_req_tx: UnboundedSender<CancelOrTimeout>,
|
116
|
+
/// Wakes every time a complete is processed
|
117
|
+
complete_notify: Notify,
|
118
|
+
|
119
|
+
rcvs: tokio::sync::Mutex<RcvChans>,
|
120
|
+
shutdown_complete_tok: CancellationToken,
|
121
|
+
dat: Mutex<LAMData>,
|
122
|
+
}
|
123
|
+
|
124
|
+
struct LAMData {
|
125
|
+
/// Activities that have been issued to lang but not yet completed
|
126
|
+
outstanding_activity_tasks: HashMap<TaskToken, LocalInFlightActInfo>,
|
127
|
+
id_to_tt: HashMap<ExecutingLAId, TaskToken>,
|
128
|
+
/// Tasks for activities which are currently backing off. May be used to cancel retrying them.
|
129
|
+
backing_off_tasks: HashMap<ExecutingLAId, JoinHandle<()>>,
|
130
|
+
/// Tasks for timing out activities which are currently in the queue or dispatched.
|
131
|
+
timeout_tasks: HashMap<ExecutingLAId, TimeoutBag>,
|
132
|
+
next_tt_num: u32,
|
133
|
+
}
|
134
|
+
|
135
|
+
impl LAMData {
|
136
|
+
fn gen_next_token(&mut self) -> TaskToken {
|
137
|
+
self.next_tt_num += 1;
|
138
|
+
TaskToken::new_local_activity_token(self.next_tt_num.to_le_bytes())
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
impl LocalActivityManager {
|
143
|
+
pub(crate) fn new(
|
144
|
+
max_concurrent: usize,
|
145
|
+
namespace: String,
|
146
|
+
metrics_context: MetricsContext,
|
147
|
+
) -> Self {
|
148
|
+
let (act_req_tx, act_req_rx) = unbounded_channel();
|
149
|
+
let (cancels_req_tx, cancels_req_rx) = unbounded_channel();
|
150
|
+
let shutdown_complete_tok = CancellationToken::new();
|
151
|
+
Self {
|
152
|
+
namespace,
|
153
|
+
semaphore: MeteredSemaphore::new(
|
154
|
+
max_concurrent,
|
155
|
+
metrics_context,
|
156
|
+
MetricsContext::available_task_slots,
|
157
|
+
),
|
158
|
+
act_req_tx,
|
159
|
+
cancels_req_tx,
|
160
|
+
complete_notify: Notify::new(),
|
161
|
+
rcvs: tokio::sync::Mutex::new(RcvChans {
|
162
|
+
act_req_rx,
|
163
|
+
cancels_req_rx,
|
164
|
+
shutdown: shutdown_complete_tok.clone(),
|
165
|
+
}),
|
166
|
+
shutdown_complete_tok,
|
167
|
+
dat: Mutex::new(LAMData {
|
168
|
+
outstanding_activity_tasks: Default::default(),
|
169
|
+
id_to_tt: Default::default(),
|
170
|
+
backing_off_tasks: Default::default(),
|
171
|
+
timeout_tasks: Default::default(),
|
172
|
+
next_tt_num: 0,
|
173
|
+
}),
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
#[cfg(test)]
|
178
|
+
fn test(max_concurrent: usize) -> Self {
|
179
|
+
Self::new(
|
180
|
+
max_concurrent,
|
181
|
+
"fake_ns".to_string(),
|
182
|
+
MetricsContext::no_op(),
|
183
|
+
)
|
184
|
+
}
|
185
|
+
|
186
|
+
#[cfg(test)]
|
187
|
+
pub(crate) fn num_outstanding(&self) -> usize {
|
188
|
+
self.dat.lock().outstanding_activity_tasks.len()
|
189
|
+
}
|
190
|
+
|
191
|
+
#[cfg(test)]
|
192
|
+
fn num_in_backoff(&self) -> usize {
|
193
|
+
self.dat.lock().backing_off_tasks.len()
|
194
|
+
}
|
195
|
+
|
196
|
+
pub(crate) fn enqueue(
|
197
|
+
&self,
|
198
|
+
reqs: impl IntoIterator<Item = LocalActRequest>,
|
199
|
+
) -> Vec<LocalActivityResolution> {
|
200
|
+
let mut immediate_resolutions = vec![];
|
201
|
+
for req in reqs {
|
202
|
+
debug!(local_activity = ?req, "Queuing local activity");
|
203
|
+
match req {
|
204
|
+
LocalActRequest::New(act) => {
|
205
|
+
let id = ExecutingLAId {
|
206
|
+
run_id: act.workflow_exec_info.run_id.clone(),
|
207
|
+
seq_num: act.schedule_cmd.seq,
|
208
|
+
};
|
209
|
+
let mut dlock = self.dat.lock();
|
210
|
+
if dlock.id_to_tt.contains_key(&id) {
|
211
|
+
// Do not queue local activities which are in fact already executing.
|
212
|
+
// This can happen during evictions.
|
213
|
+
debug!("Tried to queue already-executing local activity {:?}", &id);
|
214
|
+
continue;
|
215
|
+
}
|
216
|
+
// Pre-generate and insert the task token now, before we may or may not dispatch
|
217
|
+
// the activity, so we can enforce idempotency. Prevents two identical LAs
|
218
|
+
// ending up in the queue at once.
|
219
|
+
let tt = dlock.gen_next_token();
|
220
|
+
dlock.id_to_tt.insert(id.clone(), tt);
|
221
|
+
|
222
|
+
// Set up timeouts for the new activity
|
223
|
+
match TimeoutBag::new(&act, self.cancels_req_tx.clone()) {
|
224
|
+
Ok(tb) => {
|
225
|
+
dlock.timeout_tasks.insert(id, tb);
|
226
|
+
|
227
|
+
self.act_req_tx
|
228
|
+
.send(NewOrRetry::New(act))
|
229
|
+
.expect("Receive half of LA request channel cannot be dropped");
|
230
|
+
}
|
231
|
+
Err(res) => immediate_resolutions.push(res),
|
232
|
+
}
|
233
|
+
}
|
234
|
+
LocalActRequest::Cancel(id) => {
|
235
|
+
let mut dlock = self.dat.lock();
|
236
|
+
|
237
|
+
// First check if this ID is currently backing off, if so abort the backoff
|
238
|
+
// task
|
239
|
+
if let Some(t) = dlock.backing_off_tasks.remove(&id) {
|
240
|
+
t.abort();
|
241
|
+
immediate_resolutions.push(LocalActivityResolution {
|
242
|
+
seq: id.seq_num,
|
243
|
+
result: LocalActivityExecutionResult::Cancelled(
|
244
|
+
Cancellation::from_details(None),
|
245
|
+
),
|
246
|
+
runtime: Duration::from_secs(0),
|
247
|
+
attempt: 0,
|
248
|
+
backoff: None,
|
249
|
+
original_schedule_time: None,
|
250
|
+
});
|
251
|
+
continue;
|
252
|
+
}
|
253
|
+
|
254
|
+
if let Some(tt) = dlock.id_to_tt.get(&id) {
|
255
|
+
self.cancels_req_tx
|
256
|
+
.send(CancelOrTimeout::Cancel(ActivityTask {
|
257
|
+
task_token: tt.0.clone(),
|
258
|
+
variant: Some(activity_task::Variant::Cancel(Cancel {
|
259
|
+
reason: ActivityCancelReason::Cancelled as i32,
|
260
|
+
})),
|
261
|
+
}))
|
262
|
+
.expect("Receive half of LA cancel channel cannot be dropped");
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
immediate_resolutions
|
268
|
+
}
|
269
|
+
|
270
|
+
/// Returns the next pending local-activity related action, or None if shutdown has initiated
|
271
|
+
/// and there are no more remaining actions to take.
|
272
|
+
pub(crate) async fn next_pending(&self) -> Option<DispatchOrTimeoutLA> {
|
273
|
+
let (new_or_retry, permit) = match self.rcvs.lock().await.next(&self.semaphore).await? {
|
274
|
+
NewOrCancel::Cancel(c) => {
|
275
|
+
return match c {
|
276
|
+
CancelOrTimeout::Cancel(c) => Some(DispatchOrTimeoutLA::Dispatch(c)),
|
277
|
+
CancelOrTimeout::Timeout {
|
278
|
+
run_id,
|
279
|
+
resolution,
|
280
|
+
dispatch_cancel,
|
281
|
+
} => {
|
282
|
+
let task = if dispatch_cancel {
|
283
|
+
let tt = self
|
284
|
+
.dat
|
285
|
+
.lock()
|
286
|
+
.id_to_tt
|
287
|
+
.get(&ExecutingLAId {
|
288
|
+
run_id: run_id.clone(),
|
289
|
+
seq_num: resolution.seq,
|
290
|
+
})
|
291
|
+
.map(Clone::clone);
|
292
|
+
if let Some(task_token) = tt {
|
293
|
+
self.complete(&task_token, &resolution.result);
|
294
|
+
Some(ActivityTask {
|
295
|
+
task_token: task_token.0,
|
296
|
+
variant: Some(activity_task::Variant::Cancel(Cancel {
|
297
|
+
reason: ActivityCancelReason::TimedOut as i32,
|
298
|
+
})),
|
299
|
+
})
|
300
|
+
} else {
|
301
|
+
None
|
302
|
+
}
|
303
|
+
} else {
|
304
|
+
None
|
305
|
+
};
|
306
|
+
Some(DispatchOrTimeoutLA::Timeout {
|
307
|
+
run_id,
|
308
|
+
resolution,
|
309
|
+
task,
|
310
|
+
})
|
311
|
+
}
|
312
|
+
};
|
313
|
+
}
|
314
|
+
NewOrCancel::New(n, perm) => (n, perm),
|
315
|
+
};
|
316
|
+
|
317
|
+
// It is important that there are no await points after receiving from the channel, as
|
318
|
+
// it would mean dropping this future would cause us to drop the activity request.
|
319
|
+
let (new_la, attempt) = match new_or_retry {
|
320
|
+
NewOrRetry::New(n) => {
|
321
|
+
let explicit_attempt_num_or_1 = n.schedule_cmd.attempt.max(1);
|
322
|
+
(n, explicit_attempt_num_or_1)
|
323
|
+
}
|
324
|
+
NewOrRetry::Retry { in_flight, attempt } => (in_flight, attempt),
|
325
|
+
};
|
326
|
+
let la_info_for_in_flight_map = new_la.clone();
|
327
|
+
let id = ExecutingLAId {
|
328
|
+
run_id: new_la.workflow_exec_info.run_id.clone(),
|
329
|
+
seq_num: new_la.schedule_cmd.seq,
|
330
|
+
};
|
331
|
+
let orig_sched_time = new_la.schedule_cmd.original_schedule_time;
|
332
|
+
let sa = new_la.schedule_cmd;
|
333
|
+
|
334
|
+
let mut dat = self.dat.lock();
|
335
|
+
// If this request originated from a local backoff task, clear the entry for it. We
|
336
|
+
// don't await the handle because we know it must already be done, and there's no
|
337
|
+
// meaningful value.
|
338
|
+
dat.backing_off_tasks.remove(&id);
|
339
|
+
|
340
|
+
// If this task sat in the queue for too long, return a timeout for it instead
|
341
|
+
if let Some(s2s) = sa.schedule_to_start_timeout.as_ref() {
|
342
|
+
let sat_for = new_la.schedule_time.elapsed().unwrap_or_default();
|
343
|
+
if sat_for > *s2s {
|
344
|
+
return Some(DispatchOrTimeoutLA::Timeout {
|
345
|
+
run_id: new_la.workflow_exec_info.run_id,
|
346
|
+
resolution: LocalActivityResolution {
|
347
|
+
seq: sa.seq,
|
348
|
+
result: LocalActivityExecutionResult::timeout(TimeoutType::ScheduleToStart),
|
349
|
+
runtime: sat_for,
|
350
|
+
attempt,
|
351
|
+
backoff: None,
|
352
|
+
original_schedule_time: orig_sched_time,
|
353
|
+
},
|
354
|
+
task: None,
|
355
|
+
});
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
let tt = dat
|
360
|
+
.id_to_tt
|
361
|
+
.get(&id)
|
362
|
+
.expect("Task token must exist")
|
363
|
+
.clone();
|
364
|
+
dat.outstanding_activity_tasks.insert(
|
365
|
+
tt.clone(),
|
366
|
+
LocalInFlightActInfo {
|
367
|
+
la_info: la_info_for_in_flight_map,
|
368
|
+
dispatch_time: Instant::now(),
|
369
|
+
attempt,
|
370
|
+
_permit: permit,
|
371
|
+
},
|
372
|
+
);
|
373
|
+
if let Some(to) = dat.timeout_tasks.get_mut(&id) {
|
374
|
+
to.mark_started();
|
375
|
+
}
|
376
|
+
|
377
|
+
let (schedule_to_close, start_to_close) = sa.close_timeouts.into_sched_and_start();
|
378
|
+
Some(DispatchOrTimeoutLA::Dispatch(ActivityTask {
|
379
|
+
task_token: tt.0,
|
380
|
+
variant: Some(activity_task::Variant::Start(Start {
|
381
|
+
workflow_namespace: self.namespace.clone(),
|
382
|
+
workflow_type: new_la.workflow_type,
|
383
|
+
workflow_execution: Some(new_la.workflow_exec_info),
|
384
|
+
activity_id: sa.activity_id,
|
385
|
+
activity_type: sa.activity_type,
|
386
|
+
header_fields: sa.headers,
|
387
|
+
input: sa.arguments,
|
388
|
+
heartbeat_details: vec![],
|
389
|
+
scheduled_time: Some(new_la.schedule_time.into()),
|
390
|
+
current_attempt_scheduled_time: Some(new_la.schedule_time.into()),
|
391
|
+
started_time: Some(SystemTime::now().into()),
|
392
|
+
attempt,
|
393
|
+
schedule_to_close_timeout: schedule_to_close.and_then(|d| d.try_into().ok()),
|
394
|
+
start_to_close_timeout: start_to_close.and_then(|d| d.try_into().ok()),
|
395
|
+
heartbeat_timeout: None,
|
396
|
+
retry_policy: Some(sa.retry_policy),
|
397
|
+
is_local: true,
|
398
|
+
})),
|
399
|
+
}))
|
400
|
+
}
|
401
|
+
|
402
|
+
/// Mark a local activity as having completed (pass, fail, or cancelled)
|
403
|
+
pub(crate) fn complete(
|
404
|
+
&self,
|
405
|
+
task_token: &TaskToken,
|
406
|
+
status: &LocalActivityExecutionResult,
|
407
|
+
) -> LACompleteAction {
|
408
|
+
let mut dlock = self.dat.lock();
|
409
|
+
if let Some(info) = dlock.outstanding_activity_tasks.remove(task_token) {
|
410
|
+
let exec_id = ExecutingLAId {
|
411
|
+
run_id: info.la_info.workflow_exec_info.run_id.clone(),
|
412
|
+
seq_num: info.la_info.schedule_cmd.seq,
|
413
|
+
};
|
414
|
+
dlock.id_to_tt.remove(&exec_id);
|
415
|
+
|
416
|
+
match status {
|
417
|
+
LocalActivityExecutionResult::Completed(_)
|
418
|
+
| LocalActivityExecutionResult::TimedOut(_)
|
419
|
+
| LocalActivityExecutionResult::Cancelled { .. } => {
|
420
|
+
// Timeouts are included in this branch since they are not retried
|
421
|
+
self.complete_notify.notify_one();
|
422
|
+
LACompleteAction::Report(info)
|
423
|
+
}
|
424
|
+
LocalActivityExecutionResult::Failed(f) => {
|
425
|
+
if let Some(backoff_dur) = info.la_info.schedule_cmd.retry_policy.should_retry(
|
426
|
+
info.attempt as usize,
|
427
|
+
f.failure
|
428
|
+
.as_ref()
|
429
|
+
.and_then(|f| f.maybe_application_failure()),
|
430
|
+
) {
|
431
|
+
let will_use_timer =
|
432
|
+
backoff_dur > info.la_info.schedule_cmd.local_retry_threshold;
|
433
|
+
debug!(run_id = %info.la_info.workflow_exec_info.run_id,
|
434
|
+
seq_num = %info.la_info.schedule_cmd.seq,
|
435
|
+
attempt = %info.attempt,
|
436
|
+
will_use_timer,
|
437
|
+
"Local activity failed, will retry after backing off for {:?}",
|
438
|
+
backoff_dur
|
439
|
+
);
|
440
|
+
if will_use_timer {
|
441
|
+
// We want this to be reported, as the workflow will mark this
|
442
|
+
// failure down, then start a timer for backoff.
|
443
|
+
return LACompleteAction::LangDoesTimerBackoff(
|
444
|
+
backoff_dur.try_into().expect("backoff fits into proto"),
|
445
|
+
info,
|
446
|
+
);
|
447
|
+
}
|
448
|
+
// Immediately create a new task token for the to-be-retried LA
|
449
|
+
let tt = dlock.gen_next_token();
|
450
|
+
dlock.id_to_tt.insert(exec_id.clone(), tt);
|
451
|
+
|
452
|
+
// Send the retry request after waiting the backoff duration
|
453
|
+
let send_chan = self.act_req_tx.clone();
|
454
|
+
let jh = tokio::spawn(async move {
|
455
|
+
tokio::time::sleep(backoff_dur).await;
|
456
|
+
|
457
|
+
send_chan
|
458
|
+
.send(NewOrRetry::Retry {
|
459
|
+
in_flight: info.la_info,
|
460
|
+
attempt: info.attempt + 1,
|
461
|
+
})
|
462
|
+
.expect("Receive half of LA request channel cannot be dropped");
|
463
|
+
});
|
464
|
+
dlock.backing_off_tasks.insert(exec_id, jh);
|
465
|
+
|
466
|
+
LACompleteAction::WillBeRetried
|
467
|
+
} else {
|
468
|
+
LACompleteAction::Report(info)
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
} else {
|
473
|
+
LACompleteAction::Untracked
|
474
|
+
}
|
475
|
+
}
|
476
|
+
|
477
|
+
pub(crate) async fn shutdown_and_wait_all_finished(&self) {
|
478
|
+
while !self.dat.lock().outstanding_activity_tasks.is_empty() {
|
479
|
+
self.complete_notify.notified().await;
|
480
|
+
}
|
481
|
+
self.shutdown_complete_tok.cancel();
|
482
|
+
}
|
483
|
+
}
|
484
|
+
|
485
|
+
#[derive(Debug)]
|
486
|
+
#[allow(clippy::large_enum_variant)] // Most will be reported
|
487
|
+
pub(crate) enum LACompleteAction {
|
488
|
+
/// Caller should report the status to the workflow
|
489
|
+
Report(LocalInFlightActInfo),
|
490
|
+
/// Lang needs to be told to do the schedule-a-timer-then-rerun hack
|
491
|
+
LangDoesTimerBackoff(prost_types::Duration, LocalInFlightActInfo),
|
492
|
+
/// The activity will be re-enqueued for another attempt (and so status should not be reported
|
493
|
+
/// to the workflow)
|
494
|
+
WillBeRetried,
|
495
|
+
/// The activity was unknown
|
496
|
+
Untracked,
|
497
|
+
}
|
498
|
+
|
499
|
+
#[derive(Debug)]
|
500
|
+
enum NewOrRetry {
|
501
|
+
New(NewLocalAct),
|
502
|
+
Retry {
|
503
|
+
in_flight: NewLocalAct,
|
504
|
+
attempt: u32,
|
505
|
+
},
|
506
|
+
}
|
507
|
+
|
508
|
+
#[allow(clippy::large_enum_variant)]
|
509
|
+
#[derive(Debug, Clone)]
|
510
|
+
enum CancelOrTimeout {
|
511
|
+
Cancel(ActivityTask),
|
512
|
+
Timeout {
|
513
|
+
run_id: String,
|
514
|
+
resolution: LocalActivityResolution,
|
515
|
+
dispatch_cancel: bool,
|
516
|
+
},
|
517
|
+
}
|
518
|
+
|
519
|
+
#[allow(clippy::large_enum_variant)]
|
520
|
+
enum NewOrCancel {
|
521
|
+
New(NewOrRetry, OwnedMeteredSemPermit),
|
522
|
+
Cancel(CancelOrTimeout),
|
523
|
+
}
|
524
|
+
|
525
|
+
struct RcvChans {
|
526
|
+
/// Activities that need to be executed by lang
|
527
|
+
act_req_rx: UnboundedReceiver<NewOrRetry>,
|
528
|
+
/// Cancels to send to lang or apply internally
|
529
|
+
cancels_req_rx: UnboundedReceiver<CancelOrTimeout>,
|
530
|
+
shutdown: CancellationToken,
|
531
|
+
}
|
532
|
+
|
533
|
+
impl RcvChans {
|
534
|
+
async fn next(&mut self, new_sem: &MeteredSemaphore) -> Option<NewOrCancel> {
|
535
|
+
tokio::select! {
|
536
|
+
cancel = async { self.cancels_req_rx.recv().await } => {
|
537
|
+
Some(NewOrCancel::Cancel(cancel.expect("Send halves of LA manager are not dropped")))
|
538
|
+
}
|
539
|
+
(maybe_new_or_retry, perm) = async {
|
540
|
+
// Wait for a permit to take a task and forget it. Permits are removed until a
|
541
|
+
// completion.
|
542
|
+
let perm = new_sem.acquire_owned().await.expect("is never closed");
|
543
|
+
(self.act_req_rx.recv().await, perm)
|
544
|
+
} => Some(NewOrCancel::New(
|
545
|
+
maybe_new_or_retry.expect("Send halves of LA manager are not dropped"), perm
|
546
|
+
)),
|
547
|
+
_ = self.shutdown.cancelled() => None
|
548
|
+
}
|
549
|
+
}
|
550
|
+
}
|
551
|
+
|
552
|
+
struct TimeoutBag {
|
553
|
+
sched_to_close_handle: JoinHandle<()>,
|
554
|
+
start_to_close_dur_and_dat: Option<(Duration, CancelOrTimeout)>,
|
555
|
+
start_to_close_handle: Option<JoinHandle<()>>,
|
556
|
+
cancel_chan: UnboundedSender<CancelOrTimeout>,
|
557
|
+
}
|
558
|
+
|
559
|
+
impl TimeoutBag {
|
560
|
+
/// Create new timeout tasks for the provided local activity. This must be called as soon
|
561
|
+
/// as request to schedule it arrives.
|
562
|
+
///
|
563
|
+
/// Returns error in the event the activity is *already* timed out
|
564
|
+
fn new(
|
565
|
+
new_la: &NewLocalAct,
|
566
|
+
cancel_chan: UnboundedSender<CancelOrTimeout>,
|
567
|
+
) -> Result<TimeoutBag, LocalActivityResolution> {
|
568
|
+
let (schedule_to_close, start_to_close) =
|
569
|
+
new_la.schedule_cmd.close_timeouts.into_sched_and_start();
|
570
|
+
|
571
|
+
let sched_time = new_la
|
572
|
+
.schedule_cmd
|
573
|
+
.original_schedule_time
|
574
|
+
.unwrap_or(new_la.schedule_time);
|
575
|
+
let resolution = LocalActivityResolution {
|
576
|
+
seq: new_la.schedule_cmd.seq,
|
577
|
+
result: LocalActivityExecutionResult::timeout(TimeoutType::ScheduleToClose),
|
578
|
+
runtime: Default::default(),
|
579
|
+
attempt: new_la.schedule_cmd.attempt,
|
580
|
+
backoff: None,
|
581
|
+
original_schedule_time: new_la.schedule_cmd.original_schedule_time,
|
582
|
+
};
|
583
|
+
// Remove any time already elapsed since the scheduling time
|
584
|
+
let schedule_to_close = schedule_to_close
|
585
|
+
.map(|s2c| s2c.saturating_sub(sched_time.elapsed().unwrap_or_default()));
|
586
|
+
if let Some(ref s2c) = schedule_to_close {
|
587
|
+
if s2c.is_zero() {
|
588
|
+
return Err(resolution);
|
589
|
+
}
|
590
|
+
}
|
591
|
+
let timeout_dat = CancelOrTimeout::Timeout {
|
592
|
+
run_id: new_la.workflow_exec_info.run_id.clone(),
|
593
|
+
resolution,
|
594
|
+
dispatch_cancel: true,
|
595
|
+
};
|
596
|
+
let start_to_close_dur_and_dat = start_to_close.map(|d| (d, timeout_dat.clone()));
|
597
|
+
let fut_dat = schedule_to_close.map(|s2c| (s2c, timeout_dat));
|
598
|
+
|
599
|
+
let cancel_chan_clone = cancel_chan.clone();
|
600
|
+
let scheduling = tokio::spawn(async move {
|
601
|
+
if let Some((timeout, dat)) = fut_dat {
|
602
|
+
sleep(timeout).await;
|
603
|
+
cancel_chan_clone
|
604
|
+
.send(dat)
|
605
|
+
.expect("receive half not dropped");
|
606
|
+
}
|
607
|
+
});
|
608
|
+
Ok(TimeoutBag {
|
609
|
+
sched_to_close_handle: scheduling,
|
610
|
+
start_to_close_dur_and_dat,
|
611
|
+
start_to_close_handle: None,
|
612
|
+
cancel_chan,
|
613
|
+
})
|
614
|
+
}
|
615
|
+
|
616
|
+
/// Must be called once the associated local activity has been started / dispatched to lang.
|
617
|
+
fn mark_started(&mut self) {
|
618
|
+
if let Some((start_to_close, mut dat)) = self.start_to_close_dur_and_dat.take() {
|
619
|
+
let started_t = Instant::now();
|
620
|
+
let cchan = self.cancel_chan.clone();
|
621
|
+
self.start_to_close_handle = Some(tokio::spawn(async move {
|
622
|
+
sleep(start_to_close).await;
|
623
|
+
if let CancelOrTimeout::Timeout { resolution, .. } = &mut dat {
|
624
|
+
resolution.result =
|
625
|
+
LocalActivityExecutionResult::timeout(TimeoutType::StartToClose);
|
626
|
+
resolution.runtime = started_t.elapsed();
|
627
|
+
}
|
628
|
+
|
629
|
+
cchan.send(dat).expect("receive half not dropped");
|
630
|
+
}));
|
631
|
+
}
|
632
|
+
}
|
633
|
+
}
|
634
|
+
|
635
|
+
impl Drop for TimeoutBag {
|
636
|
+
fn drop(&mut self) {
|
637
|
+
self.sched_to_close_handle.abort();
|
638
|
+
if let Some(x) = self.start_to_close_handle.as_ref() {
|
639
|
+
x.abort()
|
640
|
+
}
|
641
|
+
}
|
642
|
+
}
|
643
|
+
|
644
|
+
#[cfg(test)]
|
645
|
+
mod tests {
|
646
|
+
use super::*;
|
647
|
+
use crate::{prost_dur, protosext::LACloseTimeouts};
|
648
|
+
use temporal_sdk_core_protos::temporal::api::{
|
649
|
+
common::v1::RetryPolicy,
|
650
|
+
failure::v1::{failure::FailureInfo, ApplicationFailureInfo, Failure},
|
651
|
+
};
|
652
|
+
use tokio::{sync::mpsc::error::TryRecvError, task::yield_now};
|
653
|
+
|
654
|
+
impl DispatchOrTimeoutLA {
|
655
|
+
fn unwrap(self) -> ActivityTask {
|
656
|
+
match self {
|
657
|
+
DispatchOrTimeoutLA::Dispatch(t) => t,
|
658
|
+
DispatchOrTimeoutLA::Timeout { .. } => {
|
659
|
+
panic!("Timeout returned when expected a task")
|
660
|
+
}
|
661
|
+
}
|
662
|
+
}
|
663
|
+
}
|
664
|
+
|
665
|
+
#[tokio::test]
|
666
|
+
async fn max_concurrent_respected() {
|
667
|
+
let lam = LocalActivityManager::test(1);
|
668
|
+
lam.enqueue((1..=50).map(|i| {
|
669
|
+
NewLocalAct {
|
670
|
+
schedule_cmd: ValidScheduleLA {
|
671
|
+
seq: i,
|
672
|
+
activity_id: i.to_string(),
|
673
|
+
..Default::default()
|
674
|
+
},
|
675
|
+
workflow_type: "".to_string(),
|
676
|
+
workflow_exec_info: Default::default(),
|
677
|
+
schedule_time: SystemTime::now(),
|
678
|
+
}
|
679
|
+
.into()
|
680
|
+
}));
|
681
|
+
for i in 1..=50 {
|
682
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
683
|
+
assert_matches!(
|
684
|
+
next.variant.unwrap(),
|
685
|
+
activity_task::Variant::Start(Start {activity_id, ..})
|
686
|
+
if activity_id == i.to_string()
|
687
|
+
);
|
688
|
+
let next_tt = TaskToken(next.task_token);
|
689
|
+
let complete_branch = async {
|
690
|
+
lam.complete(
|
691
|
+
&next_tt,
|
692
|
+
&LocalActivityExecutionResult::Completed(Default::default()),
|
693
|
+
)
|
694
|
+
};
|
695
|
+
tokio::select! {
|
696
|
+
// Next call will not resolve until we complete the first
|
697
|
+
_ = lam.next_pending() => {
|
698
|
+
panic!("Branch must not be selected")
|
699
|
+
}
|
700
|
+
_ = complete_branch => {}
|
701
|
+
}
|
702
|
+
}
|
703
|
+
}
|
704
|
+
|
705
|
+
#[tokio::test]
|
706
|
+
async fn no_work_doesnt_deadlock_with_complete() {
|
707
|
+
let lam = LocalActivityManager::test(5);
|
708
|
+
lam.enqueue([NewLocalAct {
|
709
|
+
schedule_cmd: ValidScheduleLA {
|
710
|
+
seq: 1,
|
711
|
+
activity_id: 1.to_string(),
|
712
|
+
..Default::default()
|
713
|
+
},
|
714
|
+
workflow_type: "".to_string(),
|
715
|
+
workflow_exec_info: Default::default(),
|
716
|
+
schedule_time: SystemTime::now(),
|
717
|
+
}
|
718
|
+
.into()]);
|
719
|
+
|
720
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
721
|
+
let tt = TaskToken(next.task_token);
|
722
|
+
tokio::select! {
|
723
|
+
biased;
|
724
|
+
|
725
|
+
_ = lam.next_pending() => {
|
726
|
+
panic!("Complete branch must win")
|
727
|
+
}
|
728
|
+
_ = async {
|
729
|
+
// Spin until the receive lock has been grabbed by the call to pending, to ensure
|
730
|
+
// it's advanced enough
|
731
|
+
while lam.rcvs.try_lock().is_ok() { yield_now().await; }
|
732
|
+
lam.complete(&tt, &LocalActivityExecutionResult::Completed(Default::default()));
|
733
|
+
} => (),
|
734
|
+
};
|
735
|
+
}
|
736
|
+
|
737
|
+
#[tokio::test]
|
738
|
+
async fn can_cancel_in_flight() {
|
739
|
+
let lam = LocalActivityManager::test(5);
|
740
|
+
lam.enqueue([NewLocalAct {
|
741
|
+
schedule_cmd: ValidScheduleLA {
|
742
|
+
seq: 1,
|
743
|
+
activity_id: 1.to_string(),
|
744
|
+
..Default::default()
|
745
|
+
},
|
746
|
+
workflow_type: "".to_string(),
|
747
|
+
workflow_exec_info: WorkflowExecution {
|
748
|
+
workflow_id: "".to_string(),
|
749
|
+
run_id: "run_id".to_string(),
|
750
|
+
},
|
751
|
+
schedule_time: SystemTime::now(),
|
752
|
+
}
|
753
|
+
.into()]);
|
754
|
+
lam.next_pending().await.unwrap().unwrap();
|
755
|
+
|
756
|
+
lam.enqueue([LocalActRequest::Cancel(ExecutingLAId {
|
757
|
+
run_id: "run_id".to_string(),
|
758
|
+
seq_num: 1,
|
759
|
+
})]);
|
760
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
761
|
+
assert_matches!(next.variant.unwrap(), activity_task::Variant::Cancel(_));
|
762
|
+
}
|
763
|
+
|
764
|
+
#[tokio::test]
|
765
|
+
async fn respects_timer_backoff_threshold() {
|
766
|
+
let lam = LocalActivityManager::test(1);
|
767
|
+
lam.enqueue([NewLocalAct {
|
768
|
+
schedule_cmd: ValidScheduleLA {
|
769
|
+
seq: 1,
|
770
|
+
activity_id: 1.to_string(),
|
771
|
+
attempt: 5,
|
772
|
+
retry_policy: RetryPolicy {
|
773
|
+
initial_interval: Some(prost_dur!(from_secs(1))),
|
774
|
+
backoff_coefficient: 10.0,
|
775
|
+
maximum_interval: Some(prost_dur!(from_secs(10))),
|
776
|
+
maximum_attempts: 10,
|
777
|
+
non_retryable_error_types: vec![],
|
778
|
+
},
|
779
|
+
local_retry_threshold: Duration::from_secs(5),
|
780
|
+
..Default::default()
|
781
|
+
},
|
782
|
+
workflow_type: "".to_string(),
|
783
|
+
workflow_exec_info: Default::default(),
|
784
|
+
schedule_time: SystemTime::now(),
|
785
|
+
}
|
786
|
+
.into()]);
|
787
|
+
|
788
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
789
|
+
let tt = TaskToken(next.task_token);
|
790
|
+
let res = lam.complete(
|
791
|
+
&tt,
|
792
|
+
&LocalActivityExecutionResult::Failed(Default::default()),
|
793
|
+
);
|
794
|
+
assert_matches!(res, LACompleteAction::LangDoesTimerBackoff(dur, info)
|
795
|
+
if dur.seconds == 10 && info.attempt == 5
|
796
|
+
)
|
797
|
+
}
|
798
|
+
|
799
|
+
#[tokio::test]
|
800
|
+
async fn respects_non_retryable_error_types() {
|
801
|
+
let lam = LocalActivityManager::test(1);
|
802
|
+
lam.enqueue([NewLocalAct {
|
803
|
+
schedule_cmd: ValidScheduleLA {
|
804
|
+
seq: 1,
|
805
|
+
activity_id: "1".to_string(),
|
806
|
+
attempt: 1,
|
807
|
+
retry_policy: RetryPolicy {
|
808
|
+
initial_interval: Some(prost_dur!(from_secs(1))),
|
809
|
+
backoff_coefficient: 10.0,
|
810
|
+
maximum_interval: Some(prost_dur!(from_secs(10))),
|
811
|
+
maximum_attempts: 10,
|
812
|
+
non_retryable_error_types: vec!["TestError".to_string()],
|
813
|
+
},
|
814
|
+
local_retry_threshold: Duration::from_secs(5),
|
815
|
+
..Default::default()
|
816
|
+
},
|
817
|
+
workflow_type: "".to_string(),
|
818
|
+
workflow_exec_info: Default::default(),
|
819
|
+
schedule_time: SystemTime::now(),
|
820
|
+
}
|
821
|
+
.into()]);
|
822
|
+
|
823
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
824
|
+
let tt = TaskToken(next.task_token);
|
825
|
+
let res = lam.complete(
|
826
|
+
&tt,
|
827
|
+
&LocalActivityExecutionResult::Failed(ActFail {
|
828
|
+
failure: Some(Failure {
|
829
|
+
failure_info: Some(FailureInfo::ApplicationFailureInfo(
|
830
|
+
ApplicationFailureInfo {
|
831
|
+
r#type: "TestError".to_string(),
|
832
|
+
non_retryable: false,
|
833
|
+
..Default::default()
|
834
|
+
},
|
835
|
+
)),
|
836
|
+
..Default::default()
|
837
|
+
}),
|
838
|
+
}),
|
839
|
+
);
|
840
|
+
assert_matches!(res, LACompleteAction::Report(_));
|
841
|
+
}
|
842
|
+
|
843
|
+
#[tokio::test]
|
844
|
+
async fn can_cancel_during_local_backoff() {
|
845
|
+
let lam = LocalActivityManager::test(1);
|
846
|
+
lam.enqueue([NewLocalAct {
|
847
|
+
schedule_cmd: ValidScheduleLA {
|
848
|
+
seq: 1,
|
849
|
+
activity_id: 1.to_string(),
|
850
|
+
attempt: 5,
|
851
|
+
retry_policy: RetryPolicy {
|
852
|
+
initial_interval: Some(prost_dur!(from_secs(10))),
|
853
|
+
backoff_coefficient: 1.0,
|
854
|
+
maximum_interval: Some(prost_dur!(from_secs(10))),
|
855
|
+
maximum_attempts: 10,
|
856
|
+
non_retryable_error_types: vec![],
|
857
|
+
},
|
858
|
+
local_retry_threshold: Duration::from_secs(500),
|
859
|
+
..Default::default()
|
860
|
+
},
|
861
|
+
workflow_type: "".to_string(),
|
862
|
+
workflow_exec_info: WorkflowExecution {
|
863
|
+
workflow_id: "".to_string(),
|
864
|
+
run_id: "run_id".to_string(),
|
865
|
+
},
|
866
|
+
schedule_time: SystemTime::now(),
|
867
|
+
}
|
868
|
+
.into()]);
|
869
|
+
|
870
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
871
|
+
let tt = TaskToken(next.task_token);
|
872
|
+
lam.complete(
|
873
|
+
&tt,
|
874
|
+
&LocalActivityExecutionResult::Failed(Default::default()),
|
875
|
+
);
|
876
|
+
// Cancel the activity, which is performing local backoff
|
877
|
+
let immediate_res = lam.enqueue([LocalActRequest::Cancel(ExecutingLAId {
|
878
|
+
run_id: "run_id".to_string(),
|
879
|
+
seq_num: 1,
|
880
|
+
})]);
|
881
|
+
// It should not be present in the backoff tasks
|
882
|
+
assert_eq!(lam.num_in_backoff(), 0);
|
883
|
+
assert_eq!(lam.num_outstanding(), 0);
|
884
|
+
// It should return a resolution to cancel
|
885
|
+
assert_eq!(immediate_res.len(), 1);
|
886
|
+
assert_matches!(
|
887
|
+
immediate_res[0].result,
|
888
|
+
LocalActivityExecutionResult::Cancelled { .. }
|
889
|
+
);
|
890
|
+
}
|
891
|
+
|
892
|
+
#[tokio::test]
|
893
|
+
async fn local_backoff_clears_handle_map_when_started() {
|
894
|
+
let lam = LocalActivityManager::test(1);
|
895
|
+
lam.enqueue([NewLocalAct {
|
896
|
+
schedule_cmd: ValidScheduleLA {
|
897
|
+
seq: 1,
|
898
|
+
activity_id: 1.to_string(),
|
899
|
+
attempt: 5,
|
900
|
+
retry_policy: RetryPolicy {
|
901
|
+
initial_interval: Some(prost_dur!(from_millis(10))),
|
902
|
+
backoff_coefficient: 1.0,
|
903
|
+
..Default::default()
|
904
|
+
},
|
905
|
+
local_retry_threshold: Duration::from_secs(500),
|
906
|
+
..Default::default()
|
907
|
+
},
|
908
|
+
workflow_type: "".to_string(),
|
909
|
+
workflow_exec_info: WorkflowExecution {
|
910
|
+
workflow_id: "".to_string(),
|
911
|
+
run_id: "run_id".to_string(),
|
912
|
+
},
|
913
|
+
schedule_time: SystemTime::now(),
|
914
|
+
}
|
915
|
+
.into()]);
|
916
|
+
|
917
|
+
let next = lam.next_pending().await.unwrap().unwrap();
|
918
|
+
let tt = TaskToken(next.task_token);
|
919
|
+
lam.complete(
|
920
|
+
&tt,
|
921
|
+
&LocalActivityExecutionResult::Failed(Default::default()),
|
922
|
+
);
|
923
|
+
lam.next_pending().await.unwrap().unwrap();
|
924
|
+
assert_eq!(lam.num_in_backoff(), 0);
|
925
|
+
assert_eq!(lam.num_outstanding(), 1);
|
926
|
+
}
|
927
|
+
|
928
|
+
#[tokio::test]
|
929
|
+
async fn sched_to_start_timeout() {
|
930
|
+
let lam = LocalActivityManager::test(1);
|
931
|
+
let timeout = Duration::from_millis(100);
|
932
|
+
lam.enqueue([NewLocalAct {
|
933
|
+
schedule_cmd: ValidScheduleLA {
|
934
|
+
seq: 1,
|
935
|
+
activity_id: 1.to_string(),
|
936
|
+
attempt: 5,
|
937
|
+
retry_policy: RetryPolicy {
|
938
|
+
initial_interval: Some(prost_dur!(from_millis(10))),
|
939
|
+
backoff_coefficient: 1.0,
|
940
|
+
..Default::default()
|
941
|
+
},
|
942
|
+
local_retry_threshold: Duration::from_secs(500),
|
943
|
+
schedule_to_start_timeout: Some(timeout),
|
944
|
+
..Default::default()
|
945
|
+
},
|
946
|
+
workflow_type: "".to_string(),
|
947
|
+
workflow_exec_info: WorkflowExecution {
|
948
|
+
workflow_id: "".to_string(),
|
949
|
+
run_id: "run_id".to_string(),
|
950
|
+
},
|
951
|
+
schedule_time: SystemTime::now(),
|
952
|
+
}
|
953
|
+
.into()]);
|
954
|
+
|
955
|
+
// Wait more than the timeout before grabbing the task
|
956
|
+
sleep(timeout + Duration::from_millis(10)).await;
|
957
|
+
|
958
|
+
assert_matches!(
|
959
|
+
lam.next_pending().await.unwrap(),
|
960
|
+
DispatchOrTimeoutLA::Timeout { .. }
|
961
|
+
);
|
962
|
+
assert_eq!(lam.num_in_backoff(), 0);
|
963
|
+
assert_eq!(lam.num_outstanding(), 0);
|
964
|
+
}
|
965
|
+
|
966
|
+
#[rstest::rstest]
|
967
|
+
#[case::schedule(true)]
|
968
|
+
#[case::start(false)]
|
969
|
+
#[tokio::test]
|
970
|
+
async fn local_x_to_close_timeout(#[case] is_schedule: bool) {
|
971
|
+
let lam = LocalActivityManager::test(1);
|
972
|
+
let timeout = Duration::from_millis(100);
|
973
|
+
let close_timeouts = if is_schedule {
|
974
|
+
LACloseTimeouts::ScheduleOnly(timeout)
|
975
|
+
} else {
|
976
|
+
LACloseTimeouts::StartOnly(timeout)
|
977
|
+
};
|
978
|
+
lam.enqueue([NewLocalAct {
|
979
|
+
schedule_cmd: ValidScheduleLA {
|
980
|
+
seq: 1,
|
981
|
+
activity_id: 1.to_string(),
|
982
|
+
attempt: 5,
|
983
|
+
retry_policy: RetryPolicy {
|
984
|
+
initial_interval: Some(prost_dur!(from_millis(10))),
|
985
|
+
backoff_coefficient: 1.0,
|
986
|
+
..Default::default()
|
987
|
+
},
|
988
|
+
local_retry_threshold: Duration::from_secs(500),
|
989
|
+
close_timeouts,
|
990
|
+
..Default::default()
|
991
|
+
},
|
992
|
+
workflow_type: "".to_string(),
|
993
|
+
workflow_exec_info: WorkflowExecution {
|
994
|
+
workflow_id: "".to_string(),
|
995
|
+
run_id: "run_id".to_string(),
|
996
|
+
},
|
997
|
+
schedule_time: SystemTime::now(),
|
998
|
+
}
|
999
|
+
.into()]);
|
1000
|
+
|
1001
|
+
lam.next_pending().await.unwrap().unwrap();
|
1002
|
+
assert_eq!(lam.num_in_backoff(), 0);
|
1003
|
+
assert_eq!(lam.num_outstanding(), 1);
|
1004
|
+
|
1005
|
+
sleep(timeout + Duration::from_millis(10)).await;
|
1006
|
+
assert_matches!(
|
1007
|
+
lam.next_pending().await.unwrap(),
|
1008
|
+
DispatchOrTimeoutLA::Timeout { .. }
|
1009
|
+
);
|
1010
|
+
assert_eq!(lam.num_outstanding(), 0);
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
#[tokio::test]
|
1014
|
+
async fn idempotency_enforced() {
|
1015
|
+
let lam = LocalActivityManager::test(10);
|
1016
|
+
let new_la = NewLocalAct {
|
1017
|
+
schedule_cmd: ValidScheduleLA {
|
1018
|
+
seq: 1,
|
1019
|
+
activity_id: 1.to_string(),
|
1020
|
+
..Default::default()
|
1021
|
+
},
|
1022
|
+
workflow_type: "".to_string(),
|
1023
|
+
workflow_exec_info: WorkflowExecution {
|
1024
|
+
workflow_id: "".to_string(),
|
1025
|
+
run_id: "run_id".to_string(),
|
1026
|
+
},
|
1027
|
+
schedule_time: SystemTime::now(),
|
1028
|
+
};
|
1029
|
+
// Verify only one will get queued
|
1030
|
+
lam.enqueue([new_la.clone().into(), new_la.clone().into()]);
|
1031
|
+
lam.next_pending().await.unwrap().unwrap();
|
1032
|
+
assert_eq!(lam.num_outstanding(), 1);
|
1033
|
+
// There should be nothing else in the queue
|
1034
|
+
assert_eq!(
|
1035
|
+
lam.rcvs.lock().await.act_req_rx.try_recv().unwrap_err(),
|
1036
|
+
TryRecvError::Empty
|
1037
|
+
);
|
1038
|
+
|
1039
|
+
// Verify that if we now enqueue the same act again, after the task is outstanding, we still
|
1040
|
+
// don't add it.
|
1041
|
+
lam.enqueue([new_la.into()]);
|
1042
|
+
assert_eq!(lam.num_outstanding(), 1);
|
1043
|
+
assert_eq!(
|
1044
|
+
lam.rcvs.lock().await.act_req_rx.try_recv().unwrap_err(),
|
1045
|
+
TryRecvError::Empty
|
1046
|
+
);
|
1047
|
+
}
|
1048
|
+
}
|