temporalio 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +130 -0
- data/bridge/Cargo.lock +2865 -0
- data/bridge/Cargo.toml +26 -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 +107 -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/bridge-ffi/Cargo.toml +24 -0
- data/bridge/sdk-core/bridge-ffi/LICENSE.txt +23 -0
- data/bridge/sdk-core/bridge-ffi/build.rs +25 -0
- data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +249 -0
- data/bridge/sdk-core/bridge-ffi/src/lib.rs +825 -0
- data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +211 -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 +1294 -0
- data/bridge/sdk-core/client/src/metrics.rs +165 -0
- data/bridge/sdk-core/client/src/raw.rs +931 -0
- data/bridge/sdk-core/client/src/retry.rs +674 -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 +73 -0
- data/bridge/sdk-core/core/src/abstractions.rs +166 -0
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +911 -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 +515 -0
- data/bridge/sdk-core/core/src/core_tests/mod.rs +100 -0
- data/bridge/sdk-core/core/src/core_tests/queries.rs +736 -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 +2070 -0
- data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +515 -0
- data/bridge/sdk-core/core/src/lib.rs +175 -0
- data/bridge/sdk-core/core/src/log_export.rs +62 -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 +71 -0
- data/bridge/sdk-core/core/src/retry_logic.rs +202 -0
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +383 -0
- data/bridge/sdk-core/core/src/telemetry/mod.rs +412 -0
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +77 -0
- data/bridge/sdk-core/core/src/test_help/mod.rs +875 -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 +1042 -0
- data/bridge/sdk-core/core/src/worker/activities.rs +464 -0
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +87 -0
- data/bridge/sdk-core/core/src/worker/client.rs +347 -0
- data/bridge/sdk-core/core/src/worker/mod.rs +566 -0
- data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +37 -0
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +110 -0
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +458 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +911 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +298 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +171 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +860 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +140 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +161 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +133 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +1448 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +342 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +127 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +712 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +71 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +443 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +439 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +169 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +246 -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 +1184 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +277 -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 +647 -0
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +1143 -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 +940 -0
- data/bridge/sdk-core/core-api/Cargo.toml +31 -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 +151 -0
- data/bridge/sdk-core/core-api/src/worker.rs +135 -0
- data/bridge/sdk-core/etc/deps.svg +187 -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/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/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 +12 -0
- data/bridge/sdk-core/protos/api_upstream/dependencies/gogoproto/gogo.proto +141 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +86 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +83 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +259 -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 +46 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/cluster.proto +40 -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 +55 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +168 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +97 -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 +51 -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 +751 -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 +161 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +99 -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 +300 -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/update/v1/message.proto +46 -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 +145 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +1124 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +401 -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/bridge/bridge.proto +210 -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 +261 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +297 -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/conversions.rs +8 -0
- data/bridge/sdk-core/sdk/src/interceptors.rs +17 -0
- data/bridge/sdk-core/sdk/src/lib.rs +792 -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 +683 -0
- data/bridge/sdk-core/sdk/src/workflow_future.rs +503 -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 +108 -0
- data/bridge/sdk-core/sdk-core-protos/src/constants.rs +7 -0
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +497 -0
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +230 -0
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +1910 -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 +35 -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 +598 -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 +218 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +146 -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 +634 -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 +137 -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 +587 -0
- data/bridge/sdk-core/tests/load_tests.rs +191 -0
- data/bridge/sdk-core/tests/main.rs +111 -0
- data/bridge/sdk-core/tests/runner.rs +93 -0
- data/bridge/src/connection.rs +167 -0
- data/bridge/src/lib.rs +180 -0
- data/bridge/src/runtime.rs +47 -0
- data/bridge/src/worker.rs +73 -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 +48 -0
- data/lib/gen/temporal/api/cluster/v1/message_pb.rb +67 -0
- data/lib/gen/temporal/api/command/v1/message_pb.rb +166 -0
- data/lib/gen/temporal/api/common/v1/message_pb.rb +69 -0
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +32 -0
- data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +26 -0
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +37 -0
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +41 -0
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +67 -0
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +71 -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 +28 -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 +489 -0
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +63 -0
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +125 -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 +128 -0
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +73 -0
- data/lib/gen/temporal/api/update/v1/message_pb.rb +26 -0
- data/lib/gen/temporal/api/version/v1/message_pb.rb +41 -0
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +110 -0
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +771 -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 +164 -0
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +192 -0
- data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +34 -0
- data/lib/temporal/bridge.rb +14 -0
- data/lib/temporal/client/implementation.rb +339 -0
- data/lib/temporal/client/workflow_handle.rb +243 -0
- data/lib/temporal/client.rb +144 -0
- data/lib/temporal/connection.rb +736 -0
- data/lib/temporal/data_converter.rb +150 -0
- data/lib/temporal/error/failure.rb +194 -0
- data/lib/temporal/error/workflow_failure.rb +17 -0
- data/lib/temporal/errors.rb +22 -0
- data/lib/temporal/failure_converter/base.rb +26 -0
- data/lib/temporal/failure_converter/basic.rb +313 -0
- data/lib/temporal/failure_converter.rb +8 -0
- data/lib/temporal/interceptor/chain.rb +27 -0
- data/lib/temporal/interceptor/client.rb +102 -0
- data/lib/temporal/payload_codec/base.rb +32 -0
- data/lib/temporal/payload_converter/base.rb +24 -0
- data/lib/temporal/payload_converter/bytes.rb +26 -0
- data/lib/temporal/payload_converter/composite.rb +47 -0
- data/lib/temporal/payload_converter/encoding_base.rb +35 -0
- data/lib/temporal/payload_converter/json.rb +25 -0
- data/lib/temporal/payload_converter/nil.rb +25 -0
- data/lib/temporal/payload_converter.rb +14 -0
- data/lib/temporal/retry_policy.rb +82 -0
- data/lib/temporal/retry_state.rb +35 -0
- data/lib/temporal/runtime.rb +22 -0
- data/lib/temporal/timeout_type.rb +29 -0
- data/lib/temporal/version.rb +3 -0
- data/lib/temporal/workflow/execution_info.rb +54 -0
- data/lib/temporal/workflow/execution_status.rb +36 -0
- data/lib/temporal/workflow/id_reuse_policy.rb +36 -0
- data/lib/temporal/workflow/query_reject_condition.rb +33 -0
- data/lib/temporal.rb +8 -0
- data/lib/temporalio.rb +3 -0
- data/lib/thermite_patch.rb +23 -0
- data/temporalio.gemspec +41 -0
- metadata +583 -0
@@ -0,0 +1,860 @@
|
|
1
|
+
use super::{
|
2
|
+
workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
|
3
|
+
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
4
|
+
};
|
5
|
+
use rustfsm::{fsm, MachineError, TransitionResult};
|
6
|
+
use std::convert::{TryFrom, TryInto};
|
7
|
+
use temporal_sdk_core_protos::{
|
8
|
+
coresdk::{
|
9
|
+
child_workflow::{
|
10
|
+
self as wfr, child_workflow_result::Status as ChildWorkflowStatus,
|
11
|
+
ChildWorkflowCancellationType, ChildWorkflowResult,
|
12
|
+
},
|
13
|
+
workflow_activation::{
|
14
|
+
resolve_child_workflow_execution_start, ResolveChildWorkflowExecution,
|
15
|
+
ResolveChildWorkflowExecutionStart, ResolveChildWorkflowExecutionStartCancelled,
|
16
|
+
ResolveChildWorkflowExecutionStartFailure, ResolveChildWorkflowExecutionStartSuccess,
|
17
|
+
},
|
18
|
+
workflow_commands::StartChildWorkflowExecution,
|
19
|
+
},
|
20
|
+
temporal::api::{
|
21
|
+
command::v1::{Command, RequestCancelExternalWorkflowExecutionCommandAttributes},
|
22
|
+
common::v1::{Payload, Payloads, WorkflowExecution, WorkflowType},
|
23
|
+
enums::v1::{
|
24
|
+
CommandType, EventType, RetryState, StartChildWorkflowExecutionFailedCause, TimeoutType,
|
25
|
+
},
|
26
|
+
failure::v1::{self as failure, failure::FailureInfo, Failure},
|
27
|
+
history::v1::{
|
28
|
+
history_event, ChildWorkflowExecutionCompletedEventAttributes,
|
29
|
+
ChildWorkflowExecutionFailedEventAttributes,
|
30
|
+
ChildWorkflowExecutionStartedEventAttributes, HistoryEvent,
|
31
|
+
StartChildWorkflowExecutionFailedEventAttributes,
|
32
|
+
},
|
33
|
+
},
|
34
|
+
};
|
35
|
+
|
36
|
+
fsm! {
|
37
|
+
pub(super) name ChildWorkflowMachine;
|
38
|
+
command ChildWorkflowCommand;
|
39
|
+
error WFMachinesError;
|
40
|
+
shared_state SharedState;
|
41
|
+
|
42
|
+
Created --(Schedule, on_schedule) --> StartCommandCreated;
|
43
|
+
StartCommandCreated --(CommandStartChildWorkflowExecution) --> StartCommandCreated;
|
44
|
+
StartCommandCreated --(StartChildWorkflowExecutionInitiated(i64),
|
45
|
+
shared on_start_child_workflow_execution_initiated) --> StartEventRecorded;
|
46
|
+
StartCommandCreated --(Cancel, shared on_cancelled) --> Cancelled;
|
47
|
+
|
48
|
+
StartEventRecorded --(ChildWorkflowExecutionStarted(ChildWorkflowExecutionStartedEvent),
|
49
|
+
shared on_child_workflow_execution_started) --> Started;
|
50
|
+
StartEventRecorded --(StartChildWorkflowExecutionFailed(StartChildWorkflowExecutionFailedCause),
|
51
|
+
on_start_child_workflow_execution_failed) --> StartFailed;
|
52
|
+
|
53
|
+
Started --(ChildWorkflowExecutionCompleted(Option<Payloads>),
|
54
|
+
on_child_workflow_execution_completed) --> Completed;
|
55
|
+
Started --(ChildWorkflowExecutionFailed(ChildWorkflowExecutionFailedEventAttributes),
|
56
|
+
shared on_child_workflow_execution_failed) --> Failed;
|
57
|
+
Started --(ChildWorkflowExecutionTimedOut(RetryState),
|
58
|
+
shared on_child_workflow_execution_timed_out) --> TimedOut;
|
59
|
+
Started --(ChildWorkflowExecutionCancelled,
|
60
|
+
on_child_workflow_execution_cancelled) --> Cancelled;
|
61
|
+
Started --(ChildWorkflowExecutionTerminated,
|
62
|
+
shared on_child_workflow_execution_terminated) --> Terminated;
|
63
|
+
// If cancelled after started, we need to issue a cancel external workflow command, and then
|
64
|
+
// the child workflow will resolve somehow, so we want to go back to started and wait for that
|
65
|
+
// resolution.
|
66
|
+
Started --(Cancel, shared on_cancelled) --> Started;
|
67
|
+
// Abandon & try cancel modes may immediately move to cancelled
|
68
|
+
Started --(Cancel, shared on_cancelled) --> Cancelled;
|
69
|
+
Started --(CommandRequestCancelExternalWorkflowExecution) --> Started;
|
70
|
+
|
71
|
+
// Ignore any spurious cancellations after resolution
|
72
|
+
Cancelled --(Cancel) --> Cancelled;
|
73
|
+
Failed --(Cancel) --> Failed;
|
74
|
+
TimedOut --(Cancel) --> TimedOut;
|
75
|
+
Completed --(Cancel) --> Completed;
|
76
|
+
}
|
77
|
+
|
78
|
+
pub struct ChildWorkflowExecutionStartedEvent {
|
79
|
+
workflow_execution: WorkflowExecution,
|
80
|
+
started_event_id: i64,
|
81
|
+
}
|
82
|
+
|
83
|
+
#[derive(Debug, derive_more::Display)]
|
84
|
+
pub(super) enum ChildWorkflowCommand {
|
85
|
+
#[display(fmt = "Start")]
|
86
|
+
Start(WorkflowExecution),
|
87
|
+
#[display(fmt = "Complete")]
|
88
|
+
Complete(Option<Payloads>),
|
89
|
+
#[display(fmt = "Fail")]
|
90
|
+
Fail(Failure),
|
91
|
+
#[display(fmt = "Cancel")]
|
92
|
+
Cancel,
|
93
|
+
#[display(fmt = "StartFail")]
|
94
|
+
StartFail(StartChildWorkflowExecutionFailedCause),
|
95
|
+
#[display(fmt = "StartCancel")]
|
96
|
+
StartCancel(Failure),
|
97
|
+
#[display(fmt = "CancelAfterStarted")]
|
98
|
+
IssueCancelAfterStarted { reason: String },
|
99
|
+
}
|
100
|
+
|
101
|
+
#[derive(Default, Clone)]
|
102
|
+
pub(super) struct Cancelled {}
|
103
|
+
|
104
|
+
#[derive(Default, Clone)]
|
105
|
+
pub(super) struct Completed {}
|
106
|
+
|
107
|
+
#[derive(Default, Clone)]
|
108
|
+
pub(super) struct Created {}
|
109
|
+
|
110
|
+
impl Created {
|
111
|
+
pub(super) fn on_schedule(self) -> ChildWorkflowMachineTransition<StartCommandCreated> {
|
112
|
+
TransitionResult::default()
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
#[derive(Default, Clone)]
|
117
|
+
pub(super) struct Failed {}
|
118
|
+
|
119
|
+
#[derive(Default, Clone)]
|
120
|
+
pub(super) struct StartCommandCreated {}
|
121
|
+
|
122
|
+
impl StartCommandCreated {
|
123
|
+
pub(super) fn on_start_child_workflow_execution_initiated(
|
124
|
+
self,
|
125
|
+
state: SharedState,
|
126
|
+
initiated_event_id: i64,
|
127
|
+
) -> ChildWorkflowMachineTransition<StartEventRecorded> {
|
128
|
+
ChildWorkflowMachineTransition::ok_shared(
|
129
|
+
vec![],
|
130
|
+
StartEventRecorded::default(),
|
131
|
+
SharedState {
|
132
|
+
initiated_event_id,
|
133
|
+
..state
|
134
|
+
},
|
135
|
+
)
|
136
|
+
}
|
137
|
+
|
138
|
+
pub(super) fn on_cancelled(
|
139
|
+
self,
|
140
|
+
state: SharedState,
|
141
|
+
) -> ChildWorkflowMachineTransition<Cancelled> {
|
142
|
+
let state = SharedState {
|
143
|
+
cancelled_before_sent: true,
|
144
|
+
..state
|
145
|
+
};
|
146
|
+
ChildWorkflowMachineTransition::ok_shared(
|
147
|
+
vec![ChildWorkflowCommand::StartCancel(Failure {
|
148
|
+
message: "Child Workflow execution cancelled before scheduled".to_owned(),
|
149
|
+
cause: Some(Box::new(Failure {
|
150
|
+
failure_info: Some(FailureInfo::CanceledFailureInfo(
|
151
|
+
failure::CanceledFailureInfo {
|
152
|
+
..Default::default()
|
153
|
+
},
|
154
|
+
)),
|
155
|
+
..Default::default()
|
156
|
+
})),
|
157
|
+
failure_info: failure_info_from_state(&state, RetryState::NonRetryableFailure),
|
158
|
+
..Default::default()
|
159
|
+
})],
|
160
|
+
Cancelled::default(),
|
161
|
+
state,
|
162
|
+
)
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
#[derive(Default, Clone)]
|
167
|
+
pub(super) struct StartEventRecorded {}
|
168
|
+
|
169
|
+
impl StartEventRecorded {
|
170
|
+
pub(super) fn on_child_workflow_execution_started(
|
171
|
+
self,
|
172
|
+
state: SharedState,
|
173
|
+
event: ChildWorkflowExecutionStartedEvent,
|
174
|
+
) -> ChildWorkflowMachineTransition<Started> {
|
175
|
+
ChildWorkflowMachineTransition::ok_shared(
|
176
|
+
vec![ChildWorkflowCommand::Start(
|
177
|
+
event.workflow_execution.clone(),
|
178
|
+
)],
|
179
|
+
Started::default(),
|
180
|
+
SharedState {
|
181
|
+
started_event_id: event.started_event_id,
|
182
|
+
run_id: event.workflow_execution.run_id,
|
183
|
+
..state
|
184
|
+
},
|
185
|
+
)
|
186
|
+
}
|
187
|
+
pub(super) fn on_start_child_workflow_execution_failed(
|
188
|
+
self,
|
189
|
+
cause: StartChildWorkflowExecutionFailedCause,
|
190
|
+
) -> ChildWorkflowMachineTransition<StartFailed> {
|
191
|
+
ChildWorkflowMachineTransition::ok(
|
192
|
+
vec![ChildWorkflowCommand::StartFail(cause)],
|
193
|
+
StartFailed::default(),
|
194
|
+
)
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
#[derive(Default, Clone)]
|
199
|
+
pub(super) struct StartFailed {}
|
200
|
+
|
201
|
+
#[derive(Default, Clone)]
|
202
|
+
pub(super) struct Started {}
|
203
|
+
|
204
|
+
impl Started {
|
205
|
+
fn on_child_workflow_execution_completed(
|
206
|
+
self,
|
207
|
+
result: Option<Payloads>,
|
208
|
+
) -> ChildWorkflowMachineTransition<Completed> {
|
209
|
+
ChildWorkflowMachineTransition::ok(
|
210
|
+
vec![ChildWorkflowCommand::Complete(result)],
|
211
|
+
Completed::default(),
|
212
|
+
)
|
213
|
+
}
|
214
|
+
fn on_child_workflow_execution_failed(
|
215
|
+
self,
|
216
|
+
state: SharedState,
|
217
|
+
attrs: ChildWorkflowExecutionFailedEventAttributes,
|
218
|
+
) -> ChildWorkflowMachineTransition<Failed> {
|
219
|
+
ChildWorkflowMachineTransition::ok(
|
220
|
+
vec![ChildWorkflowCommand::Fail(Failure {
|
221
|
+
message: "Child Workflow execution failed".to_owned(),
|
222
|
+
failure_info: failure_info_from_state(&state, attrs.retry_state()),
|
223
|
+
cause: attrs.failure.map(Box::new),
|
224
|
+
..Default::default()
|
225
|
+
})],
|
226
|
+
Failed::default(),
|
227
|
+
)
|
228
|
+
}
|
229
|
+
fn on_child_workflow_execution_timed_out(
|
230
|
+
self,
|
231
|
+
state: SharedState,
|
232
|
+
retry_state: RetryState,
|
233
|
+
) -> ChildWorkflowMachineTransition<TimedOut> {
|
234
|
+
ChildWorkflowMachineTransition::ok(
|
235
|
+
vec![ChildWorkflowCommand::Fail(Failure {
|
236
|
+
message: "Child Workflow execution timed out".to_owned(),
|
237
|
+
cause: Some(Box::new(Failure {
|
238
|
+
message: "Timed out".to_owned(),
|
239
|
+
failure_info: Some(FailureInfo::TimeoutFailureInfo(
|
240
|
+
failure::TimeoutFailureInfo {
|
241
|
+
last_heartbeat_details: None,
|
242
|
+
timeout_type: TimeoutType::StartToClose as i32,
|
243
|
+
},
|
244
|
+
)),
|
245
|
+
..Default::default()
|
246
|
+
})),
|
247
|
+
failure_info: failure_info_from_state(&state, retry_state),
|
248
|
+
..Default::default()
|
249
|
+
})],
|
250
|
+
TimedOut::default(),
|
251
|
+
)
|
252
|
+
}
|
253
|
+
fn on_child_workflow_execution_cancelled(self) -> ChildWorkflowMachineTransition<Cancelled> {
|
254
|
+
ChildWorkflowMachineTransition::ok(vec![ChildWorkflowCommand::Cancel], Cancelled::default())
|
255
|
+
}
|
256
|
+
fn on_child_workflow_execution_terminated(
|
257
|
+
self,
|
258
|
+
state: SharedState,
|
259
|
+
) -> ChildWorkflowMachineTransition<Terminated> {
|
260
|
+
ChildWorkflowMachineTransition::ok(
|
261
|
+
vec![ChildWorkflowCommand::Fail(Failure {
|
262
|
+
message: "Child Workflow execution terminated".to_owned(),
|
263
|
+
cause: Some(Box::new(Failure {
|
264
|
+
message: "Terminated".to_owned(),
|
265
|
+
failure_info: Some(FailureInfo::TerminatedFailureInfo(
|
266
|
+
failure::TerminatedFailureInfo {},
|
267
|
+
)),
|
268
|
+
..Default::default()
|
269
|
+
})),
|
270
|
+
failure_info: failure_info_from_state(&state, RetryState::NonRetryableFailure),
|
271
|
+
..Default::default()
|
272
|
+
})],
|
273
|
+
Terminated::default(),
|
274
|
+
)
|
275
|
+
}
|
276
|
+
fn on_cancelled(
|
277
|
+
self,
|
278
|
+
state: SharedState,
|
279
|
+
) -> ChildWorkflowMachineTransition<StartedOrCancelled> {
|
280
|
+
let dest = match state.cancel_type {
|
281
|
+
ChildWorkflowCancellationType::Abandon | ChildWorkflowCancellationType::TryCancel => {
|
282
|
+
StartedOrCancelled::Cancelled(Default::default())
|
283
|
+
}
|
284
|
+
_ => StartedOrCancelled::Started(Default::default()),
|
285
|
+
};
|
286
|
+
TransitionResult::ok(
|
287
|
+
[ChildWorkflowCommand::IssueCancelAfterStarted {
|
288
|
+
reason: "Parent workflow requested cancel".to_string(),
|
289
|
+
}],
|
290
|
+
dest,
|
291
|
+
)
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
#[derive(Default, Clone)]
|
296
|
+
pub(super) struct Terminated {}
|
297
|
+
|
298
|
+
#[derive(Default, Clone)]
|
299
|
+
pub(super) struct TimedOut {}
|
300
|
+
|
301
|
+
#[derive(Default, Clone, Debug)]
|
302
|
+
pub(super) struct SharedState {
|
303
|
+
initiated_event_id: i64,
|
304
|
+
started_event_id: i64,
|
305
|
+
lang_sequence_number: u32,
|
306
|
+
namespace: String,
|
307
|
+
workflow_id: String,
|
308
|
+
run_id: String,
|
309
|
+
workflow_type: String,
|
310
|
+
cancelled_before_sent: bool,
|
311
|
+
cancel_type: ChildWorkflowCancellationType,
|
312
|
+
}
|
313
|
+
|
314
|
+
/// Creates a new child workflow state machine and a command to start it on the server.
|
315
|
+
pub(super) fn new_child_workflow(attribs: StartChildWorkflowExecution) -> NewMachineWithCommand {
|
316
|
+
let (wf, add_cmd) = ChildWorkflowMachine::new_scheduled(attribs);
|
317
|
+
NewMachineWithCommand {
|
318
|
+
command: add_cmd,
|
319
|
+
machine: wf.into(),
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
impl ChildWorkflowMachine {
|
324
|
+
/// Create a new child workflow and immediately schedule it.
|
325
|
+
pub(crate) fn new_scheduled(attribs: StartChildWorkflowExecution) -> (Self, Command) {
|
326
|
+
let mut s = Self {
|
327
|
+
state: Created {}.into(),
|
328
|
+
shared_state: SharedState {
|
329
|
+
lang_sequence_number: attribs.seq,
|
330
|
+
workflow_id: attribs.workflow_id.clone(),
|
331
|
+
workflow_type: attribs.workflow_type.clone(),
|
332
|
+
namespace: attribs.namespace.clone(),
|
333
|
+
cancel_type: attribs.cancellation_type(),
|
334
|
+
..Default::default()
|
335
|
+
},
|
336
|
+
};
|
337
|
+
OnEventWrapper::on_event_mut(&mut s, ChildWorkflowMachineEvents::Schedule)
|
338
|
+
.expect("Scheduling child workflows doesn't fail");
|
339
|
+
let cmd = Command {
|
340
|
+
command_type: CommandType::StartChildWorkflowExecution as i32,
|
341
|
+
attributes: Some(attribs.into()),
|
342
|
+
};
|
343
|
+
(s, cmd)
|
344
|
+
}
|
345
|
+
|
346
|
+
fn resolve_cancelled_msg(&self) -> ResolveChildWorkflowExecution {
|
347
|
+
let failure = Failure {
|
348
|
+
message: "Child Workflow execution cancelled".to_owned(),
|
349
|
+
cause: Some(Box::new(Failure {
|
350
|
+
failure_info: Some(FailureInfo::CanceledFailureInfo(
|
351
|
+
failure::CanceledFailureInfo {
|
352
|
+
..Default::default()
|
353
|
+
},
|
354
|
+
)),
|
355
|
+
..Default::default()
|
356
|
+
})),
|
357
|
+
failure_info: failure_info_from_state(
|
358
|
+
&self.shared_state,
|
359
|
+
RetryState::NonRetryableFailure,
|
360
|
+
),
|
361
|
+
..Default::default()
|
362
|
+
};
|
363
|
+
ResolveChildWorkflowExecution {
|
364
|
+
seq: self.shared_state.lang_sequence_number,
|
365
|
+
result: Some(ChildWorkflowResult {
|
366
|
+
status: Some(ChildWorkflowStatus::Cancelled(wfr::Cancellation {
|
367
|
+
failure: Some(failure),
|
368
|
+
})),
|
369
|
+
}),
|
370
|
+
}
|
371
|
+
}
|
372
|
+
}
|
373
|
+
|
374
|
+
impl TryFrom<HistoryEvent> for ChildWorkflowMachineEvents {
|
375
|
+
type Error = WFMachinesError;
|
376
|
+
|
377
|
+
fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
|
378
|
+
Ok(match EventType::from_i32(e.event_type) {
|
379
|
+
Some(EventType::StartChildWorkflowExecutionInitiated) => {
|
380
|
+
Self::StartChildWorkflowExecutionInitiated(e.event_id)
|
381
|
+
}
|
382
|
+
Some(EventType::StartChildWorkflowExecutionFailed) => {
|
383
|
+
if let Some(
|
384
|
+
history_event::Attributes::StartChildWorkflowExecutionFailedEventAttributes(
|
385
|
+
StartChildWorkflowExecutionFailedEventAttributes { cause, .. },
|
386
|
+
),
|
387
|
+
) = e.attributes
|
388
|
+
{
|
389
|
+
Self::StartChildWorkflowExecutionFailed(
|
390
|
+
StartChildWorkflowExecutionFailedCause::from_i32(cause).ok_or_else(
|
391
|
+
|| {
|
392
|
+
WFMachinesError::Fatal(
|
393
|
+
"Invalid StartChildWorkflowExecutionFailedCause".to_string(),
|
394
|
+
)
|
395
|
+
},
|
396
|
+
)?,
|
397
|
+
)
|
398
|
+
} else {
|
399
|
+
return Err(WFMachinesError::Fatal(
|
400
|
+
"StartChildWorkflowExecutionFailed attributes were unset".to_string(),
|
401
|
+
));
|
402
|
+
}
|
403
|
+
}
|
404
|
+
Some(EventType::ChildWorkflowExecutionStarted) => {
|
405
|
+
if let Some(
|
406
|
+
history_event::Attributes::ChildWorkflowExecutionStartedEventAttributes(
|
407
|
+
ChildWorkflowExecutionStartedEventAttributes {
|
408
|
+
workflow_execution: Some(we),
|
409
|
+
..
|
410
|
+
},
|
411
|
+
),
|
412
|
+
) = e.attributes
|
413
|
+
{
|
414
|
+
Self::ChildWorkflowExecutionStarted(ChildWorkflowExecutionStartedEvent {
|
415
|
+
workflow_execution: we,
|
416
|
+
started_event_id: e.event_id,
|
417
|
+
})
|
418
|
+
} else {
|
419
|
+
return Err(WFMachinesError::Fatal(
|
420
|
+
"ChildWorkflowExecutionStarted attributes were unset or malformed"
|
421
|
+
.to_string(),
|
422
|
+
));
|
423
|
+
}
|
424
|
+
}
|
425
|
+
Some(EventType::ChildWorkflowExecutionCompleted) => {
|
426
|
+
if let Some(
|
427
|
+
history_event::Attributes::ChildWorkflowExecutionCompletedEventAttributes(
|
428
|
+
ChildWorkflowExecutionCompletedEventAttributes { result, .. },
|
429
|
+
),
|
430
|
+
) = e.attributes
|
431
|
+
{
|
432
|
+
Self::ChildWorkflowExecutionCompleted(result)
|
433
|
+
} else {
|
434
|
+
return Err(WFMachinesError::Fatal(
|
435
|
+
"ChildWorkflowExecutionCompleted attributes were unset or malformed"
|
436
|
+
.to_string(),
|
437
|
+
));
|
438
|
+
}
|
439
|
+
}
|
440
|
+
Some(EventType::ChildWorkflowExecutionFailed) => {
|
441
|
+
if let Some(
|
442
|
+
history_event::Attributes::ChildWorkflowExecutionFailedEventAttributes(attrs),
|
443
|
+
) = e.attributes
|
444
|
+
{
|
445
|
+
Self::ChildWorkflowExecutionFailed(attrs)
|
446
|
+
} else {
|
447
|
+
return Err(WFMachinesError::Fatal(
|
448
|
+
"ChildWorkflowExecutionFailed attributes were unset".to_string(),
|
449
|
+
));
|
450
|
+
}
|
451
|
+
}
|
452
|
+
Some(EventType::ChildWorkflowExecutionTimedOut) => {
|
453
|
+
if let Some(
|
454
|
+
history_event::Attributes::ChildWorkflowExecutionTimedOutEventAttributes(atts),
|
455
|
+
) = e.attributes
|
456
|
+
{
|
457
|
+
Self::ChildWorkflowExecutionTimedOut(atts.retry_state())
|
458
|
+
} else {
|
459
|
+
return Err(WFMachinesError::Fatal(
|
460
|
+
"ChildWorkflowExecutionTimedOut attributes were unset or malformed"
|
461
|
+
.to_string(),
|
462
|
+
));
|
463
|
+
}
|
464
|
+
}
|
465
|
+
Some(EventType::ChildWorkflowExecutionTerminated) => {
|
466
|
+
Self::ChildWorkflowExecutionTerminated
|
467
|
+
}
|
468
|
+
Some(EventType::ChildWorkflowExecutionCanceled) => {
|
469
|
+
Self::ChildWorkflowExecutionCancelled
|
470
|
+
}
|
471
|
+
_ => {
|
472
|
+
return Err(WFMachinesError::Fatal(format!(
|
473
|
+
"Child workflow machine does not handle this event: {:?}",
|
474
|
+
e
|
475
|
+
)))
|
476
|
+
}
|
477
|
+
})
|
478
|
+
}
|
479
|
+
}
|
480
|
+
|
481
|
+
impl WFMachinesAdapter for ChildWorkflowMachine {
|
482
|
+
fn adapt_response(
|
483
|
+
&self,
|
484
|
+
my_command: Self::Command,
|
485
|
+
event_info: Option<EventInfo>,
|
486
|
+
) -> Result<Vec<MachineResponse>, WFMachinesError> {
|
487
|
+
Ok(match my_command {
|
488
|
+
ChildWorkflowCommand::Start(we) => {
|
489
|
+
vec![ResolveChildWorkflowExecutionStart {
|
490
|
+
seq: self.shared_state.lang_sequence_number,
|
491
|
+
status: Some(resolve_child_workflow_execution_start::Status::Succeeded(
|
492
|
+
ResolveChildWorkflowExecutionStartSuccess { run_id: we.run_id },
|
493
|
+
)),
|
494
|
+
}
|
495
|
+
.into()]
|
496
|
+
}
|
497
|
+
ChildWorkflowCommand::StartFail(cause) => {
|
498
|
+
vec![ResolveChildWorkflowExecutionStart {
|
499
|
+
seq: self.shared_state.lang_sequence_number,
|
500
|
+
status: Some(resolve_child_workflow_execution_start::Status::Failed(
|
501
|
+
ResolveChildWorkflowExecutionStartFailure {
|
502
|
+
workflow_id: self.shared_state.workflow_id.clone(),
|
503
|
+
workflow_type: self.shared_state.workflow_type.clone(),
|
504
|
+
cause: cause as i32,
|
505
|
+
},
|
506
|
+
)),
|
507
|
+
}
|
508
|
+
.into()]
|
509
|
+
}
|
510
|
+
ChildWorkflowCommand::StartCancel(failure) => {
|
511
|
+
vec![ResolveChildWorkflowExecutionStart {
|
512
|
+
seq: self.shared_state.lang_sequence_number,
|
513
|
+
status: Some(resolve_child_workflow_execution_start::Status::Cancelled(
|
514
|
+
ResolveChildWorkflowExecutionStartCancelled {
|
515
|
+
failure: Some(failure),
|
516
|
+
},
|
517
|
+
)),
|
518
|
+
}
|
519
|
+
.into()]
|
520
|
+
}
|
521
|
+
ChildWorkflowCommand::Complete(result) => {
|
522
|
+
vec![ResolveChildWorkflowExecution {
|
523
|
+
seq: self.shared_state.lang_sequence_number,
|
524
|
+
result: Some(ChildWorkflowResult {
|
525
|
+
status: Some(ChildWorkflowStatus::Completed(wfr::Success {
|
526
|
+
result: convert_payloads(event_info, result)?,
|
527
|
+
})),
|
528
|
+
}),
|
529
|
+
}
|
530
|
+
.into()]
|
531
|
+
}
|
532
|
+
ChildWorkflowCommand::Fail(failure) => {
|
533
|
+
vec![ResolveChildWorkflowExecution {
|
534
|
+
seq: self.shared_state.lang_sequence_number,
|
535
|
+
result: Some(ChildWorkflowResult {
|
536
|
+
status: Some(ChildWorkflowStatus::Failed(wfr::Failure {
|
537
|
+
failure: Some(failure),
|
538
|
+
})),
|
539
|
+
}),
|
540
|
+
}
|
541
|
+
.into()]
|
542
|
+
}
|
543
|
+
ChildWorkflowCommand::Cancel => {
|
544
|
+
vec![self.resolve_cancelled_msg().into()]
|
545
|
+
}
|
546
|
+
ChildWorkflowCommand::IssueCancelAfterStarted { reason } => {
|
547
|
+
let mut resps = vec![];
|
548
|
+
if self.shared_state.cancel_type != ChildWorkflowCancellationType::Abandon {
|
549
|
+
resps.push(MachineResponse::NewCoreOriginatedCommand(
|
550
|
+
RequestCancelExternalWorkflowExecutionCommandAttributes {
|
551
|
+
namespace: self.shared_state.namespace.clone(),
|
552
|
+
workflow_id: self.shared_state.workflow_id.clone(),
|
553
|
+
run_id: self.shared_state.run_id.clone(),
|
554
|
+
child_workflow_only: true,
|
555
|
+
reason,
|
556
|
+
control: "".to_string(),
|
557
|
+
}
|
558
|
+
.into(),
|
559
|
+
))
|
560
|
+
}
|
561
|
+
// Immediately resolve abandon/trycancel modes
|
562
|
+
if matches!(
|
563
|
+
self.shared_state.cancel_type,
|
564
|
+
ChildWorkflowCancellationType::Abandon
|
565
|
+
| ChildWorkflowCancellationType::TryCancel
|
566
|
+
) {
|
567
|
+
resps.push(self.resolve_cancelled_msg().into())
|
568
|
+
}
|
569
|
+
resps
|
570
|
+
}
|
571
|
+
})
|
572
|
+
}
|
573
|
+
|
574
|
+
fn matches_event(&self, event: &HistoryEvent) -> bool {
|
575
|
+
matches!(
|
576
|
+
event.event_type(),
|
577
|
+
EventType::StartChildWorkflowExecutionInitiated
|
578
|
+
| EventType::StartChildWorkflowExecutionFailed
|
579
|
+
| EventType::ChildWorkflowExecutionStarted
|
580
|
+
| EventType::ChildWorkflowExecutionCompleted
|
581
|
+
| EventType::ChildWorkflowExecutionFailed
|
582
|
+
| EventType::ChildWorkflowExecutionTimedOut
|
583
|
+
| EventType::ChildWorkflowExecutionTerminated
|
584
|
+
| EventType::ChildWorkflowExecutionCanceled
|
585
|
+
)
|
586
|
+
}
|
587
|
+
|
588
|
+
fn kind(&self) -> MachineKind {
|
589
|
+
MachineKind::ChildWorkflow
|
590
|
+
}
|
591
|
+
}
|
592
|
+
|
593
|
+
impl TryFrom<CommandType> for ChildWorkflowMachineEvents {
|
594
|
+
type Error = ();
|
595
|
+
|
596
|
+
fn try_from(c: CommandType) -> Result<Self, Self::Error> {
|
597
|
+
Ok(match c {
|
598
|
+
CommandType::StartChildWorkflowExecution => Self::CommandStartChildWorkflowExecution,
|
599
|
+
CommandType::RequestCancelExternalWorkflowExecution => {
|
600
|
+
Self::CommandRequestCancelExternalWorkflowExecution
|
601
|
+
}
|
602
|
+
_ => return Err(()),
|
603
|
+
})
|
604
|
+
}
|
605
|
+
}
|
606
|
+
|
607
|
+
impl Cancellable for ChildWorkflowMachine {
|
608
|
+
fn cancel(&mut self) -> Result<Vec<MachineResponse>, MachineError<Self::Error>> {
|
609
|
+
let event = ChildWorkflowMachineEvents::Cancel;
|
610
|
+
let vec = OnEventWrapper::on_event_mut(self, event)?;
|
611
|
+
let res = vec
|
612
|
+
.into_iter()
|
613
|
+
.map(|mc| match mc {
|
614
|
+
c @ ChildWorkflowCommand::StartCancel(_)
|
615
|
+
| c @ ChildWorkflowCommand::IssueCancelAfterStarted { .. } => {
|
616
|
+
self.adapt_response(c, None)
|
617
|
+
}
|
618
|
+
x => panic!("Invalid cancel event response {:?}", x),
|
619
|
+
})
|
620
|
+
.collect::<Result<Vec<_>, _>>()?
|
621
|
+
.into_iter()
|
622
|
+
.flatten()
|
623
|
+
.collect();
|
624
|
+
Ok(res)
|
625
|
+
}
|
626
|
+
|
627
|
+
fn was_cancelled_before_sent_to_server(&self) -> bool {
|
628
|
+
self.shared_state.cancelled_before_sent
|
629
|
+
}
|
630
|
+
}
|
631
|
+
|
632
|
+
fn failure_info_from_state(state: &SharedState, retry_state: RetryState) -> Option<FailureInfo> {
|
633
|
+
Some(FailureInfo::ChildWorkflowExecutionFailureInfo(
|
634
|
+
failure::ChildWorkflowExecutionFailureInfo {
|
635
|
+
namespace: state.namespace.clone(),
|
636
|
+
workflow_type: Some(WorkflowType {
|
637
|
+
name: state.workflow_type.clone(),
|
638
|
+
}),
|
639
|
+
initiated_event_id: state.initiated_event_id,
|
640
|
+
started_event_id: state.started_event_id,
|
641
|
+
retry_state: retry_state as i32,
|
642
|
+
workflow_execution: Some(WorkflowExecution {
|
643
|
+
workflow_id: state.workflow_id.clone(),
|
644
|
+
run_id: state.run_id.clone(),
|
645
|
+
}),
|
646
|
+
},
|
647
|
+
))
|
648
|
+
}
|
649
|
+
|
650
|
+
fn convert_payloads(
|
651
|
+
event_info: Option<EventInfo>,
|
652
|
+
result: Option<Payloads>,
|
653
|
+
) -> Result<Option<Payload>, WFMachinesError> {
|
654
|
+
result.map(TryInto::try_into).transpose().map_err(|pe| {
|
655
|
+
WFMachinesError::Fatal(format!(
|
656
|
+
"Not exactly one payload in child workflow result ({}) for event: {:?}",
|
657
|
+
pe, event_info
|
658
|
+
))
|
659
|
+
})
|
660
|
+
}
|
661
|
+
|
662
|
+
#[cfg(test)]
|
663
|
+
mod test {
|
664
|
+
use super::*;
|
665
|
+
use crate::{
|
666
|
+
replay::TestHistoryBuilder, test_help::canned_histories, worker::workflow::ManagedWFFunc,
|
667
|
+
};
|
668
|
+
use anyhow::anyhow;
|
669
|
+
use rstest::{fixture, rstest};
|
670
|
+
use std::mem::discriminant;
|
671
|
+
use temporal_sdk::{
|
672
|
+
CancellableFuture, ChildWorkflowOptions, WfContext, WorkflowFunction, WorkflowResult,
|
673
|
+
};
|
674
|
+
use temporal_sdk_core_protos::coresdk::{
|
675
|
+
child_workflow::child_workflow_result,
|
676
|
+
workflow_activation::resolve_child_workflow_execution_start::Status as StartStatus,
|
677
|
+
};
|
678
|
+
|
679
|
+
#[derive(Clone, Copy)]
|
680
|
+
enum Expectation {
|
681
|
+
Success,
|
682
|
+
Failure,
|
683
|
+
StartFailure,
|
684
|
+
}
|
685
|
+
|
686
|
+
impl Expectation {
|
687
|
+
const fn try_from_u8(x: u8) -> Option<Self> {
|
688
|
+
Some(match x {
|
689
|
+
0 => Self::Success,
|
690
|
+
1 => Self::Failure,
|
691
|
+
2 => Self::StartFailure,
|
692
|
+
_ => return None,
|
693
|
+
})
|
694
|
+
}
|
695
|
+
}
|
696
|
+
|
697
|
+
#[fixture]
|
698
|
+
fn child_workflow_happy_hist() -> ManagedWFFunc {
|
699
|
+
let func = WorkflowFunction::new(parent_wf);
|
700
|
+
let t = canned_histories::single_child_workflow("child-id-1");
|
701
|
+
assert_eq!(3, t.get_full_history_info().unwrap().wf_task_count());
|
702
|
+
ManagedWFFunc::new(t, func, vec![[Expectation::Success as u8].into()])
|
703
|
+
}
|
704
|
+
|
705
|
+
#[fixture]
|
706
|
+
fn child_workflow_fail_hist() -> ManagedWFFunc {
|
707
|
+
let func = WorkflowFunction::new(parent_wf);
|
708
|
+
let t = canned_histories::single_child_workflow_fail("child-id-1");
|
709
|
+
assert_eq!(3, t.get_full_history_info().unwrap().wf_task_count());
|
710
|
+
ManagedWFFunc::new(t, func, vec![[Expectation::Failure as u8].into()])
|
711
|
+
}
|
712
|
+
|
713
|
+
#[fixture]
|
714
|
+
fn child_workflow_start_fail_hist() -> ManagedWFFunc {
|
715
|
+
let func = WorkflowFunction::new(parent_wf);
|
716
|
+
let t = canned_histories::single_child_workflow_start_fail("child-id-1");
|
717
|
+
assert_eq!(2, t.get_full_history_info().unwrap().wf_task_count());
|
718
|
+
ManagedWFFunc::new(t, func, vec![[Expectation::StartFailure as u8].into()])
|
719
|
+
}
|
720
|
+
|
721
|
+
async fn parent_wf(ctx: WfContext) -> WorkflowResult<()> {
|
722
|
+
let expectation = Expectation::try_from_u8(ctx.get_args()[0].data[0]).unwrap();
|
723
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
724
|
+
workflow_id: "child-id-1".to_string(),
|
725
|
+
workflow_type: "child".to_string(),
|
726
|
+
..Default::default()
|
727
|
+
});
|
728
|
+
|
729
|
+
let start_res = child.start(&ctx).await;
|
730
|
+
match (expectation, &start_res.status) {
|
731
|
+
(Expectation::Success | Expectation::Failure, StartStatus::Succeeded(_)) => {}
|
732
|
+
(Expectation::StartFailure, StartStatus::Failed(_)) => return Ok(().into()),
|
733
|
+
_ => return Err(anyhow!("Unexpected start status")),
|
734
|
+
};
|
735
|
+
match (
|
736
|
+
expectation,
|
737
|
+
start_res.into_started().unwrap().result().await.status,
|
738
|
+
) {
|
739
|
+
(Expectation::Success, Some(child_workflow_result::Status::Completed(_))) => {
|
740
|
+
Ok(().into())
|
741
|
+
}
|
742
|
+
(Expectation::Failure, _) => Ok(().into()),
|
743
|
+
_ => Err(anyhow!("Unexpected child WF status")),
|
744
|
+
}
|
745
|
+
}
|
746
|
+
|
747
|
+
#[rstest(
|
748
|
+
wfm,
|
749
|
+
case::success(child_workflow_happy_hist()),
|
750
|
+
case::failure(child_workflow_fail_hist())
|
751
|
+
)]
|
752
|
+
#[tokio::test]
|
753
|
+
async fn single_child_workflow_until_completion(mut wfm: ManagedWFFunc) {
|
754
|
+
wfm.get_next_activation().await.unwrap();
|
755
|
+
let commands = wfm.get_server_commands().commands;
|
756
|
+
assert_eq!(commands.len(), 1);
|
757
|
+
assert_eq!(
|
758
|
+
commands[0].command_type,
|
759
|
+
CommandType::StartChildWorkflowExecution as i32
|
760
|
+
);
|
761
|
+
|
762
|
+
wfm.get_next_activation().await.unwrap();
|
763
|
+
let commands = wfm.get_server_commands().commands;
|
764
|
+
// Workflow is activated because the child WF has started.
|
765
|
+
// It does not generate any commands, just waits for completion.
|
766
|
+
assert_eq!(commands.len(), 0);
|
767
|
+
|
768
|
+
wfm.get_next_activation().await.unwrap();
|
769
|
+
let commands = wfm.get_server_commands().commands;
|
770
|
+
assert_eq!(commands.len(), 1);
|
771
|
+
assert_eq!(
|
772
|
+
commands[0].command_type,
|
773
|
+
CommandType::CompleteWorkflowExecution as i32
|
774
|
+
);
|
775
|
+
wfm.shutdown().await.unwrap();
|
776
|
+
}
|
777
|
+
|
778
|
+
#[rstest(wfm, case::start_failure(child_workflow_start_fail_hist()))]
|
779
|
+
#[tokio::test]
|
780
|
+
async fn single_child_workflow_start_fail(mut wfm: ManagedWFFunc) {
|
781
|
+
wfm.get_next_activation().await.unwrap();
|
782
|
+
let commands = wfm.get_server_commands().commands;
|
783
|
+
assert_eq!(commands.len(), 1);
|
784
|
+
assert_eq!(
|
785
|
+
commands[0].command_type,
|
786
|
+
CommandType::StartChildWorkflowExecution as i32
|
787
|
+
);
|
788
|
+
|
789
|
+
wfm.get_next_activation().await.unwrap();
|
790
|
+
let commands = wfm.get_server_commands().commands;
|
791
|
+
assert_eq!(commands.len(), 1);
|
792
|
+
assert_eq!(
|
793
|
+
commands[0].command_type,
|
794
|
+
CommandType::CompleteWorkflowExecution as i32
|
795
|
+
);
|
796
|
+
wfm.shutdown().await.unwrap();
|
797
|
+
}
|
798
|
+
|
799
|
+
async fn cancel_before_send_wf(ctx: WfContext) -> WorkflowResult<()> {
|
800
|
+
let workflow_id = "child-id-1";
|
801
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
802
|
+
workflow_id: workflow_id.to_string(),
|
803
|
+
workflow_type: "child".to_string(),
|
804
|
+
..Default::default()
|
805
|
+
});
|
806
|
+
let start = child.start(&ctx);
|
807
|
+
start.cancel(&ctx);
|
808
|
+
match start.await.status {
|
809
|
+
StartStatus::Cancelled(_) => Ok(().into()),
|
810
|
+
_ => Err(anyhow!("Unexpected start status")),
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
814
|
+
#[fixture]
|
815
|
+
fn child_workflow_cancel_before_sent() -> ManagedWFFunc {
|
816
|
+
let func = WorkflowFunction::new(cancel_before_send_wf);
|
817
|
+
let mut t = TestHistoryBuilder::default();
|
818
|
+
t.add_by_type(EventType::WorkflowExecutionStarted);
|
819
|
+
t.add_full_wf_task();
|
820
|
+
t.add_workflow_task_scheduled_and_started();
|
821
|
+
assert_eq!(2, t.get_full_history_info().unwrap().wf_task_count());
|
822
|
+
ManagedWFFunc::new(t, func, vec![])
|
823
|
+
}
|
824
|
+
|
825
|
+
#[rstest(wfm, case::default(child_workflow_cancel_before_sent()))]
|
826
|
+
#[tokio::test]
|
827
|
+
async fn single_child_workflow_cancel_before_sent(mut wfm: ManagedWFFunc) {
|
828
|
+
wfm.get_next_activation().await.unwrap();
|
829
|
+
let commands = wfm.get_server_commands().commands;
|
830
|
+
// Workflow starts and cancels the child workflow, no commands should be sent to server.
|
831
|
+
assert_eq!(commands.len(), 0);
|
832
|
+
|
833
|
+
wfm.get_next_activation().await.unwrap();
|
834
|
+
let commands = wfm.get_server_commands().commands;
|
835
|
+
assert_eq!(commands.len(), 1);
|
836
|
+
assert_eq!(
|
837
|
+
commands[0].command_type,
|
838
|
+
CommandType::CompleteWorkflowExecution as i32
|
839
|
+
);
|
840
|
+
wfm.shutdown().await.unwrap();
|
841
|
+
}
|
842
|
+
|
843
|
+
#[test]
|
844
|
+
fn cancels_ignored_terminal() {
|
845
|
+
for state in [
|
846
|
+
ChildWorkflowMachineState::Cancelled(Cancelled {}),
|
847
|
+
Failed {}.into(),
|
848
|
+
TimedOut {}.into(),
|
849
|
+
Completed {}.into(),
|
850
|
+
] {
|
851
|
+
let mut s = ChildWorkflowMachine {
|
852
|
+
state: state.clone(),
|
853
|
+
shared_state: Default::default(),
|
854
|
+
};
|
855
|
+
let cmds = s.cancel().unwrap();
|
856
|
+
assert_eq!(cmds.len(), 0);
|
857
|
+
assert_eq!(discriminant(&state), discriminant(&s.state));
|
858
|
+
}
|
859
|
+
}
|
860
|
+
}
|