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,825 @@
|
|
1
|
+
#![allow(
|
2
|
+
// Non-camel-case types needed since this is exported as a C header and we
|
3
|
+
// want C-like underscores in our type names
|
4
|
+
non_camel_case_types,
|
5
|
+
|
6
|
+
// We choose to have narrow "unsafe" blocks instead of marking entire
|
7
|
+
// functions as unsafe. Even the example in clippy's docs at
|
8
|
+
// https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
|
9
|
+
// cause a rustc warning for unnecessary inner-unsafe when marked on fn.
|
10
|
+
// This check only applies to "pub" functions which are all exposed via C
|
11
|
+
// API.
|
12
|
+
clippy::not_unsafe_ptr_arg_deref,
|
13
|
+
)]
|
14
|
+
|
15
|
+
mod wrappers;
|
16
|
+
|
17
|
+
use bridge::{init_response, CreateWorkerRequest, InitResponse};
|
18
|
+
use prost::Message;
|
19
|
+
use std::sync::Arc;
|
20
|
+
use temporal_sdk_core::{
|
21
|
+
fetch_global_buffered_logs, telemetry_init, Client, ClientOptions, RetryClient,
|
22
|
+
};
|
23
|
+
use temporal_sdk_core_api::Worker;
|
24
|
+
use temporal_sdk_core_protos::coresdk::{
|
25
|
+
bridge,
|
26
|
+
bridge::{CreateClientRequest, InitTelemetryRequest},
|
27
|
+
};
|
28
|
+
|
29
|
+
/// A set of bytes owned by Core. No fields within nor any bytes references must
|
30
|
+
/// ever be mutated outside of Core. This must always be passed to
|
31
|
+
/// tmprl_bytes_free when no longer in use.
|
32
|
+
#[repr(C)]
|
33
|
+
pub struct tmprl_bytes_t {
|
34
|
+
bytes: *const u8,
|
35
|
+
len: libc::size_t,
|
36
|
+
/// For internal use only.
|
37
|
+
cap: libc::size_t,
|
38
|
+
/// For internal use only.
|
39
|
+
disable_free: bool,
|
40
|
+
}
|
41
|
+
|
42
|
+
impl tmprl_bytes_t {
|
43
|
+
fn from_vec(vec: Vec<u8>) -> tmprl_bytes_t {
|
44
|
+
// Mimics Vec::into_raw_parts that's only available in nightly
|
45
|
+
let mut vec = std::mem::ManuallyDrop::new(vec);
|
46
|
+
tmprl_bytes_t {
|
47
|
+
bytes: vec.as_mut_ptr(),
|
48
|
+
len: vec.len(),
|
49
|
+
cap: vec.capacity(),
|
50
|
+
disable_free: false,
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
fn from_vec_disable_free(vec: Vec<u8>) -> tmprl_bytes_t {
|
55
|
+
let mut b = tmprl_bytes_t::from_vec(vec);
|
56
|
+
b.disable_free = true;
|
57
|
+
b
|
58
|
+
}
|
59
|
+
|
60
|
+
fn into_raw(self) -> *mut tmprl_bytes_t {
|
61
|
+
Box::into_raw(Box::new(self))
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
/// Required because these instances are used by lazy_static and raw pointers
|
66
|
+
/// are not usually safe for send/sync.
|
67
|
+
unsafe impl Send for tmprl_bytes_t {}
|
68
|
+
unsafe impl Sync for tmprl_bytes_t {}
|
69
|
+
|
70
|
+
impl Drop for tmprl_bytes_t {
|
71
|
+
fn drop(&mut self) {
|
72
|
+
// In cases where freeing is disabled (or technically some other
|
73
|
+
// drop-but-not-freed situation though we don't expect any), the bytes
|
74
|
+
// remain non-null so we re-own them here
|
75
|
+
if !self.bytes.is_null() {
|
76
|
+
unsafe { Vec::from_raw_parts(self.bytes as *mut u8, self.len, self.cap) };
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
/// Free a set of bytes. The first parameter can be null in cases where a [tmprl_worker_t] instance
|
82
|
+
/// isn't available. If the second parameter is null, this is a no-op.
|
83
|
+
#[no_mangle]
|
84
|
+
pub extern "C" fn tmprl_bytes_free(worker: *mut tmprl_worker_t, bytes: *const tmprl_bytes_t) {
|
85
|
+
// Bail if freeing is disabled
|
86
|
+
unsafe {
|
87
|
+
if bytes.is_null() || (*bytes).disable_free {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
let bytes = bytes as *mut tmprl_bytes_t;
|
92
|
+
// Return vec back to core before dropping bytes
|
93
|
+
let vec = unsafe { Vec::from_raw_parts((*bytes).bytes as *mut u8, (*bytes).len, (*bytes).cap) };
|
94
|
+
// Set to null so the byte dropper doesn't try to free it
|
95
|
+
unsafe { (*bytes).bytes = std::ptr::null_mut() };
|
96
|
+
// Return only if worker is non-null
|
97
|
+
if !worker.is_null() {
|
98
|
+
let worker = unsafe { &mut *worker };
|
99
|
+
worker.return_buf(vec);
|
100
|
+
}
|
101
|
+
unsafe {
|
102
|
+
let _ = Box::from_raw(bytes);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
/// Used for maintaining pointer to user data across threads. See
|
107
|
+
/// https://doc.rust-lang.org/nomicon/send-and-sync.html.
|
108
|
+
struct UserDataHandle(*mut libc::c_void);
|
109
|
+
unsafe impl Send for UserDataHandle {}
|
110
|
+
unsafe impl Sync for UserDataHandle {}
|
111
|
+
|
112
|
+
impl From<UserDataHandle> for *mut libc::c_void {
|
113
|
+
fn from(v: UserDataHandle) -> Self {
|
114
|
+
v.0
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
lazy_static::lazy_static! {
|
119
|
+
static ref DEFAULT_INIT_RESPONSE_BYTES: tmprl_bytes_t = {
|
120
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::InitResponse::default().encode_to_vec())
|
121
|
+
};
|
122
|
+
|
123
|
+
static ref DEFAULT_REGISTER_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
|
124
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::RegisterWorkerResponse::default().encode_to_vec())
|
125
|
+
};
|
126
|
+
|
127
|
+
static ref DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES: tmprl_bytes_t = {
|
128
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::ShutdownWorkerResponse::default().encode_to_vec())
|
129
|
+
};
|
130
|
+
|
131
|
+
static ref DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES: tmprl_bytes_t = {
|
132
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::CompleteWorkflowActivationResponse::default().encode_to_vec())
|
133
|
+
};
|
134
|
+
|
135
|
+
static ref DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES: tmprl_bytes_t = {
|
136
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::CompleteActivityTaskResponse::default().encode_to_vec())
|
137
|
+
};
|
138
|
+
|
139
|
+
static ref DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES: tmprl_bytes_t = {
|
140
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::RecordActivityHeartbeatResponse::default().encode_to_vec())
|
141
|
+
};
|
142
|
+
|
143
|
+
static ref DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES: tmprl_bytes_t = {
|
144
|
+
tmprl_bytes_t::from_vec_disable_free(bridge::RequestWorkflowEvictionResponse::default().encode_to_vec())
|
145
|
+
};
|
146
|
+
}
|
147
|
+
|
148
|
+
/// A runtime owned by Core. This must be passed to [tmprl_runtime_free] when no longer in use. This
|
149
|
+
/// should not be freed until every call to every [tmprl_worker_t] instance created with this
|
150
|
+
/// runtime has been shutdown. In practice, since the actual runtime is behind an [Arc], it's
|
151
|
+
/// currently OK, but that's an implementation detail.
|
152
|
+
pub struct tmprl_runtime_t {
|
153
|
+
// This is the same runtime shared with worker instances
|
154
|
+
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
155
|
+
}
|
156
|
+
|
157
|
+
/// Create a new runtime. The result is never null and must be freed via
|
158
|
+
/// tmprl_runtime_free when no longer in use.
|
159
|
+
#[no_mangle]
|
160
|
+
pub extern "C" fn tmprl_runtime_new() -> *mut tmprl_runtime_t {
|
161
|
+
Box::into_raw(Box::new(tmprl_runtime_t {
|
162
|
+
// TODO(cretz): Options to configure thread pool?
|
163
|
+
tokio_runtime: Arc::new(
|
164
|
+
tokio::runtime::Builder::new_multi_thread()
|
165
|
+
.enable_all()
|
166
|
+
.build()
|
167
|
+
.unwrap(),
|
168
|
+
),
|
169
|
+
}))
|
170
|
+
}
|
171
|
+
|
172
|
+
/// Free a previously created runtime.
|
173
|
+
#[no_mangle]
|
174
|
+
pub extern "C" fn tmprl_runtime_free(runtime: *mut tmprl_runtime_t) {
|
175
|
+
if !runtime.is_null() {
|
176
|
+
unsafe {
|
177
|
+
let _ = Box::from_raw(runtime);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
/// A worker instance owned by Core. This must be passed to [tmprl_worker_shutdown]
|
183
|
+
/// when no longer in use which will free the resources.
|
184
|
+
pub struct tmprl_worker_t {
|
185
|
+
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
186
|
+
// We are not concerned with the overhead of dynamic dispatch at this time
|
187
|
+
worker: Arc<dyn Worker>,
|
188
|
+
}
|
189
|
+
|
190
|
+
/// Callback called by [tmprl_worker_init] on completion. The first parameter of the
|
191
|
+
/// callback is user data passed into the original function. The second
|
192
|
+
/// parameter is a worker instance if the call is successful or null if not. If
|
193
|
+
/// present, the worker instance must be freed via [tmprl_worker_shutdown] when no
|
194
|
+
/// longer in use. The third parameter of the callback is a byte array for a
|
195
|
+
/// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
|
196
|
+
type tmprl_worker_init_callback = unsafe extern "C" fn(
|
197
|
+
user_data: *mut libc::c_void,
|
198
|
+
worker: *mut tmprl_worker_t,
|
199
|
+
resp: *const tmprl_bytes_t,
|
200
|
+
);
|
201
|
+
|
202
|
+
/// Callback called on function completion. The first parameter of the callback
|
203
|
+
/// is user data passed into the original function. The second parameter of the
|
204
|
+
/// callback is a never-null byte array for a response protobuf message which
|
205
|
+
/// must be freed via [tmprl_bytes_free].
|
206
|
+
type tmprl_callback =
|
207
|
+
unsafe extern "C" fn(user_data: *mut libc::c_void, core: *const tmprl_bytes_t);
|
208
|
+
|
209
|
+
/// Create a new worker instance.
|
210
|
+
///
|
211
|
+
/// `runtime` and `client` are both required and must outlive this instance.
|
212
|
+
/// `req_proto` and `req_proto_len` represent a byte array for a [CreateWorkerRequest] protobuf
|
213
|
+
/// message.
|
214
|
+
/// The callback is invoked on completion.
|
215
|
+
#[no_mangle]
|
216
|
+
pub extern "C" fn tmprl_worker_init(
|
217
|
+
runtime: *mut tmprl_runtime_t,
|
218
|
+
client: *mut tmprl_client_t,
|
219
|
+
req_proto: *const u8,
|
220
|
+
req_proto_len: libc::size_t,
|
221
|
+
user_data: *mut libc::c_void,
|
222
|
+
callback: tmprl_worker_init_callback,
|
223
|
+
) {
|
224
|
+
let (runtime, client) = unsafe { (&*runtime, &*client) };
|
225
|
+
let req = match tmprl_worker_t::decode_proto::<CreateWorkerRequest>(req_proto, req_proto_len) {
|
226
|
+
Ok(req) => req,
|
227
|
+
Err(message) => {
|
228
|
+
let resp = InitResponse {
|
229
|
+
error: Some(init_response::Error { message }),
|
230
|
+
};
|
231
|
+
unsafe {
|
232
|
+
callback(
|
233
|
+
user_data,
|
234
|
+
std::ptr::null_mut(),
|
235
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
236
|
+
);
|
237
|
+
}
|
238
|
+
return;
|
239
|
+
}
|
240
|
+
};
|
241
|
+
let user_data = UserDataHandle(user_data);
|
242
|
+
match tmprl_worker_t::new(
|
243
|
+
runtime.tokio_runtime.clone(),
|
244
|
+
client.client.clone(),
|
245
|
+
wrappers::WorkerConfig(req),
|
246
|
+
) {
|
247
|
+
Ok(worker) => unsafe {
|
248
|
+
callback(
|
249
|
+
user_data.into(),
|
250
|
+
Box::into_raw(Box::new(worker)),
|
251
|
+
&*DEFAULT_INIT_RESPONSE_BYTES,
|
252
|
+
);
|
253
|
+
},
|
254
|
+
Err(message) => {
|
255
|
+
let resp = InitResponse {
|
256
|
+
error: Some(init_response::Error { message }),
|
257
|
+
};
|
258
|
+
unsafe {
|
259
|
+
callback(
|
260
|
+
user_data.into(),
|
261
|
+
std::ptr::null_mut(),
|
262
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
263
|
+
);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
};
|
267
|
+
}
|
268
|
+
|
269
|
+
/// Shutdown and free a previously created worker.
|
270
|
+
///
|
271
|
+
/// The req_proto and req_proto_len represent a byte array for a [bridge::ShutdownWorkerRequest]
|
272
|
+
/// protobuf message, which currently contains nothing and are unused, but the parameters are kept
|
273
|
+
/// for now.
|
274
|
+
///
|
275
|
+
/// The callback is invoked on completion with a ShutdownWorkerResponse protobuf message.
|
276
|
+
///
|
277
|
+
/// After the callback has been called, the worker struct will be freed and the pointer will no
|
278
|
+
/// longer be valid.
|
279
|
+
#[no_mangle]
|
280
|
+
pub extern "C" fn tmprl_worker_shutdown(
|
281
|
+
worker: *mut tmprl_worker_t,
|
282
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
283
|
+
req_proto: *const u8,
|
284
|
+
#[allow(unused_variables)] req_proto_len: libc::size_t,
|
285
|
+
user_data: *mut libc::c_void,
|
286
|
+
callback: tmprl_callback,
|
287
|
+
) {
|
288
|
+
let worker = unsafe { Box::from_raw(worker) };
|
289
|
+
let user_data = UserDataHandle(user_data);
|
290
|
+
worker.tokio_runtime.clone().spawn(async move {
|
291
|
+
worker.shutdown().await;
|
292
|
+
unsafe {
|
293
|
+
callback(user_data.into(), &*DEFAULT_SHUTDOWN_WORKER_RESPONSE_BYTES);
|
294
|
+
}
|
295
|
+
drop(worker);
|
296
|
+
});
|
297
|
+
}
|
298
|
+
|
299
|
+
/// Initialize process-wide telemetry. Should only be called once, subsequent calls will be ignored
|
300
|
+
/// by core.
|
301
|
+
///
|
302
|
+
/// Unlike the other functions in this bridge, this blocks until initting is complete, as telemetry
|
303
|
+
/// should typically be initialized before doing other work.
|
304
|
+
///
|
305
|
+
/// Returns a byte array for a [InitResponse] protobuf message which must be freed via
|
306
|
+
/// tmprl_bytes_free.
|
307
|
+
#[no_mangle]
|
308
|
+
pub extern "C" fn tmprl_telemetry_init(
|
309
|
+
req_proto: *const u8,
|
310
|
+
req_proto_len: libc::size_t,
|
311
|
+
) -> *const tmprl_bytes_t {
|
312
|
+
let req = match tmprl_worker_t::decode_proto::<InitTelemetryRequest>(req_proto, req_proto_len) {
|
313
|
+
Ok(req) => req,
|
314
|
+
Err(message) => {
|
315
|
+
let resp = InitResponse {
|
316
|
+
error: Some(init_response::Error { message }),
|
317
|
+
};
|
318
|
+
return tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw();
|
319
|
+
}
|
320
|
+
};
|
321
|
+
|
322
|
+
match wrappers::InitTelemetryRequest(req)
|
323
|
+
.try_into()
|
324
|
+
.map(|opts| telemetry_init(&opts))
|
325
|
+
{
|
326
|
+
Ok(_) => &*DEFAULT_INIT_RESPONSE_BYTES,
|
327
|
+
Err(message) => {
|
328
|
+
let resp = InitResponse {
|
329
|
+
error: Some(init_response::Error { message }),
|
330
|
+
};
|
331
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw()
|
332
|
+
}
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
/// A client instance owned by Core. This must be passed to [tmprl_client_free]
|
337
|
+
/// when no longer in use which will free the resources.
|
338
|
+
pub struct tmprl_client_t {
|
339
|
+
client: Arc<RetryClient<Client>>,
|
340
|
+
}
|
341
|
+
|
342
|
+
impl tmprl_client_t {
|
343
|
+
pub fn new(client: Arc<RetryClient<Client>>) -> Self {
|
344
|
+
Self { client }
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
/// Callback called by [tmprl_client_init] on completion. The first parameter of the
|
349
|
+
/// callback is user data passed into the original function. The second
|
350
|
+
/// parameter is a client instance if the call is successful or null if not. If
|
351
|
+
/// present, the client instance must be freed via [tmprl_client_free] when no
|
352
|
+
/// longer in use. The third parameter of the callback is a byte array for a
|
353
|
+
/// [InitResponse] protobuf message which must be freed via [tmprl_bytes_free].
|
354
|
+
type tmprl_client_init_callback = unsafe extern "C" fn(
|
355
|
+
user_data: *mut libc::c_void,
|
356
|
+
client: *mut tmprl_client_t,
|
357
|
+
resp: *const tmprl_bytes_t,
|
358
|
+
);
|
359
|
+
|
360
|
+
/// Initialize a client connection to the Temporal service.
|
361
|
+
///
|
362
|
+
/// The runtime is required and must outlive this instance. The `req_proto` and `req_proto_len`
|
363
|
+
/// represent a byte array for a [CreateClientRequest] protobuf message. The callback is invoked on
|
364
|
+
/// completion.
|
365
|
+
#[no_mangle]
|
366
|
+
pub extern "C" fn tmprl_client_init(
|
367
|
+
runtime: *mut tmprl_runtime_t,
|
368
|
+
req_proto: *const u8,
|
369
|
+
req_proto_len: libc::size_t,
|
370
|
+
user_data: *mut libc::c_void,
|
371
|
+
callback: tmprl_client_init_callback,
|
372
|
+
) {
|
373
|
+
let runtime = unsafe { &*runtime };
|
374
|
+
let (namespace, req) =
|
375
|
+
match tmprl_worker_t::decode_proto::<CreateClientRequest>(req_proto, req_proto_len)
|
376
|
+
.and_then(|cgr| {
|
377
|
+
let ns = cgr.namespace.clone();
|
378
|
+
wrappers::ClientOptions(cgr)
|
379
|
+
.try_into()
|
380
|
+
.map(|sgo: ClientOptions| (ns, sgo))
|
381
|
+
}) {
|
382
|
+
Ok(req) => req,
|
383
|
+
Err(message) => {
|
384
|
+
let resp = InitResponse {
|
385
|
+
error: Some(init_response::Error { message }),
|
386
|
+
};
|
387
|
+
unsafe {
|
388
|
+
callback(
|
389
|
+
user_data,
|
390
|
+
std::ptr::null_mut(),
|
391
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
392
|
+
);
|
393
|
+
}
|
394
|
+
return;
|
395
|
+
}
|
396
|
+
};
|
397
|
+
|
398
|
+
let user_data = UserDataHandle(user_data);
|
399
|
+
runtime.tokio_runtime.spawn(async move {
|
400
|
+
match req.connect(namespace, None, None).await {
|
401
|
+
Ok(client) => unsafe {
|
402
|
+
callback(
|
403
|
+
user_data.into(),
|
404
|
+
Box::into_raw(Box::new(tmprl_client_t::new(Arc::new(client)))),
|
405
|
+
&*DEFAULT_INIT_RESPONSE_BYTES,
|
406
|
+
);
|
407
|
+
},
|
408
|
+
Err(e) => {
|
409
|
+
let resp = InitResponse {
|
410
|
+
error: Some(init_response::Error {
|
411
|
+
message: e.to_string(),
|
412
|
+
}),
|
413
|
+
};
|
414
|
+
unsafe {
|
415
|
+
callback(
|
416
|
+
user_data.into(),
|
417
|
+
std::ptr::null_mut(),
|
418
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
419
|
+
);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
});
|
424
|
+
}
|
425
|
+
|
426
|
+
/// Free a previously created client
|
427
|
+
#[no_mangle]
|
428
|
+
pub extern "C" fn tmprl_client_free(client: *mut tmprl_client_t) {
|
429
|
+
unsafe { drop(Box::from_raw(client)) };
|
430
|
+
}
|
431
|
+
|
432
|
+
/// Poll for a workflow activation.
|
433
|
+
///
|
434
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
435
|
+
/// [bridge::PollWorkflowActivationRequest] protobuf message, which currently contains nothing and
|
436
|
+
/// is unused, but the parameters are kept for now.
|
437
|
+
///
|
438
|
+
/// The callback is invoked on completion with a [bridge::PollWorkflowActivationResponse] protobuf
|
439
|
+
/// message.
|
440
|
+
#[no_mangle]
|
441
|
+
pub extern "C" fn tmprl_poll_workflow_activation(
|
442
|
+
worker: *mut tmprl_worker_t,
|
443
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
444
|
+
req_proto: *const u8,
|
445
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
446
|
+
req_proto_len: libc::size_t,
|
447
|
+
user_data: *mut libc::c_void,
|
448
|
+
callback: tmprl_callback,
|
449
|
+
) {
|
450
|
+
let worker = unsafe { &mut *worker };
|
451
|
+
let user_data = UserDataHandle(user_data);
|
452
|
+
worker.tokio_runtime.clone().spawn(async move {
|
453
|
+
let resp = bridge::PollWorkflowActivationResponse {
|
454
|
+
response: Some(match worker.poll_workflow_activation().await {
|
455
|
+
Ok(act) => bridge::poll_workflow_activation_response::Response::Activation(act),
|
456
|
+
Err(err) => bridge::poll_workflow_activation_response::Response::Error(err),
|
457
|
+
}),
|
458
|
+
};
|
459
|
+
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
460
|
+
});
|
461
|
+
}
|
462
|
+
|
463
|
+
/// Poll for an activity task.
|
464
|
+
///
|
465
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
466
|
+
/// [bridge::PollActivityTaskRequest] protobuf message, which currently contains nothing and is
|
467
|
+
/// unused, but the parameters are kept for now.
|
468
|
+
///
|
469
|
+
/// The callback is invoked on completion with a [bridge::PollActivityTaskResponse] protobuf
|
470
|
+
/// message.
|
471
|
+
#[no_mangle]
|
472
|
+
pub extern "C" fn tmprl_poll_activity_task(
|
473
|
+
worker: *mut tmprl_worker_t,
|
474
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
475
|
+
req_proto: *const u8,
|
476
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
477
|
+
req_proto_len: libc::size_t,
|
478
|
+
user_data: *mut libc::c_void,
|
479
|
+
callback: tmprl_callback,
|
480
|
+
) {
|
481
|
+
let worker = unsafe { &mut *worker };
|
482
|
+
let user_data = UserDataHandle(user_data);
|
483
|
+
worker.tokio_runtime.clone().spawn(async move {
|
484
|
+
let resp = bridge::PollActivityTaskResponse {
|
485
|
+
response: Some(match worker.poll_activity_task().await {
|
486
|
+
Ok(task) => bridge::poll_activity_task_response::Response::Task(task),
|
487
|
+
Err(err) => bridge::poll_activity_task_response::Response::Error(err),
|
488
|
+
}),
|
489
|
+
};
|
490
|
+
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
491
|
+
});
|
492
|
+
}
|
493
|
+
|
494
|
+
/// Complete a workflow activation.
|
495
|
+
///
|
496
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
497
|
+
/// [bridge::CompleteWorkflowActivationRequest] protobuf message. The callback is invoked on
|
498
|
+
/// completion with a [bridge::CompleteWorkflowActivationResponse] protobuf message.
|
499
|
+
#[no_mangle]
|
500
|
+
pub extern "C" fn tmprl_complete_workflow_activation(
|
501
|
+
worker: *mut tmprl_worker_t,
|
502
|
+
req_proto: *const u8,
|
503
|
+
req_proto_len: libc::size_t,
|
504
|
+
user_data: *mut libc::c_void,
|
505
|
+
callback: tmprl_callback,
|
506
|
+
) {
|
507
|
+
let worker = unsafe { &mut *worker };
|
508
|
+
let req = match tmprl_worker_t::decode_proto::<bridge::CompleteWorkflowActivationRequest>(
|
509
|
+
req_proto,
|
510
|
+
req_proto_len,
|
511
|
+
) {
|
512
|
+
Ok(req) => req,
|
513
|
+
Err(message) => {
|
514
|
+
let resp = bridge::CompleteWorkflowActivationResponse {
|
515
|
+
error: Some(bridge::complete_workflow_activation_response::Error { message }),
|
516
|
+
};
|
517
|
+
unsafe {
|
518
|
+
callback(user_data, worker.encode_proto(&resp).into_raw());
|
519
|
+
}
|
520
|
+
return;
|
521
|
+
}
|
522
|
+
};
|
523
|
+
let user_data = UserDataHandle(user_data);
|
524
|
+
worker.tokio_runtime.clone().spawn(async move {
|
525
|
+
match worker.complete_workflow_activation(req).await {
|
526
|
+
Ok(()) => unsafe {
|
527
|
+
callback(
|
528
|
+
user_data.into(),
|
529
|
+
&*DEFAULT_COMPLETE_WORKFLOW_ACTIVATION_RESPONSE_BYTES,
|
530
|
+
);
|
531
|
+
},
|
532
|
+
Err(err) => {
|
533
|
+
let resp = bridge::CompleteWorkflowActivationResponse { error: Some(err) };
|
534
|
+
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
535
|
+
}
|
536
|
+
}
|
537
|
+
});
|
538
|
+
}
|
539
|
+
|
540
|
+
/// Complete an activity task.
|
541
|
+
///
|
542
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
543
|
+
/// [bridge::CompleteActivityTaskRequest] protobuf message. The callback is invoked on completion
|
544
|
+
/// with a [bridge::CompleteActivityTaskResponse] protobuf message.
|
545
|
+
#[no_mangle]
|
546
|
+
pub extern "C" fn tmprl_complete_activity_task(
|
547
|
+
worker: *mut tmprl_worker_t,
|
548
|
+
req_proto: *const u8,
|
549
|
+
req_proto_len: libc::size_t,
|
550
|
+
user_data: *mut libc::c_void,
|
551
|
+
callback: tmprl_callback,
|
552
|
+
) {
|
553
|
+
let worker = unsafe { &mut *worker };
|
554
|
+
let req = match tmprl_worker_t::decode_proto::<bridge::CompleteActivityTaskRequest>(
|
555
|
+
req_proto,
|
556
|
+
req_proto_len,
|
557
|
+
) {
|
558
|
+
Ok(req) => req,
|
559
|
+
Err(message) => {
|
560
|
+
let resp = bridge::CompleteActivityTaskResponse {
|
561
|
+
error: Some(bridge::complete_activity_task_response::Error { message }),
|
562
|
+
};
|
563
|
+
unsafe {
|
564
|
+
callback(user_data, worker.encode_proto(&resp).into_raw());
|
565
|
+
}
|
566
|
+
return;
|
567
|
+
}
|
568
|
+
};
|
569
|
+
let user_data = UserDataHandle(user_data);
|
570
|
+
worker.tokio_runtime.clone().spawn(async move {
|
571
|
+
match worker.complete_activity_task(req).await {
|
572
|
+
Ok(()) => unsafe {
|
573
|
+
callback(
|
574
|
+
user_data.into(),
|
575
|
+
&*DEFAULT_COMPLETE_ACTIVITY_TASK_RESPONSE_BYTES,
|
576
|
+
);
|
577
|
+
},
|
578
|
+
Err(err) => {
|
579
|
+
let resp = bridge::CompleteActivityTaskResponse { error: Some(err) };
|
580
|
+
unsafe { callback(user_data.into(), worker.encode_proto(&resp).into_raw()) };
|
581
|
+
}
|
582
|
+
}
|
583
|
+
});
|
584
|
+
}
|
585
|
+
|
586
|
+
/// Record an activity heartbeat.
|
587
|
+
///
|
588
|
+
/// `req_proto` and `req_proto_len` represent a byte array for a
|
589
|
+
/// [bridge::RecordActivityHeartbeatRequest] protobuf message. The callback is invoked on completion
|
590
|
+
/// with a RecordActivityHeartbeatResponse protobuf message.
|
591
|
+
#[no_mangle]
|
592
|
+
pub extern "C" fn tmprl_record_activity_heartbeat(
|
593
|
+
worker: *mut tmprl_worker_t,
|
594
|
+
req_proto: *const u8,
|
595
|
+
req_proto_len: libc::size_t,
|
596
|
+
user_data: *mut libc::c_void,
|
597
|
+
callback: tmprl_callback,
|
598
|
+
) {
|
599
|
+
let worker = unsafe { &mut *worker };
|
600
|
+
let req = match tmprl_worker_t::decode_proto::<bridge::RecordActivityHeartbeatRequest>(
|
601
|
+
req_proto,
|
602
|
+
req_proto_len,
|
603
|
+
) {
|
604
|
+
Ok(req) => req,
|
605
|
+
Err(message) => {
|
606
|
+
let resp = bridge::RecordActivityHeartbeatResponse {
|
607
|
+
error: Some(bridge::record_activity_heartbeat_response::Error { message }),
|
608
|
+
};
|
609
|
+
unsafe {
|
610
|
+
callback(user_data, worker.encode_proto(&resp).into_raw());
|
611
|
+
}
|
612
|
+
return;
|
613
|
+
}
|
614
|
+
};
|
615
|
+
let user_data = UserDataHandle(user_data);
|
616
|
+
// We intentionally spawn even though the core call is not async so the
|
617
|
+
// callback can be made in the tokio runtime
|
618
|
+
worker.tokio_runtime.clone().spawn(async move {
|
619
|
+
worker.record_activity_heartbeat(req);
|
620
|
+
unsafe {
|
621
|
+
callback(
|
622
|
+
user_data.into(),
|
623
|
+
&*DEFAULT_RECORD_ACTIVITY_HEARTBEAT_RESPONSE_BYTES,
|
624
|
+
);
|
625
|
+
}
|
626
|
+
});
|
627
|
+
}
|
628
|
+
|
629
|
+
/// Request a workflow eviction.
|
630
|
+
///
|
631
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
632
|
+
/// [bridge::RequestWorkflowEvictionRequest] protobuf message. The callback is invoked on completion
|
633
|
+
/// with a [bridge::RequestWorkflowEvictionResponse] protobuf message.
|
634
|
+
#[no_mangle]
|
635
|
+
pub extern "C" fn tmprl_request_workflow_eviction(
|
636
|
+
worker: *mut tmprl_worker_t,
|
637
|
+
req_proto: *const u8,
|
638
|
+
req_proto_len: libc::size_t,
|
639
|
+
user_data: *mut libc::c_void,
|
640
|
+
callback: tmprl_callback,
|
641
|
+
) {
|
642
|
+
let worker = unsafe { &mut *worker };
|
643
|
+
let req = match tmprl_worker_t::decode_proto::<bridge::RequestWorkflowEvictionRequest>(
|
644
|
+
req_proto,
|
645
|
+
req_proto_len,
|
646
|
+
) {
|
647
|
+
Ok(req) => req,
|
648
|
+
Err(message) => {
|
649
|
+
let resp = bridge::RequestWorkflowEvictionResponse {
|
650
|
+
error: Some(bridge::request_workflow_eviction_response::Error { message }),
|
651
|
+
};
|
652
|
+
unsafe {
|
653
|
+
callback(user_data, worker.encode_proto(&resp).into_raw());
|
654
|
+
}
|
655
|
+
return;
|
656
|
+
}
|
657
|
+
};
|
658
|
+
let user_data = UserDataHandle(user_data);
|
659
|
+
// We intentionally spawn even though the core call is not async so the
|
660
|
+
// callback can be made in the tokio runtime
|
661
|
+
worker.tokio_runtime.clone().spawn(async move {
|
662
|
+
worker.request_workflow_eviction(req);
|
663
|
+
unsafe {
|
664
|
+
callback(
|
665
|
+
user_data.into(),
|
666
|
+
&*DEFAULT_REQUEST_WORKFLOW_EVICTION_RESPONSE_BYTES,
|
667
|
+
);
|
668
|
+
}
|
669
|
+
});
|
670
|
+
}
|
671
|
+
|
672
|
+
/// Fetch buffered logs. Blocks until complete. This is still using the callback since we might
|
673
|
+
/// reasonably change log fetching to be async in the future.
|
674
|
+
///
|
675
|
+
/// The `req_proto` and `req_proto_len` represent a byte array for a
|
676
|
+
/// [bridge::FetchBufferedLogsRequest] protobuf message. The callback is invoked on completion with
|
677
|
+
/// a [bridge::FetchBufferedLogsResponse] protobuf message.
|
678
|
+
#[no_mangle]
|
679
|
+
pub extern "C" fn tmprl_fetch_buffered_logs(
|
680
|
+
#[allow(unused_variables)] // We intentionally ignore the request
|
681
|
+
req_proto: *const u8,
|
682
|
+
#[allow(unused_variables)] req_proto_len: libc::size_t,
|
683
|
+
user_data: *mut libc::c_void,
|
684
|
+
callback: tmprl_callback,
|
685
|
+
) {
|
686
|
+
let user_data = UserDataHandle(user_data);
|
687
|
+
// We intentionally spawn even though the core call is not async so the
|
688
|
+
// callback can be made in the tokio runtime
|
689
|
+
let resp = bridge::FetchBufferedLogsResponse {
|
690
|
+
entries: fetch_global_buffered_logs()
|
691
|
+
.into_iter()
|
692
|
+
.map(|log| bridge::fetch_buffered_logs_response::LogEntry {
|
693
|
+
message: log.message,
|
694
|
+
timestamp: Some(log.timestamp.into()),
|
695
|
+
level: match log.level {
|
696
|
+
log::Level::Error => bridge::LogLevel::Error.into(),
|
697
|
+
log::Level::Warn => bridge::LogLevel::Warn.into(),
|
698
|
+
log::Level::Info => bridge::LogLevel::Info.into(),
|
699
|
+
log::Level::Debug => bridge::LogLevel::Debug.into(),
|
700
|
+
log::Level::Trace => bridge::LogLevel::Trace.into(),
|
701
|
+
},
|
702
|
+
})
|
703
|
+
.collect(),
|
704
|
+
};
|
705
|
+
|
706
|
+
unsafe {
|
707
|
+
callback(
|
708
|
+
user_data.into(),
|
709
|
+
// TODO: Creates vec every time since no worker/core instance. Can be fixed with a
|
710
|
+
// pool if optimizations needed.
|
711
|
+
tmprl_bytes_t::from_vec(resp.encode_to_vec()).into_raw(),
|
712
|
+
)
|
713
|
+
};
|
714
|
+
}
|
715
|
+
|
716
|
+
impl tmprl_worker_t {
|
717
|
+
fn new(
|
718
|
+
tokio_runtime: Arc<tokio::runtime::Runtime>,
|
719
|
+
client: Arc<RetryClient<Client>>,
|
720
|
+
opts: wrappers::WorkerConfig,
|
721
|
+
) -> Result<tmprl_worker_t, String> {
|
722
|
+
Ok(tmprl_worker_t {
|
723
|
+
tokio_runtime,
|
724
|
+
worker: Arc::new(temporal_sdk_core::init_worker(opts.try_into()?, client)),
|
725
|
+
})
|
726
|
+
}
|
727
|
+
|
728
|
+
async fn shutdown(&self) {
|
729
|
+
self.worker.shutdown().await;
|
730
|
+
}
|
731
|
+
|
732
|
+
async fn poll_workflow_activation(
|
733
|
+
&self,
|
734
|
+
) -> Result<
|
735
|
+
temporal_sdk_core_protos::coresdk::workflow_activation::WorkflowActivation,
|
736
|
+
bridge::poll_workflow_activation_response::Error,
|
737
|
+
> {
|
738
|
+
self.worker.poll_workflow_activation().await.map_err(|err| {
|
739
|
+
bridge::poll_workflow_activation_response::Error {
|
740
|
+
message: format!("{}", err),
|
741
|
+
shutdown: matches!(err, temporal_sdk_core_api::errors::PollWfError::ShutDown),
|
742
|
+
}
|
743
|
+
})
|
744
|
+
}
|
745
|
+
|
746
|
+
async fn poll_activity_task(
|
747
|
+
&self,
|
748
|
+
) -> Result<
|
749
|
+
temporal_sdk_core_protos::coresdk::activity_task::ActivityTask,
|
750
|
+
bridge::poll_activity_task_response::Error,
|
751
|
+
> {
|
752
|
+
self.worker.poll_activity_task().await.map_err(|err| {
|
753
|
+
bridge::poll_activity_task_response::Error {
|
754
|
+
message: format!("{}", err),
|
755
|
+
shutdown: matches!(
|
756
|
+
err,
|
757
|
+
temporal_sdk_core_api::errors::PollActivityError::ShutDown
|
758
|
+
),
|
759
|
+
}
|
760
|
+
})
|
761
|
+
}
|
762
|
+
|
763
|
+
async fn complete_workflow_activation(
|
764
|
+
&self,
|
765
|
+
req: bridge::CompleteWorkflowActivationRequest,
|
766
|
+
) -> Result<(), bridge::complete_workflow_activation_response::Error> {
|
767
|
+
self.worker
|
768
|
+
.complete_workflow_activation(req.completion.unwrap_or_default())
|
769
|
+
.await
|
770
|
+
.map_err(|err| bridge::complete_workflow_activation_response::Error {
|
771
|
+
message: format!("{}", err),
|
772
|
+
})
|
773
|
+
}
|
774
|
+
|
775
|
+
async fn complete_activity_task(
|
776
|
+
&self,
|
777
|
+
req: bridge::CompleteActivityTaskRequest,
|
778
|
+
) -> Result<(), bridge::complete_activity_task_response::Error> {
|
779
|
+
self.worker
|
780
|
+
.complete_activity_task(req.completion.unwrap_or_default())
|
781
|
+
.await
|
782
|
+
.map_err(|err| bridge::complete_activity_task_response::Error {
|
783
|
+
message: format!("{}", err),
|
784
|
+
})
|
785
|
+
}
|
786
|
+
|
787
|
+
fn record_activity_heartbeat(&self, req: bridge::RecordActivityHeartbeatRequest) {
|
788
|
+
self.worker
|
789
|
+
.record_activity_heartbeat(req.heartbeat.unwrap_or_default());
|
790
|
+
}
|
791
|
+
|
792
|
+
fn request_workflow_eviction(&self, req: bridge::RequestWorkflowEvictionRequest) {
|
793
|
+
self.worker.request_workflow_eviction(&req.run_id);
|
794
|
+
}
|
795
|
+
|
796
|
+
fn borrow_buf(&mut self) -> Vec<u8> {
|
797
|
+
// We currently do not use a thread-safe byte pool, but if wanted, it
|
798
|
+
// can be added here
|
799
|
+
Vec::new()
|
800
|
+
}
|
801
|
+
|
802
|
+
fn return_buf(&mut self, _vec: Vec<u8>) {
|
803
|
+
// We currently do not use a thread-safe byte pool, but if wanted, it
|
804
|
+
// can be added here
|
805
|
+
}
|
806
|
+
|
807
|
+
fn encode_proto(&mut self, proto: &impl prost::Message) -> tmprl_bytes_t {
|
808
|
+
let mut buf = self.borrow_buf();
|
809
|
+
buf.clear();
|
810
|
+
// Increase buf capacity if needed
|
811
|
+
buf.reserve(proto.encoded_len());
|
812
|
+
// Only fails if size not big enough which can't happen in our case
|
813
|
+
proto.encode(&mut buf).unwrap();
|
814
|
+
tmprl_bytes_t::from_vec(buf)
|
815
|
+
}
|
816
|
+
|
817
|
+
fn decode_proto<P>(bytes: *const u8, bytes_len: libc::size_t) -> Result<P, String>
|
818
|
+
where
|
819
|
+
P: prost::Message,
|
820
|
+
P: Default,
|
821
|
+
{
|
822
|
+
P::decode(unsafe { std::slice::from_raw_parts(bytes, bytes_len) })
|
823
|
+
.map_err(|err| format!("failed decoding proto: {}", err))
|
824
|
+
}
|
825
|
+
}
|