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,751 @@
|
|
1
|
+
use crate::{
|
2
|
+
ClientOptions, ListClosedFilters, ListOpenFilters, Namespace, Result, RetryConfig,
|
3
|
+
StartTimeFilter, WorkflowClientTrait, WorkflowOptions,
|
4
|
+
};
|
5
|
+
use backoff::{backoff::Backoff, exponential::ExponentialBackoff, Clock, SystemClock};
|
6
|
+
use futures_retry::{ErrorHandler, FutureRetry, RetryPolicy};
|
7
|
+
use std::{fmt::Debug, future::Future, sync::Arc, time::Duration};
|
8
|
+
use temporal_sdk_core_protos::{
|
9
|
+
coresdk::workflow_commands::QueryResult,
|
10
|
+
temporal::api::{
|
11
|
+
common::v1::{Header, Payload, Payloads},
|
12
|
+
enums::v1::WorkflowTaskFailedCause,
|
13
|
+
failure::v1::Failure,
|
14
|
+
query::v1::WorkflowQuery,
|
15
|
+
workflowservice::v1::*,
|
16
|
+
},
|
17
|
+
TaskToken,
|
18
|
+
};
|
19
|
+
use tonic::Code;
|
20
|
+
|
21
|
+
/// List of gRPC error codes that client will retry.
|
22
|
+
pub const RETRYABLE_ERROR_CODES: [Code; 7] = [
|
23
|
+
Code::DataLoss,
|
24
|
+
Code::Internal,
|
25
|
+
Code::Unknown,
|
26
|
+
Code::ResourceExhausted,
|
27
|
+
Code::Aborted,
|
28
|
+
Code::OutOfRange,
|
29
|
+
Code::Unavailable,
|
30
|
+
];
|
31
|
+
const LONG_POLL_FATAL_GRACE: Duration = Duration::from_secs(60);
|
32
|
+
/// Must match the method name in [crate::raw::WorkflowService]
|
33
|
+
const POLL_WORKFLOW_METH_NAME: &str = "poll_workflow_task_queue";
|
34
|
+
/// Must match the method name in [crate::raw::WorkflowService]
|
35
|
+
const POLL_ACTIVITY_METH_NAME: &str = "poll_activity_task_queue";
|
36
|
+
|
37
|
+
/// A wrapper for a [WorkflowClientTrait] or [crate::WorkflowService] implementor which performs
|
38
|
+
/// auto-retries
|
39
|
+
#[derive(Debug, Clone)]
|
40
|
+
pub struct RetryClient<SG> {
|
41
|
+
client: SG,
|
42
|
+
retry_config: Arc<RetryConfig>,
|
43
|
+
}
|
44
|
+
|
45
|
+
impl<SG> RetryClient<SG> {
|
46
|
+
/// Use the provided retry config with the provided client
|
47
|
+
pub fn new(client: SG, retry_config: RetryConfig) -> Self {
|
48
|
+
Self {
|
49
|
+
client,
|
50
|
+
retry_config: Arc::new(retry_config),
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
impl<SG> RetryClient<SG> {
|
56
|
+
/// Return the inner client type
|
57
|
+
pub fn get_client(&self) -> &SG {
|
58
|
+
&self.client
|
59
|
+
}
|
60
|
+
|
61
|
+
/// Return the inner client type mutably
|
62
|
+
pub fn get_client_mut(&mut self) -> &mut SG {
|
63
|
+
&mut self.client
|
64
|
+
}
|
65
|
+
|
66
|
+
/// Disable retry and return the inner client type
|
67
|
+
pub fn into_inner(self) -> SG {
|
68
|
+
self.client
|
69
|
+
}
|
70
|
+
|
71
|
+
/// Wraps a call to the underlying client with retry capability.
|
72
|
+
///
|
73
|
+
/// This is the "old" path used by higher-level [WorkflowClientTrait] implementors
|
74
|
+
pub(crate) async fn call_with_retry<R, F, Fut>(
|
75
|
+
&self,
|
76
|
+
factory: F,
|
77
|
+
call_name: &'static str,
|
78
|
+
) -> Result<R>
|
79
|
+
where
|
80
|
+
F: Fn() -> Fut + Unpin,
|
81
|
+
Fut: Future<Output = Result<R>>,
|
82
|
+
{
|
83
|
+
let rtc = self.get_retry_config(call_name);
|
84
|
+
let res = Self::make_future_retry(rtc, factory, call_name).await;
|
85
|
+
Ok(res.map_err(|(e, _attempt)| e)?.0)
|
86
|
+
}
|
87
|
+
|
88
|
+
pub(crate) fn get_retry_config(&self, call_name: &'static str) -> RetryConfig {
|
89
|
+
match CallType::from_call_name(call_name) {
|
90
|
+
CallType::Normal => (*self.retry_config).clone(),
|
91
|
+
CallType::LongPoll => RetryConfig::poll_retry_policy(),
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
pub(crate) fn make_future_retry<R, F, Fut>(
|
96
|
+
rtc: RetryConfig,
|
97
|
+
factory: F,
|
98
|
+
call_name: &'static str,
|
99
|
+
) -> FutureRetry<F, TonicErrorHandler<SystemClock>>
|
100
|
+
where
|
101
|
+
F: FnMut() -> Fut + Unpin,
|
102
|
+
Fut: Future<Output = Result<R>>,
|
103
|
+
{
|
104
|
+
FutureRetry::new(
|
105
|
+
factory,
|
106
|
+
TonicErrorHandler::new(rtc, RetryConfig::throttle_retry_policy(), call_name),
|
107
|
+
)
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
#[derive(Debug)]
|
112
|
+
pub(crate) struct TonicErrorHandler<C: Clock> {
|
113
|
+
backoff: ExponentialBackoff<C>,
|
114
|
+
throttle_backoff: ExponentialBackoff<C>,
|
115
|
+
max_retries: usize,
|
116
|
+
call_type: CallType,
|
117
|
+
call_name: &'static str,
|
118
|
+
}
|
119
|
+
impl TonicErrorHandler<SystemClock> {
|
120
|
+
fn new(cfg: RetryConfig, throttle_cfg: RetryConfig, call_name: &'static str) -> Self {
|
121
|
+
Self::new_with_clock(
|
122
|
+
cfg,
|
123
|
+
throttle_cfg,
|
124
|
+
call_name,
|
125
|
+
SystemClock::default(),
|
126
|
+
SystemClock::default(),
|
127
|
+
)
|
128
|
+
}
|
129
|
+
}
|
130
|
+
impl<C> TonicErrorHandler<C>
|
131
|
+
where
|
132
|
+
C: Clock,
|
133
|
+
{
|
134
|
+
fn new_with_clock(
|
135
|
+
cfg: RetryConfig,
|
136
|
+
throttle_cfg: RetryConfig,
|
137
|
+
call_name: &'static str,
|
138
|
+
clock: C,
|
139
|
+
throttle_clock: C,
|
140
|
+
) -> Self {
|
141
|
+
Self {
|
142
|
+
max_retries: cfg.max_retries,
|
143
|
+
call_type: CallType::from_call_name(call_name),
|
144
|
+
call_name,
|
145
|
+
backoff: cfg.into_exp_backoff(clock),
|
146
|
+
throttle_backoff: throttle_cfg.into_exp_backoff(throttle_clock),
|
147
|
+
}
|
148
|
+
}
|
149
|
+
const fn should_log_retry_warning(&self, cur_attempt: usize) -> bool {
|
150
|
+
// Warn on more than 5 retries for unlimited retrying
|
151
|
+
if self.max_retries == 0 && cur_attempt > 5 {
|
152
|
+
return true;
|
153
|
+
}
|
154
|
+
// Warn if the attempts are more than 50% of max retries
|
155
|
+
if self.max_retries > 0 && cur_attempt * 2 >= self.max_retries {
|
156
|
+
return true;
|
157
|
+
}
|
158
|
+
false
|
159
|
+
}
|
160
|
+
}
|
161
|
+
#[doc(hidden)]
|
162
|
+
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
163
|
+
pub enum CallType {
|
164
|
+
Normal,
|
165
|
+
LongPoll,
|
166
|
+
}
|
167
|
+
impl CallType {
|
168
|
+
fn from_call_name(call_name: &str) -> Self {
|
169
|
+
match call_name {
|
170
|
+
POLL_WORKFLOW_METH_NAME | POLL_ACTIVITY_METH_NAME => CallType::LongPoll,
|
171
|
+
_ => CallType::Normal,
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
impl<C> ErrorHandler<tonic::Status> for TonicErrorHandler<C>
|
177
|
+
where
|
178
|
+
C: Clock,
|
179
|
+
{
|
180
|
+
type OutError = tonic::Status;
|
181
|
+
|
182
|
+
fn handle(&mut self, current_attempt: usize, e: tonic::Status) -> RetryPolicy<tonic::Status> {
|
183
|
+
// 0 max retries means unlimited retries
|
184
|
+
if self.max_retries > 0 && current_attempt >= self.max_retries {
|
185
|
+
return RetryPolicy::ForwardError(e);
|
186
|
+
}
|
187
|
+
|
188
|
+
let is_long_poll = self.call_type == CallType::LongPoll;
|
189
|
+
// Long polls are OK with being cancelled or running into the timeout because there's
|
190
|
+
// nothing to do but retry anyway
|
191
|
+
let long_poll_allowed =
|
192
|
+
is_long_poll && [Code::Cancelled, Code::DeadlineExceeded].contains(&e.code());
|
193
|
+
|
194
|
+
if RETRYABLE_ERROR_CODES.contains(&e.code()) || long_poll_allowed {
|
195
|
+
if current_attempt == 1 {
|
196
|
+
debug!(error=?e, "gRPC call {} failed on first attempt", self.call_name);
|
197
|
+
} else if self.should_log_retry_warning(current_attempt) {
|
198
|
+
warn!(error=?e, "gRPC call {} retried {} times", self.call_name, current_attempt);
|
199
|
+
}
|
200
|
+
|
201
|
+
match self.backoff.next_backoff() {
|
202
|
+
None => RetryPolicy::ForwardError(e), // None is returned when we've ran out of time
|
203
|
+
Some(backoff) => {
|
204
|
+
// We treat ResourceExhausted as a special case and backoff more
|
205
|
+
// so we don't overload the server
|
206
|
+
if e.code() == Code::ResourceExhausted {
|
207
|
+
let extended_backoff =
|
208
|
+
backoff.max(self.throttle_backoff.next_backoff().unwrap_or_default());
|
209
|
+
RetryPolicy::WaitRetry(extended_backoff)
|
210
|
+
} else {
|
211
|
+
RetryPolicy::WaitRetry(backoff)
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}
|
215
|
+
} else if is_long_poll && self.backoff.get_elapsed_time() <= LONG_POLL_FATAL_GRACE {
|
216
|
+
// We permit "fatal" errors while long polling for a while, because some proxies return
|
217
|
+
// stupid error codes while getting ready, among other weird infra issues
|
218
|
+
RetryPolicy::WaitRetry(self.backoff.max_interval)
|
219
|
+
} else {
|
220
|
+
RetryPolicy::ForwardError(e)
|
221
|
+
}
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
macro_rules! retry_call {
|
226
|
+
($myself:ident, $call_name:ident) => { retry_call!($myself, $call_name,) };
|
227
|
+
($myself:ident, $call_name:ident, $($args:expr),*) => {{
|
228
|
+
let call_name_str = stringify!($call_name);
|
229
|
+
let fact = || { $myself.get_client().$call_name($($args,)*)};
|
230
|
+
$myself.call_with_retry(fact, call_name_str).await
|
231
|
+
}}
|
232
|
+
}
|
233
|
+
|
234
|
+
// Ideally, this would be auto-implemented for anything that implements the raw client, but that
|
235
|
+
// breaks all our retry clients which use a mock since it's based on this trait currently. Ideally
|
236
|
+
// we would create an automock for the WorkflowServiceClient copy-paste trait and use that, but
|
237
|
+
// that's a huge pain. Maybe one day tonic will provide traits.
|
238
|
+
#[async_trait::async_trait]
|
239
|
+
impl<SG> WorkflowClientTrait for RetryClient<SG>
|
240
|
+
where
|
241
|
+
SG: WorkflowClientTrait + Send + Sync + 'static,
|
242
|
+
{
|
243
|
+
async fn start_workflow(
|
244
|
+
&self,
|
245
|
+
input: Vec<Payload>,
|
246
|
+
task_queue: String,
|
247
|
+
workflow_id: String,
|
248
|
+
workflow_type: String,
|
249
|
+
request_id: Option<String>,
|
250
|
+
options: WorkflowOptions,
|
251
|
+
) -> Result<StartWorkflowExecutionResponse> {
|
252
|
+
retry_call!(
|
253
|
+
self,
|
254
|
+
start_workflow,
|
255
|
+
input.clone(),
|
256
|
+
task_queue.clone(),
|
257
|
+
workflow_id.clone(),
|
258
|
+
workflow_type.clone(),
|
259
|
+
request_id.clone(),
|
260
|
+
options.clone()
|
261
|
+
)
|
262
|
+
}
|
263
|
+
|
264
|
+
async fn reset_sticky_task_queue(
|
265
|
+
&self,
|
266
|
+
workflow_id: String,
|
267
|
+
run_id: String,
|
268
|
+
) -> Result<ResetStickyTaskQueueResponse> {
|
269
|
+
retry_call!(
|
270
|
+
self,
|
271
|
+
reset_sticky_task_queue,
|
272
|
+
workflow_id.clone(),
|
273
|
+
run_id.clone()
|
274
|
+
)
|
275
|
+
}
|
276
|
+
|
277
|
+
async fn complete_activity_task(
|
278
|
+
&self,
|
279
|
+
task_token: TaskToken,
|
280
|
+
result: Option<Payloads>,
|
281
|
+
) -> Result<RespondActivityTaskCompletedResponse> {
|
282
|
+
retry_call!(
|
283
|
+
self,
|
284
|
+
complete_activity_task,
|
285
|
+
task_token.clone(),
|
286
|
+
result.clone()
|
287
|
+
)
|
288
|
+
}
|
289
|
+
|
290
|
+
async fn record_activity_heartbeat(
|
291
|
+
&self,
|
292
|
+
task_token: TaskToken,
|
293
|
+
details: Option<Payloads>,
|
294
|
+
) -> Result<RecordActivityTaskHeartbeatResponse> {
|
295
|
+
retry_call!(
|
296
|
+
self,
|
297
|
+
record_activity_heartbeat,
|
298
|
+
task_token.clone(),
|
299
|
+
details.clone()
|
300
|
+
)
|
301
|
+
}
|
302
|
+
|
303
|
+
async fn cancel_activity_task(
|
304
|
+
&self,
|
305
|
+
task_token: TaskToken,
|
306
|
+
details: Option<Payloads>,
|
307
|
+
) -> Result<RespondActivityTaskCanceledResponse> {
|
308
|
+
retry_call!(
|
309
|
+
self,
|
310
|
+
cancel_activity_task,
|
311
|
+
task_token.clone(),
|
312
|
+
details.clone()
|
313
|
+
)
|
314
|
+
}
|
315
|
+
|
316
|
+
async fn fail_activity_task(
|
317
|
+
&self,
|
318
|
+
task_token: TaskToken,
|
319
|
+
failure: Option<Failure>,
|
320
|
+
) -> Result<RespondActivityTaskFailedResponse> {
|
321
|
+
retry_call!(
|
322
|
+
self,
|
323
|
+
fail_activity_task,
|
324
|
+
task_token.clone(),
|
325
|
+
failure.clone()
|
326
|
+
)
|
327
|
+
}
|
328
|
+
|
329
|
+
async fn fail_workflow_task(
|
330
|
+
&self,
|
331
|
+
task_token: TaskToken,
|
332
|
+
cause: WorkflowTaskFailedCause,
|
333
|
+
failure: Option<Failure>,
|
334
|
+
) -> Result<RespondWorkflowTaskFailedResponse> {
|
335
|
+
retry_call!(
|
336
|
+
self,
|
337
|
+
fail_workflow_task,
|
338
|
+
task_token.clone(),
|
339
|
+
cause,
|
340
|
+
failure.clone()
|
341
|
+
)
|
342
|
+
}
|
343
|
+
|
344
|
+
async fn signal_workflow_execution(
|
345
|
+
&self,
|
346
|
+
workflow_id: String,
|
347
|
+
run_id: String,
|
348
|
+
signal_name: String,
|
349
|
+
payloads: Option<Payloads>,
|
350
|
+
request_id: Option<String>,
|
351
|
+
) -> Result<SignalWorkflowExecutionResponse> {
|
352
|
+
retry_call!(
|
353
|
+
self,
|
354
|
+
signal_workflow_execution,
|
355
|
+
workflow_id.clone(),
|
356
|
+
run_id.clone(),
|
357
|
+
signal_name.clone(),
|
358
|
+
payloads.clone(),
|
359
|
+
request_id.clone()
|
360
|
+
)
|
361
|
+
}
|
362
|
+
|
363
|
+
async fn signal_with_start_workflow_execution(
|
364
|
+
&self,
|
365
|
+
input: Option<Payloads>,
|
366
|
+
task_queue: String,
|
367
|
+
workflow_id: String,
|
368
|
+
workflow_type: String,
|
369
|
+
request_id: Option<String>,
|
370
|
+
options: WorkflowOptions,
|
371
|
+
signal_name: String,
|
372
|
+
signal_input: Option<Payloads>,
|
373
|
+
signal_header: Option<Header>,
|
374
|
+
) -> Result<SignalWithStartWorkflowExecutionResponse> {
|
375
|
+
retry_call!(
|
376
|
+
self,
|
377
|
+
signal_with_start_workflow_execution,
|
378
|
+
input.clone(),
|
379
|
+
task_queue.clone(),
|
380
|
+
workflow_id.clone(),
|
381
|
+
workflow_type.clone(),
|
382
|
+
request_id.clone(),
|
383
|
+
options.clone(),
|
384
|
+
signal_name.clone(),
|
385
|
+
signal_input.clone(),
|
386
|
+
signal_header.clone()
|
387
|
+
)
|
388
|
+
}
|
389
|
+
|
390
|
+
async fn query_workflow_execution(
|
391
|
+
&self,
|
392
|
+
workflow_id: String,
|
393
|
+
run_id: String,
|
394
|
+
query: WorkflowQuery,
|
395
|
+
) -> Result<QueryWorkflowResponse> {
|
396
|
+
retry_call!(
|
397
|
+
self,
|
398
|
+
query_workflow_execution,
|
399
|
+
workflow_id.clone(),
|
400
|
+
run_id.clone(),
|
401
|
+
query.clone()
|
402
|
+
)
|
403
|
+
}
|
404
|
+
|
405
|
+
async fn describe_workflow_execution(
|
406
|
+
&self,
|
407
|
+
workflow_id: String,
|
408
|
+
run_id: Option<String>,
|
409
|
+
) -> Result<DescribeWorkflowExecutionResponse> {
|
410
|
+
retry_call!(
|
411
|
+
self,
|
412
|
+
describe_workflow_execution,
|
413
|
+
workflow_id.clone(),
|
414
|
+
run_id.clone()
|
415
|
+
)
|
416
|
+
}
|
417
|
+
|
418
|
+
async fn get_workflow_execution_history(
|
419
|
+
&self,
|
420
|
+
workflow_id: String,
|
421
|
+
run_id: Option<String>,
|
422
|
+
page_token: Vec<u8>,
|
423
|
+
) -> Result<GetWorkflowExecutionHistoryResponse> {
|
424
|
+
retry_call!(
|
425
|
+
self,
|
426
|
+
get_workflow_execution_history,
|
427
|
+
workflow_id.clone(),
|
428
|
+
run_id.clone(),
|
429
|
+
page_token.clone()
|
430
|
+
)
|
431
|
+
}
|
432
|
+
|
433
|
+
async fn respond_legacy_query(
|
434
|
+
&self,
|
435
|
+
task_token: TaskToken,
|
436
|
+
query_result: QueryResult,
|
437
|
+
) -> Result<RespondQueryTaskCompletedResponse> {
|
438
|
+
retry_call!(
|
439
|
+
self,
|
440
|
+
respond_legacy_query,
|
441
|
+
task_token.clone(),
|
442
|
+
query_result.clone()
|
443
|
+
)
|
444
|
+
}
|
445
|
+
|
446
|
+
async fn cancel_workflow_execution(
|
447
|
+
&self,
|
448
|
+
workflow_id: String,
|
449
|
+
run_id: Option<String>,
|
450
|
+
reason: String,
|
451
|
+
request_id: Option<String>,
|
452
|
+
) -> Result<RequestCancelWorkflowExecutionResponse> {
|
453
|
+
retry_call!(
|
454
|
+
self,
|
455
|
+
cancel_workflow_execution,
|
456
|
+
workflow_id.clone(),
|
457
|
+
run_id.clone(),
|
458
|
+
reason.clone(),
|
459
|
+
request_id.clone()
|
460
|
+
)
|
461
|
+
}
|
462
|
+
|
463
|
+
async fn terminate_workflow_execution(
|
464
|
+
&self,
|
465
|
+
workflow_id: String,
|
466
|
+
run_id: Option<String>,
|
467
|
+
) -> Result<TerminateWorkflowExecutionResponse> {
|
468
|
+
retry_call!(
|
469
|
+
self,
|
470
|
+
terminate_workflow_execution,
|
471
|
+
workflow_id.clone(),
|
472
|
+
run_id.clone()
|
473
|
+
)
|
474
|
+
}
|
475
|
+
|
476
|
+
async fn list_namespaces(&self) -> Result<ListNamespacesResponse> {
|
477
|
+
retry_call!(self, list_namespaces,)
|
478
|
+
}
|
479
|
+
|
480
|
+
async fn describe_namespace(&self, namespace: Namespace) -> Result<DescribeNamespaceResponse> {
|
481
|
+
retry_call!(self, describe_namespace, namespace.clone())
|
482
|
+
}
|
483
|
+
|
484
|
+
async fn list_open_workflow_executions(
|
485
|
+
&self,
|
486
|
+
maximum_page_size: i32,
|
487
|
+
next_page_token: Vec<u8>,
|
488
|
+
start_time_filter: Option<StartTimeFilter>,
|
489
|
+
filters: Option<ListOpenFilters>,
|
490
|
+
) -> Result<ListOpenWorkflowExecutionsResponse> {
|
491
|
+
retry_call!(
|
492
|
+
self,
|
493
|
+
list_open_workflow_executions,
|
494
|
+
maximum_page_size,
|
495
|
+
next_page_token.clone(),
|
496
|
+
start_time_filter.clone(),
|
497
|
+
filters.clone()
|
498
|
+
)
|
499
|
+
}
|
500
|
+
|
501
|
+
async fn list_closed_workflow_executions(
|
502
|
+
&self,
|
503
|
+
maximum_page_size: i32,
|
504
|
+
next_page_token: Vec<u8>,
|
505
|
+
start_time_filter: Option<StartTimeFilter>,
|
506
|
+
filters: Option<ListClosedFilters>,
|
507
|
+
) -> Result<ListClosedWorkflowExecutionsResponse> {
|
508
|
+
retry_call!(
|
509
|
+
self,
|
510
|
+
list_closed_workflow_executions,
|
511
|
+
maximum_page_size,
|
512
|
+
next_page_token.clone(),
|
513
|
+
start_time_filter.clone(),
|
514
|
+
filters.clone()
|
515
|
+
)
|
516
|
+
}
|
517
|
+
|
518
|
+
async fn list_workflow_executions(
|
519
|
+
&self,
|
520
|
+
page_size: i32,
|
521
|
+
next_page_token: Vec<u8>,
|
522
|
+
query: String,
|
523
|
+
) -> Result<ListWorkflowExecutionsResponse> {
|
524
|
+
retry_call!(
|
525
|
+
self,
|
526
|
+
list_workflow_executions,
|
527
|
+
page_size,
|
528
|
+
next_page_token.clone(),
|
529
|
+
query.clone()
|
530
|
+
)
|
531
|
+
}
|
532
|
+
|
533
|
+
fn get_options(&self) -> &ClientOptions {
|
534
|
+
self.client.get_options()
|
535
|
+
}
|
536
|
+
|
537
|
+
fn namespace(&self) -> &str {
|
538
|
+
self.client.namespace()
|
539
|
+
}
|
540
|
+
}
|
541
|
+
|
542
|
+
#[cfg(test)]
|
543
|
+
mod tests {
|
544
|
+
use super::*;
|
545
|
+
use crate::MockWorkflowClientTrait;
|
546
|
+
use assert_matches::assert_matches;
|
547
|
+
use backoff::Clock;
|
548
|
+
use std::{ops::Add, time::Instant};
|
549
|
+
use tonic::Status;
|
550
|
+
|
551
|
+
/// Predefined retry configs with low durations to make unit tests faster
|
552
|
+
const TEST_RETRY_CONFIG: RetryConfig = RetryConfig {
|
553
|
+
initial_interval: Duration::from_millis(1),
|
554
|
+
randomization_factor: 0.0,
|
555
|
+
multiplier: 1.1,
|
556
|
+
max_interval: Duration::from_millis(2),
|
557
|
+
max_elapsed_time: None,
|
558
|
+
max_retries: 10,
|
559
|
+
};
|
560
|
+
|
561
|
+
#[tokio::test]
|
562
|
+
async fn non_retryable_errors() {
|
563
|
+
for code in [
|
564
|
+
Code::InvalidArgument,
|
565
|
+
Code::NotFound,
|
566
|
+
Code::AlreadyExists,
|
567
|
+
Code::PermissionDenied,
|
568
|
+
Code::FailedPrecondition,
|
569
|
+
Code::Cancelled,
|
570
|
+
Code::DeadlineExceeded,
|
571
|
+
Code::Unauthenticated,
|
572
|
+
Code::Unimplemented,
|
573
|
+
] {
|
574
|
+
let mut mock_client = MockWorkflowClientTrait::new();
|
575
|
+
mock_client
|
576
|
+
.expect_cancel_activity_task()
|
577
|
+
.returning(move |_, _| Err(Status::new(code, "non-retryable failure")))
|
578
|
+
.times(1);
|
579
|
+
let retry_client = RetryClient::new(mock_client, TEST_RETRY_CONFIG);
|
580
|
+
let result = retry_client
|
581
|
+
.cancel_activity_task(vec![1].into(), None)
|
582
|
+
.await;
|
583
|
+
// Expecting an error after a single attempt, since there was a non-retryable error.
|
584
|
+
assert!(result.is_err());
|
585
|
+
}
|
586
|
+
}
|
587
|
+
|
588
|
+
struct FixedClock(Instant);
|
589
|
+
impl Clock for FixedClock {
|
590
|
+
fn now(&self) -> Instant {
|
591
|
+
self.0
|
592
|
+
}
|
593
|
+
}
|
594
|
+
|
595
|
+
#[tokio::test]
|
596
|
+
async fn long_poll_non_retryable_errors() {
|
597
|
+
for code in [
|
598
|
+
Code::InvalidArgument,
|
599
|
+
Code::NotFound,
|
600
|
+
Code::AlreadyExists,
|
601
|
+
Code::PermissionDenied,
|
602
|
+
Code::FailedPrecondition,
|
603
|
+
Code::Unauthenticated,
|
604
|
+
Code::Unimplemented,
|
605
|
+
] {
|
606
|
+
for call_name in [POLL_WORKFLOW_METH_NAME, POLL_ACTIVITY_METH_NAME] {
|
607
|
+
let mut err_handler = TonicErrorHandler {
|
608
|
+
max_retries: TEST_RETRY_CONFIG.max_retries,
|
609
|
+
call_type: CallType::LongPoll,
|
610
|
+
call_name,
|
611
|
+
backoff: TEST_RETRY_CONFIG.into_exp_backoff(FixedClock(Instant::now())),
|
612
|
+
throttle_backoff: TEST_RETRY_CONFIG
|
613
|
+
.into_exp_backoff(FixedClock(Instant::now())),
|
614
|
+
};
|
615
|
+
let result = err_handler.handle(1, Status::new(code, "Ahh"));
|
616
|
+
assert_matches!(result, RetryPolicy::WaitRetry(_));
|
617
|
+
err_handler.backoff.clock.0 = err_handler
|
618
|
+
.backoff
|
619
|
+
.clock
|
620
|
+
.0
|
621
|
+
.add(LONG_POLL_FATAL_GRACE + Duration::from_secs(1));
|
622
|
+
let result = err_handler.handle(2, Status::new(code, "Ahh"));
|
623
|
+
assert_matches!(result, RetryPolicy::ForwardError(_));
|
624
|
+
}
|
625
|
+
}
|
626
|
+
}
|
627
|
+
|
628
|
+
#[tokio::test]
|
629
|
+
async fn long_poll_retryable_errors_never_fatal() {
|
630
|
+
for code in RETRYABLE_ERROR_CODES {
|
631
|
+
for call_name in [POLL_WORKFLOW_METH_NAME, POLL_ACTIVITY_METH_NAME] {
|
632
|
+
let mut err_handler = TonicErrorHandler {
|
633
|
+
max_retries: TEST_RETRY_CONFIG.max_retries,
|
634
|
+
call_type: CallType::LongPoll,
|
635
|
+
call_name,
|
636
|
+
backoff: TEST_RETRY_CONFIG.into_exp_backoff(FixedClock(Instant::now())),
|
637
|
+
throttle_backoff: TEST_RETRY_CONFIG
|
638
|
+
.into_exp_backoff(FixedClock(Instant::now())),
|
639
|
+
};
|
640
|
+
let result = err_handler.handle(1, Status::new(code, "Ahh"));
|
641
|
+
assert_matches!(result, RetryPolicy::WaitRetry(_));
|
642
|
+
err_handler.backoff.clock.0 = err_handler
|
643
|
+
.backoff
|
644
|
+
.clock
|
645
|
+
.0
|
646
|
+
.add(LONG_POLL_FATAL_GRACE + Duration::from_secs(1));
|
647
|
+
let result = err_handler.handle(2, Status::new(code, "Ahh"));
|
648
|
+
assert_matches!(result, RetryPolicy::WaitRetry(_));
|
649
|
+
}
|
650
|
+
}
|
651
|
+
}
|
652
|
+
|
653
|
+
#[tokio::test]
|
654
|
+
async fn retryable_errors() {
|
655
|
+
// Take out retry exhausted since it gets a special policy which would make this take ages
|
656
|
+
for code in RETRYABLE_ERROR_CODES
|
657
|
+
.iter()
|
658
|
+
.copied()
|
659
|
+
.filter(|p| p != &Code::ResourceExhausted)
|
660
|
+
{
|
661
|
+
let mut mock_client = MockWorkflowClientTrait::new();
|
662
|
+
mock_client
|
663
|
+
.expect_cancel_activity_task()
|
664
|
+
.returning(move |_, _| Err(Status::new(code, "retryable failure")))
|
665
|
+
.times(3);
|
666
|
+
mock_client
|
667
|
+
.expect_cancel_activity_task()
|
668
|
+
.returning(|_, _| Ok(Default::default()))
|
669
|
+
.times(1);
|
670
|
+
|
671
|
+
let retry_client = RetryClient::new(mock_client, TEST_RETRY_CONFIG);
|
672
|
+
let result = retry_client
|
673
|
+
.cancel_activity_task(vec![1].into(), None)
|
674
|
+
.await;
|
675
|
+
// Expecting successful response after retries
|
676
|
+
assert!(result.is_ok());
|
677
|
+
}
|
678
|
+
}
|
679
|
+
|
680
|
+
#[tokio::test]
|
681
|
+
async fn retry_resource_exhausted() {
|
682
|
+
let mut err_handler = TonicErrorHandler {
|
683
|
+
max_retries: TEST_RETRY_CONFIG.max_retries,
|
684
|
+
call_type: CallType::Normal,
|
685
|
+
call_name: POLL_WORKFLOW_METH_NAME,
|
686
|
+
backoff: TEST_RETRY_CONFIG.into_exp_backoff(FixedClock(Instant::now())),
|
687
|
+
throttle_backoff: RetryConfig {
|
688
|
+
initial_interval: Duration::from_millis(2),
|
689
|
+
randomization_factor: 0.0,
|
690
|
+
multiplier: 4.0,
|
691
|
+
max_interval: Duration::from_millis(10),
|
692
|
+
max_elapsed_time: None,
|
693
|
+
max_retries: 10,
|
694
|
+
}
|
695
|
+
.into_exp_backoff(FixedClock(Instant::now())),
|
696
|
+
};
|
697
|
+
let result = err_handler.handle(1, Status::new(Code::ResourceExhausted, "leave me alone"));
|
698
|
+
match result {
|
699
|
+
RetryPolicy::WaitRetry(duration) => assert_eq!(duration, Duration::from_millis(2)),
|
700
|
+
_ => panic!(),
|
701
|
+
}
|
702
|
+
err_handler.backoff.clock.0 = err_handler.backoff.clock.0.add(Duration::from_millis(10));
|
703
|
+
err_handler.throttle_backoff.clock.0 = err_handler
|
704
|
+
.throttle_backoff
|
705
|
+
.clock
|
706
|
+
.0
|
707
|
+
.add(Duration::from_millis(10));
|
708
|
+
let result = err_handler.handle(2, Status::new(Code::ResourceExhausted, "leave me alone"));
|
709
|
+
match result {
|
710
|
+
RetryPolicy::WaitRetry(duration) => assert_eq!(duration, Duration::from_millis(8)),
|
711
|
+
_ => panic!(),
|
712
|
+
}
|
713
|
+
}
|
714
|
+
|
715
|
+
#[tokio::test]
|
716
|
+
async fn long_poll_retries_forever() {
|
717
|
+
// A bit odd, but we don't need a real client to test the retry client passes through the
|
718
|
+
// correct retry config
|
719
|
+
let fake_retry = RetryClient::new((), TEST_RETRY_CONFIG);
|
720
|
+
for i in 1..=50 {
|
721
|
+
for call in [POLL_WORKFLOW_METH_NAME, POLL_ACTIVITY_METH_NAME] {
|
722
|
+
let mut err_handler = TonicErrorHandler::new(
|
723
|
+
fake_retry.get_retry_config(call),
|
724
|
+
fake_retry.get_retry_config(call),
|
725
|
+
call,
|
726
|
+
);
|
727
|
+
let result = err_handler.handle(i, Status::new(Code::Unknown, "Ahh"));
|
728
|
+
assert_matches!(result, RetryPolicy::WaitRetry(_));
|
729
|
+
}
|
730
|
+
}
|
731
|
+
}
|
732
|
+
|
733
|
+
#[tokio::test]
|
734
|
+
async fn long_poll_retries_deadline_exceeded() {
|
735
|
+
let fake_retry = RetryClient::new((), TEST_RETRY_CONFIG);
|
736
|
+
// For some reason we will get cancelled in these situations occasionally (always?) too
|
737
|
+
for code in [Code::Cancelled, Code::DeadlineExceeded] {
|
738
|
+
for call in [POLL_WORKFLOW_METH_NAME, POLL_ACTIVITY_METH_NAME] {
|
739
|
+
let mut err_handler = TonicErrorHandler::new(
|
740
|
+
fake_retry.get_retry_config(call),
|
741
|
+
fake_retry.get_retry_config(call),
|
742
|
+
call,
|
743
|
+
);
|
744
|
+
for i in 1..=5 {
|
745
|
+
let result = err_handler.handle(i, Status::new(code, "retryable failure"));
|
746
|
+
assert_matches!(result, RetryPolicy::WaitRetry(_));
|
747
|
+
}
|
748
|
+
}
|
749
|
+
}
|
750
|
+
}
|
751
|
+
}
|