temporalio 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +180 -7
- data/bridge/Cargo.lock +208 -76
- data/bridge/Cargo.toml +5 -2
- data/bridge/sdk-core/Cargo.toml +1 -1
- data/bridge/sdk-core/README.md +20 -10
- data/bridge/sdk-core/client/Cargo.toml +1 -1
- data/bridge/sdk-core/client/src/lib.rs +227 -59
- data/bridge/sdk-core/client/src/metrics.rs +17 -8
- data/bridge/sdk-core/client/src/raw.rs +13 -12
- data/bridge/sdk-core/client/src/retry.rs +132 -43
- data/bridge/sdk-core/core/Cargo.toml +28 -15
- data/bridge/sdk-core/core/benches/workflow_replay.rs +13 -10
- data/bridge/sdk-core/core/src/abstractions.rs +225 -36
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +217 -79
- data/bridge/sdk-core/core/src/core_tests/determinism.rs +165 -2
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +565 -34
- data/bridge/sdk-core/core/src/core_tests/queries.rs +247 -90
- data/bridge/sdk-core/core/src/core_tests/workers.rs +3 -5
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +1 -1
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +430 -67
- data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +106 -12
- data/bridge/sdk-core/core/src/internal_flags.rs +136 -0
- data/bridge/sdk-core/core/src/lib.rs +148 -34
- data/bridge/sdk-core/core/src/protosext/mod.rs +1 -1
- data/bridge/sdk-core/core/src/replay/mod.rs +185 -41
- data/bridge/sdk-core/core/src/telemetry/log_export.rs +190 -0
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +219 -140
- data/bridge/sdk-core/core/src/telemetry/mod.rs +326 -315
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +20 -14
- data/bridge/sdk-core/core/src/test_help/mod.rs +85 -21
- data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +112 -156
- data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +364 -128
- data/bridge/sdk-core/core/src/worker/activities.rs +263 -170
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +23 -3
- data/bridge/sdk-core/core/src/worker/client.rs +48 -6
- data/bridge/sdk-core/core/src/worker/mod.rs +186 -75
- data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +13 -24
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +879 -226
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +101 -48
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +8 -12
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +90 -32
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -10
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +6 -9
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +160 -83
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +36 -54
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +179 -0
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +104 -157
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +8 -12
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +9 -13
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +10 -4
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +14 -11
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +395 -299
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +12 -20
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +33 -18
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +1032 -374
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +525 -392
- data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
- data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +125 -0
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -6
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +456 -681
- data/bridge/sdk-core/core-api/Cargo.toml +6 -4
- data/bridge/sdk-core/core-api/src/errors.rs +1 -34
- data/bridge/sdk-core/core-api/src/lib.rs +7 -45
- data/bridge/sdk-core/core-api/src/telemetry.rs +141 -0
- data/bridge/sdk-core/core-api/src/worker.rs +27 -1
- data/bridge/sdk-core/etc/deps.svg +115 -140
- data/bridge/sdk-core/etc/regen-depgraph.sh +5 -0
- data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +18 -15
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +8 -3
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
- data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -3
- data/bridge/sdk-core/protos/api_upstream/build/go.mod +7 -0
- data/bridge/sdk-core/protos/api_upstream/build/go.sum +5 -0
- data/bridge/sdk-core/protos/api_upstream/{temporal/api/enums/v1/cluster.proto → build/tools.go} +7 -18
- data/bridge/sdk-core/protos/api_upstream/go.mod +6 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +12 -9
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +15 -26
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +4 -9
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +10 -8
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +28 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +62 -26
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +24 -61
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -21
- data/bridge/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +110 -31
- data/bridge/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +4 -4
- data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
- data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +3 -2
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +111 -36
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +19 -5
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +1 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +9 -0
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +9 -1
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +6 -0
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
- data/bridge/sdk-core/sdk/Cargo.toml +4 -3
- data/bridge/sdk-core/sdk/src/interceptors.rs +36 -3
- data/bridge/sdk-core/sdk/src/lib.rs +94 -25
- data/bridge/sdk-core/sdk/src/workflow_context.rs +13 -2
- data/bridge/sdk-core/sdk/src/workflow_future.rs +10 -13
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +5 -2
- data/bridge/sdk-core/sdk-core-protos/build.rs +36 -2
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +164 -104
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +27 -23
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +252 -74
- data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
- data/bridge/sdk-core/test-utils/Cargo.toml +4 -1
- data/bridge/sdk-core/test-utils/src/canned_histories.rs +106 -296
- data/bridge/sdk-core/test-utils/src/histfetch.rs +1 -1
- data/bridge/sdk-core/test-utils/src/lib.rs +161 -50
- data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
- data/bridge/sdk-core/test-utils/src/workflows.rs +29 -0
- data/bridge/sdk-core/tests/fuzzy_workflow.rs +130 -0
- data/bridge/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
- data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +239 -0
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +4 -60
- data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
- data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +93 -69
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +151 -116
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +54 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +7 -28
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +115 -24
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -4
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +27 -18
- data/bridge/sdk-core/tests/main.rs +8 -16
- data/bridge/sdk-core/tests/runner.rs +75 -36
- data/bridge/sdk-core/tests/wf_input_replay.rs +32 -0
- data/bridge/src/connection.rs +117 -82
- data/bridge/src/lib.rs +356 -42
- data/bridge/src/runtime.rs +10 -3
- data/bridge/src/test_server.rs +153 -0
- data/bridge/src/worker.rs +133 -9
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +8 -6
- data/lib/gen/temporal/api/command/v1/message_pb.rb +10 -16
- data/lib/gen/temporal/api/common/v1/message_pb.rb +5 -1
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +3 -3
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +2 -1
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +5 -4
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +9 -1
- data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/query_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/reset_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +1 -1
- data/lib/gen/temporal/api/enums/v1/update_pb.rb +7 -10
- data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +1 -1
- data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/failure/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/filter/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/history/v1/message_pb.rb +34 -25
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +2 -1
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +14 -51
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/api/protocol/v1/message_pb.rb +30 -0
- data/lib/gen/temporal/api/query/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/replication/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/schedule/v1/message_pb.rb +22 -1
- data/lib/gen/temporal/api/sdk/v1/task_complete_metadata_pb.rb +23 -0
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +2 -2
- data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +49 -0
- data/lib/gen/temporal/api/testservice/v1/service_pb.rb +21 -0
- data/lib/gen/temporal/api/update/v1/message_pb.rb +49 -3
- data/lib/gen/temporal/api/version/v1/message_pb.rb +1 -1
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +2 -1
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +47 -20
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +1 -1
- data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +13 -9
- data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +10 -6
- data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +13 -9
- data/lib/gen/temporal/sdk/core/common/common_pb.rb +7 -3
- data/lib/gen/temporal/sdk/core/core_interface_pb.rb +9 -3
- data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +7 -3
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +28 -21
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +32 -24
- data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +12 -5
- data/lib/temporalio/activity/context.rb +102 -0
- data/lib/temporalio/activity/info.rb +67 -0
- data/lib/temporalio/activity.rb +85 -0
- data/lib/temporalio/bridge/connect_options.rb +15 -0
- data/lib/temporalio/bridge/error.rb +8 -0
- data/lib/temporalio/bridge/retry_config.rb +24 -0
- data/lib/temporalio/bridge/tls_options.rb +19 -0
- data/lib/temporalio/bridge.rb +14 -0
- data/lib/{temporal → temporalio}/client/implementation.rb +57 -56
- data/lib/{temporal → temporalio}/client/workflow_handle.rb +35 -35
- data/lib/{temporal → temporalio}/client.rb +19 -32
- data/lib/temporalio/connection/retry_config.rb +44 -0
- data/lib/temporalio/connection/service.rb +20 -0
- data/lib/temporalio/connection/test_service.rb +92 -0
- data/lib/temporalio/connection/tls_options.rb +51 -0
- data/lib/temporalio/connection/workflow_service.rb +731 -0
- data/lib/temporalio/connection.rb +86 -0
- data/lib/{temporal → temporalio}/data_converter.rb +76 -35
- data/lib/{temporal → temporalio}/error/failure.rb +6 -6
- data/lib/{temporal → temporalio}/error/workflow_failure.rb +4 -2
- data/lib/{temporal → temporalio}/errors.rb +19 -1
- data/lib/{temporal → temporalio}/failure_converter/base.rb +5 -5
- data/lib/{temporal → temporalio}/failure_converter/basic.rb +58 -52
- data/lib/temporalio/failure_converter.rb +7 -0
- data/lib/temporalio/interceptor/activity_inbound.rb +22 -0
- data/lib/temporalio/interceptor/activity_outbound.rb +24 -0
- data/lib/{temporal → temporalio}/interceptor/chain.rb +7 -6
- data/lib/{temporal → temporalio}/interceptor/client.rb +27 -2
- data/lib/temporalio/interceptor.rb +22 -0
- data/lib/{temporal → temporalio}/payload_codec/base.rb +5 -5
- data/lib/{temporal → temporalio}/payload_converter/base.rb +3 -3
- data/lib/{temporal → temporalio}/payload_converter/bytes.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/composite.rb +7 -5
- data/lib/{temporal → temporalio}/payload_converter/encoding_base.rb +4 -4
- data/lib/{temporal → temporalio}/payload_converter/json.rb +4 -3
- data/lib/{temporal → temporalio}/payload_converter/nil.rb +4 -3
- data/lib/temporalio/payload_converter.rb +14 -0
- data/lib/{temporal → temporalio}/retry_policy.rb +17 -7
- data/lib/{temporal → temporalio}/retry_state.rb +1 -1
- data/lib/temporalio/runtime.rb +25 -0
- data/lib/temporalio/testing/time_skipping_handle.rb +32 -0
- data/lib/temporalio/testing/time_skipping_interceptor.rb +23 -0
- data/lib/temporalio/testing/workflow_environment.rb +112 -0
- data/lib/temporalio/testing.rb +175 -0
- data/lib/{temporal → temporalio}/timeout_type.rb +2 -2
- data/lib/temporalio/version.rb +3 -0
- data/lib/temporalio/worker/activity_runner.rb +114 -0
- data/lib/temporalio/worker/activity_worker.rb +164 -0
- data/lib/temporalio/worker/reactor.rb +46 -0
- data/lib/temporalio/worker/runner.rb +63 -0
- data/lib/temporalio/worker/sync_worker.rb +124 -0
- data/lib/temporalio/worker/thread_pool_executor.rb +51 -0
- data/lib/temporalio/worker.rb +204 -0
- data/lib/temporalio/workflow/async.rb +46 -0
- data/lib/{temporal → temporalio}/workflow/execution_info.rb +4 -4
- data/lib/{temporal → temporalio}/workflow/execution_status.rb +1 -1
- data/lib/temporalio/workflow/future.rb +138 -0
- data/lib/{temporal → temporalio}/workflow/id_reuse_policy.rb +6 -6
- data/lib/temporalio/workflow/info.rb +76 -0
- data/lib/{temporal → temporalio}/workflow/query_reject_condition.rb +5 -5
- data/lib/temporalio.rb +12 -3
- data/temporalio.gemspec +11 -6
- metadata +137 -64
- data/bridge/sdk-core/Cargo.lock +0 -2606
- data/bridge/sdk-core/bridge-ffi/Cargo.toml +0 -24
- data/bridge/sdk-core/bridge-ffi/LICENSE.txt +0 -23
- data/bridge/sdk-core/bridge-ffi/build.rs +0 -25
- data/bridge/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -249
- data/bridge/sdk-core/bridge-ffi/src/lib.rs +0 -825
- data/bridge/sdk-core/bridge-ffi/src/wrappers.rs +0 -211
- data/bridge/sdk-core/core/src/log_export.rs +0 -62
- data/bridge/sdk-core/core/src/worker/workflow/machines/mutable_side_effect_state_machine.rs +0 -127
- data/bridge/sdk-core/core/src/worker/workflow/machines/side_effect_state_machine.rs +0 -71
- data/bridge/sdk-core/protos/api_upstream/temporal/api/cluster/v1/message.proto +0 -83
- data/bridge/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
- data/bridge/sdk-core/sdk/src/conversions.rs +0 -8
- data/lib/bridge.so +0 -0
- data/lib/gen/temporal/api/cluster/v1/message_pb.rb +0 -67
- data/lib/gen/temporal/api/enums/v1/cluster_pb.rb +0 -26
- data/lib/gen/temporal/sdk/core/bridge/bridge_pb.rb +0 -222
- data/lib/temporal/bridge.rb +0 -14
- data/lib/temporal/connection.rb +0 -736
- data/lib/temporal/failure_converter.rb +0 -8
- data/lib/temporal/payload_converter.rb +0 -14
- data/lib/temporal/runtime.rb +0 -22
- data/lib/temporal/version.rb +0 -3
- data/lib/temporal.rb +0 -8
@@ -0,0 +1,22 @@
|
|
1
|
+
module Temporalio
|
2
|
+
module Interceptor
|
3
|
+
# A mixin for implementing inbound Activity interceptors.
|
4
|
+
module ActivityInbound
|
5
|
+
class ExecuteActivityInput < Struct.new(
|
6
|
+
:activity,
|
7
|
+
:args,
|
8
|
+
:headers,
|
9
|
+
keyword_init: true,
|
10
|
+
); end
|
11
|
+
|
12
|
+
# Interceptor for {Temporalio::Activity#execute}.
|
13
|
+
#
|
14
|
+
# @param input [ExecuteActivityInput]
|
15
|
+
#
|
16
|
+
# @return [any] Activity execution result
|
17
|
+
def execute_activity(input)
|
18
|
+
yield(input)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Temporalio
|
2
|
+
module Interceptor
|
3
|
+
# A mixin for implementing outbound Activity interceptors.
|
4
|
+
module ActivityOutbound
|
5
|
+
# Interceptor for {Temporalio::Activity::Context#info}.
|
6
|
+
#
|
7
|
+
# @yieldreturn Temporalio::Activity::Info
|
8
|
+
#
|
9
|
+
# @return [Temporalio::Activity::Info]
|
10
|
+
def activity_info
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
|
14
|
+
# Interceptor for {Temporalio::Activity::Context#heartbeat}.
|
15
|
+
#
|
16
|
+
# @yieldparam Array[untyped]
|
17
|
+
#
|
18
|
+
# @param details [any] A list of details supplied with the heartbeat.
|
19
|
+
def heartbeat(*details)
|
20
|
+
yield(*details)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,22 +1,23 @@
|
|
1
|
-
module
|
1
|
+
module Temporalio
|
2
2
|
module Interceptor
|
3
|
+
# @api private
|
3
4
|
class Chain
|
4
5
|
def initialize(interceptors = [])
|
5
6
|
@interceptors = interceptors
|
6
7
|
end
|
7
8
|
|
8
|
-
def invoke(method, input)
|
9
|
+
def invoke(method, *input)
|
9
10
|
chain = interceptors.dup
|
10
11
|
|
11
|
-
traverse_chain = lambda do
|
12
|
+
traverse_chain = lambda do |*i|
|
12
13
|
if chain.empty?
|
13
|
-
yield(i)
|
14
|
+
yield(*i)
|
14
15
|
else
|
15
|
-
chain.shift.public_send(method, i, &traverse_chain)
|
16
|
+
chain.shift.public_send(method, *i, &traverse_chain)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
traverse_chain.call(input)
|
20
|
+
traverse_chain.call(*input)
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -1,6 +1,7 @@
|
|
1
|
-
module
|
1
|
+
module Temporalio
|
2
2
|
module Interceptor
|
3
|
-
|
3
|
+
# A mixin for implementing Client side interceptors.
|
4
|
+
module Client
|
4
5
|
class StartWorkflowInput < Struct.new(
|
5
6
|
:workflow,
|
6
7
|
:args,
|
@@ -74,26 +75,50 @@ module Temporal
|
|
74
75
|
keyword_init: true,
|
75
76
|
); end
|
76
77
|
|
78
|
+
# Interceptor for {Temporalio::Client#start_workflow}.
|
79
|
+
#
|
80
|
+
# @param input [StartWorkflowInput]
|
81
|
+
#
|
82
|
+
# @return [Temporalio::Client::WorkflowHandle] A handle to interact with the workflow.
|
77
83
|
def start_workflow(input)
|
78
84
|
yield(input)
|
79
85
|
end
|
80
86
|
|
87
|
+
# Interceptor for {Temporalio::Client::WorkflowHandle#describe}.
|
88
|
+
#
|
89
|
+
# @param input [DescribeWorkflowInput]
|
90
|
+
#
|
91
|
+
# @return [Temporalio::Workflow::ExecutionInfo] Information about the workflow.
|
81
92
|
def describe_workflow(input)
|
82
93
|
yield(input)
|
83
94
|
end
|
84
95
|
|
96
|
+
# Interceptor for {Temporalio::Client::WorkflowHandle#query}.
|
97
|
+
#
|
98
|
+
# @param input [QueryWorkflowInput]
|
99
|
+
#
|
100
|
+
# @return [any] Query result
|
85
101
|
def query_workflow(input)
|
86
102
|
yield(input)
|
87
103
|
end
|
88
104
|
|
105
|
+
# Interceptor for {Temporalio::Client::WorkflowHandle#signal}.
|
106
|
+
#
|
107
|
+
# @param input [SignalWorkflowInput]
|
89
108
|
def signal_workflow(input)
|
90
109
|
yield(input)
|
91
110
|
end
|
92
111
|
|
112
|
+
# Interceptor for {Temporalio::Client::WorkflowHandle#cancel}.
|
113
|
+
#
|
114
|
+
# @param input [CancelWorkflowInput]
|
93
115
|
def cancel_workflow(input)
|
94
116
|
yield(input)
|
95
117
|
end
|
96
118
|
|
119
|
+
# Interceptor for {Temporalio::Client::WorkflowHandle#terminate}.
|
120
|
+
#
|
121
|
+
# @param input [TerminateWorkflowInput]
|
97
122
|
def terminate_workflow(input)
|
98
123
|
yield(input)
|
99
124
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'temporalio/interceptor/activity_inbound'
|
2
|
+
require 'temporalio/interceptor/activity_outbound'
|
3
|
+
|
4
|
+
module Temporalio
|
5
|
+
module Interceptor
|
6
|
+
# NOTE: Using #each_with_object here and below instead of a simple #select because RBS can't
|
7
|
+
# reconcile that resulting array only has WorkflowInbound or WorkflowOutbound in it.
|
8
|
+
def self.filter(interceptors, type)
|
9
|
+
interceptor_class =
|
10
|
+
case type
|
11
|
+
when :activity_inbound
|
12
|
+
Temporalio::Interceptor::ActivityInbound
|
13
|
+
when :activity_outbound
|
14
|
+
Temporalio::Interceptor::ActivityOutbound
|
15
|
+
end
|
16
|
+
|
17
|
+
interceptors.each_with_object([]) do |i, result|
|
18
|
+
result << i if i.is_a?(interceptor_class)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Temporalio
|
2
2
|
module PayloadCodec
|
3
3
|
# @abstract Use this Interface for implementing your payload codecs.
|
4
4
|
#
|
@@ -6,10 +6,10 @@ module Temporal
|
|
6
6
|
class Base
|
7
7
|
# Encode the given payloads.
|
8
8
|
#
|
9
|
-
# @param _payloads [Array<
|
9
|
+
# @param _payloads [Array<Temporalio::Api::Common::V1::Payload>] Payloads to encode.
|
10
10
|
# This value should not be mutated.
|
11
11
|
#
|
12
|
-
# @return [Array<
|
12
|
+
# @return [Array<Temporalio::Api::Common::V1::Payload>] Encoded payloads. Note, this does not
|
13
13
|
# have to be the same number as payloads given, but must be at least one and cannot be more
|
14
14
|
# than was given.
|
15
15
|
def encode(_payloads)
|
@@ -18,10 +18,10 @@ module Temporal
|
|
18
18
|
|
19
19
|
# Decode the given payloads.
|
20
20
|
#
|
21
|
-
# @param _payloads [Array<
|
21
|
+
# @param _payloads [Array<Temporalio::Api::Common::V1::Payload>] Payloads to decode. This value
|
22
22
|
# should not be mutated.
|
23
23
|
#
|
24
|
-
# @return [Array<
|
24
|
+
# @return [Array<Temporalio::Api::Common::V1::Payload>] Decoded payloads. Note, this does not
|
25
25
|
# have to be the same number as payloads given, but must be at least one and cannot be more
|
26
26
|
# than was given.
|
27
27
|
def decode(_payloads)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Temporalio
|
2
2
|
module PayloadConverter
|
3
3
|
# @abstract Use this Interface for implementing your payload converter.
|
4
4
|
class Base
|
@@ -6,14 +6,14 @@ module Temporal
|
|
6
6
|
#
|
7
7
|
# @param _data [any] Ruby value to be converted.
|
8
8
|
#
|
9
|
-
# @return [
|
9
|
+
# @return [Temporalio::Api::Common::V1::Payload]
|
10
10
|
def to_payload(_data)
|
11
11
|
raise NoMethodError, 'must implement #to_payload'
|
12
12
|
end
|
13
13
|
|
14
14
|
# Convert a proto Payload to a Ruby value.
|
15
15
|
#
|
16
|
-
# @param _payload [
|
16
|
+
# @param _payload [Temporalio::Api::Common::V1::Payload] Proto Payload to be converted.
|
17
17
|
#
|
18
18
|
# @return [any]
|
19
19
|
def from_payload(_payload)
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'temporalio/payload_converter/encoding_base'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Temporalio
|
4
4
|
module PayloadConverter
|
5
|
+
# A payload converter for encoding/decoding byte strings.
|
5
6
|
class Bytes < EncodingBase
|
6
7
|
ENCODING = 'binary/plain'.freeze
|
7
8
|
|
@@ -16,7 +17,7 @@ module Temporal
|
|
16
17
|
def to_payload(data)
|
17
18
|
return nil unless data.is_a?(String) && data.encoding == Encoding::ASCII_8BIT
|
18
19
|
|
19
|
-
|
20
|
+
Temporalio::Api::Common::V1::Payload.new(
|
20
21
|
metadata: { 'encoding' => ENCODING },
|
21
22
|
data: data,
|
22
23
|
)
|
@@ -1,12 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'temporalio/payload_converter/base'
|
2
|
+
require 'temporalio/errors'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Temporalio
|
5
5
|
module PayloadConverter
|
6
|
+
# A payload converter for combining multiple payload converters together.
|
6
7
|
class Composite < Base
|
7
|
-
class ConverterNotFound <
|
8
|
-
class EncodingNotSet <
|
8
|
+
class ConverterNotFound < Temporalio::Error; end
|
9
|
+
class EncodingNotSet < Temporalio::Error; end
|
9
10
|
|
11
|
+
# @param converters [Array<Temporalio::PayloadConverter::Base>] List of converters
|
10
12
|
def initialize(*converters)
|
11
13
|
super()
|
12
14
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'temporal/api/common/v1/message_pb'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Temporalio
|
4
4
|
module PayloadConverter
|
5
5
|
# @abstract Use this Interface for implementing an encoding payload converter.
|
6
|
-
# This is used as a converter for the {
|
6
|
+
# This is used as a converter for the {Temporalio::PayloadConverter::Composite}.
|
7
7
|
class EncodingBase
|
8
8
|
# A mime-type for the converter's encoding.
|
9
9
|
#
|
@@ -16,7 +16,7 @@ module Temporal
|
|
16
16
|
#
|
17
17
|
# @param _data [any] Ruby value to be converted.
|
18
18
|
#
|
19
|
-
# @return [
|
19
|
+
# @return [Temporalio::Api::Common::V1::Payload, nil] Return `nil` if the received value is not
|
20
20
|
# supported by this converter.
|
21
21
|
def to_payload(_data)
|
22
22
|
raise NoMethodError, 'must implement #to_payload'
|
@@ -24,7 +24,7 @@ module Temporal
|
|
24
24
|
|
25
25
|
# Convert a proto Payload to a Ruby value.
|
26
26
|
#
|
27
|
-
# @param _payload [
|
27
|
+
# @param _payload [Temporalio::Api::Common::V1::Payload] Proto Payload to be converted.
|
28
28
|
#
|
29
29
|
# @return [any]
|
30
30
|
def from_payload(_payload)
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'json/ext'
|
2
|
-
require '
|
2
|
+
require 'temporalio/payload_converter/encoding_base'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Temporalio
|
5
5
|
module PayloadConverter
|
6
|
+
# A payload converter for encoding/decoding JSON data.
|
6
7
|
class JSON < EncodingBase
|
7
8
|
ENCODING = 'json/plain'.freeze
|
8
9
|
|
@@ -15,7 +16,7 @@ module Temporal
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def to_payload(data)
|
18
|
-
|
19
|
+
Temporalio::Api::Common::V1::Payload.new(
|
19
20
|
metadata: { 'encoding' => ENCODING },
|
20
21
|
data: ::JSON.generate(data).b,
|
21
22
|
)
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'temporalio/payload_converter/encoding_base'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Temporalio
|
4
4
|
module PayloadConverter
|
5
|
+
# A payload converter for encoding/decoding nils.
|
5
6
|
class Nil < EncodingBase
|
6
7
|
ENCODING = 'binary/null'.freeze
|
7
8
|
|
@@ -16,7 +17,7 @@ module Temporal
|
|
16
17
|
def to_payload(data)
|
17
18
|
return nil unless data.nil?
|
18
19
|
|
19
|
-
|
20
|
+
Temporalio::Api::Common::V1::Payload.new(
|
20
21
|
metadata: { 'encoding' => ENCODING },
|
21
22
|
)
|
22
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'temporalio/payload_converter/bytes'
|
2
|
+
require 'temporalio/payload_converter/composite'
|
3
|
+
require 'temporalio/payload_converter/json'
|
4
|
+
require 'temporalio/payload_converter/nil'
|
5
|
+
|
6
|
+
module Temporalio
|
7
|
+
module PayloadConverter
|
8
|
+
DEFAULT = Temporalio::PayloadConverter::Composite.new(
|
9
|
+
Temporalio::PayloadConverter::Nil.new,
|
10
|
+
Temporalio::PayloadConverter::Bytes.new,
|
11
|
+
Temporalio::PayloadConverter::JSON.new,
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'temporal/api/common/v1/message_pb'
|
2
|
-
require '
|
2
|
+
require 'temporalio/errors'
|
3
3
|
|
4
|
-
module
|
4
|
+
module Temporalio
|
5
5
|
# Options for retrying workflows and activities.
|
6
6
|
#
|
7
7
|
# @see https://docs.temporal.io/application-development/features/#workflow-retry-policy
|
8
8
|
class RetryPolicy
|
9
|
-
class Invalid <
|
9
|
+
class Invalid < Temporalio::Error; end
|
10
10
|
|
11
11
|
# @return [Integer] Backoff interval for the first retry.
|
12
12
|
attr_reader :initial_interval
|
@@ -24,13 +24,23 @@ module Temporal
|
|
24
24
|
# @return [Array<String>] List of error types that are not retryable.
|
25
25
|
attr_reader :non_retriable_errors
|
26
26
|
|
27
|
+
def self.from_proto(proto)
|
28
|
+
new(
|
29
|
+
initial_interval: proto.initial_interval&.to_f&.round || 0,
|
30
|
+
backoff: proto.backoff_coefficient&.to_f || 0.0,
|
31
|
+
max_interval: proto.maximum_interval&.to_f&.round || 0,
|
32
|
+
max_attempts: proto.maximum_attempts || 1,
|
33
|
+
non_retriable_errors: proto.non_retryable_error_types || [],
|
34
|
+
).freeze
|
35
|
+
end
|
36
|
+
|
27
37
|
# @param initial_interval [Integer] Backoff interval (in seconds) for the first retry.
|
28
38
|
# @param backoff [Float] Coefficient to multiply previous backoff interval by to get new
|
29
39
|
# interval.
|
30
40
|
# @param max_interval [Integer] Maximum backoff interval between retries. Default 100x
|
31
41
|
# {#initial_interval}.
|
32
42
|
# @param max_attempts [Integer] Maximum number of attempts. If 0, there is no maximum.
|
33
|
-
# @param non_retriable_errors [Array<String>] List of error types that are not retryable.
|
43
|
+
# @param non_retriable_errors [Array<Class, String>] List of error types that are not retryable.
|
34
44
|
def initialize(
|
35
45
|
initial_interval: 1,
|
36
46
|
backoff: 2.0,
|
@@ -42,7 +52,7 @@ module Temporal
|
|
42
52
|
@backoff = backoff
|
43
53
|
@max_interval = max_interval
|
44
54
|
@max_attempts = max_attempts
|
45
|
-
@non_retriable_errors = non_retriable_errors
|
55
|
+
@non_retriable_errors = non_retriable_errors.map(&:to_s).compact
|
46
56
|
end
|
47
57
|
|
48
58
|
def validate!
|
@@ -70,12 +80,12 @@ module Temporal
|
|
70
80
|
end
|
71
81
|
|
72
82
|
def to_proto
|
73
|
-
|
83
|
+
Temporalio::Api::Common::V1::RetryPolicy.new(
|
74
84
|
initial_interval: Google::Protobuf::Duration.new(seconds: initial_interval),
|
75
85
|
backoff_coefficient: backoff,
|
76
86
|
maximum_interval: max_interval ? Google::Protobuf::Duration.new(seconds: max_interval) : nil,
|
77
87
|
maximum_attempts: max_attempts,
|
78
|
-
non_retryable_error_types: non_retriable_errors
|
88
|
+
non_retryable_error_types: non_retriable_errors,
|
79
89
|
)
|
80
90
|
end
|
81
91
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'temporalio/bridge'
|
3
|
+
require 'temporalio/worker/reactor'
|
4
|
+
|
5
|
+
module Temporalio
|
6
|
+
# @api private
|
7
|
+
class Runtime
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_reader :core_runtime, :reactor
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@core_runtime = Temporalio::Bridge::Runtime.init
|
14
|
+
@reactor = Temporalio::Worker::Reactor.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def ensure_callback_loop
|
18
|
+
return if @thread
|
19
|
+
|
20
|
+
@thread = Thread.new do
|
21
|
+
core_runtime.run_callback_loop
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
module Testing
|
5
|
+
class TimeSkippingHandle
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
# Proxy all the WorkflowHandle calls to the original handle except for :result
|
9
|
+
def_delegators :handle, :id, :run_id, :result_run_id, :first_execution_run_id, :describe,
|
10
|
+
:cancel, :query, :signal, :terminate
|
11
|
+
|
12
|
+
def initialize(handle, env)
|
13
|
+
@handle = handle
|
14
|
+
@env = env
|
15
|
+
end
|
16
|
+
|
17
|
+
def result(follow_runs: true, rpc_metadata: {}, rpc_timeout: nil)
|
18
|
+
env.with_time_skipping do
|
19
|
+
handle.result(
|
20
|
+
follow_runs: follow_runs,
|
21
|
+
rpc_metadata: rpc_metadata,
|
22
|
+
rpc_timeout: rpc_timeout,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :handle, :env
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'temporalio/interceptor/client'
|
2
|
+
require 'temporalio/testing/time_skipping_handle'
|
3
|
+
|
4
|
+
module Temporalio
|
5
|
+
module Testing
|
6
|
+
class TimeSkippingInterceptor
|
7
|
+
include Temporalio::Interceptor::Client
|
8
|
+
|
9
|
+
def initialize(env)
|
10
|
+
@env = env
|
11
|
+
end
|
12
|
+
|
13
|
+
def start_workflow(input)
|
14
|
+
handle = yield(input)
|
15
|
+
Temporalio::Testing::TimeSkippingHandle.new(handle, env)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :env
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'google/protobuf/well_known_types'
|
2
|
+
require 'temporalio/client'
|
3
|
+
require 'temporalio/testing/time_skipping_interceptor'
|
4
|
+
|
5
|
+
module Temporalio
|
6
|
+
module Testing
|
7
|
+
# Workflow environment for testing workflows.
|
8
|
+
#
|
9
|
+
# Most developers will want to use the {Temporalio::Testing.start_time_skipping_environment} to
|
10
|
+
# start a test server process that automatically skips time as needed. Alternatively,
|
11
|
+
# {Temporalio::Testing.start_local_environment} may be used for a full, local Temporal server
|
12
|
+
# with more features.
|
13
|
+
#
|
14
|
+
# @note Unless using the above mentioned methods with an explicit block, you will need to call
|
15
|
+
# {#shutdown} after you're finished with this environment.
|
16
|
+
class WorkflowEnvironment
|
17
|
+
# @return [Temporalio::Connection] A connection to this environment.
|
18
|
+
attr_reader :connection
|
19
|
+
|
20
|
+
# @return [String] A namespace for this environment.
|
21
|
+
attr_reader :namespace
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
def initialize(server, connection, namespace)
|
25
|
+
@server = server
|
26
|
+
@connection = connection
|
27
|
+
@namespace = namespace
|
28
|
+
end
|
29
|
+
|
30
|
+
# A default client to be used with this environment.
|
31
|
+
#
|
32
|
+
# @return [Temporalio::Client] A default client.
|
33
|
+
def client
|
34
|
+
@client ||= begin
|
35
|
+
# TODO: Add a workflow interceptor for interpreting assertion error
|
36
|
+
interceptors = [TimeSkippingInterceptor.new(self)]
|
37
|
+
Temporalio::Client.new(connection, namespace, interceptors: interceptors)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Sleep in this environment.
|
42
|
+
#
|
43
|
+
# This awaits a regular {Kernel.sleep} in regular environments, or manually skips time in
|
44
|
+
# time-skipping environments.
|
45
|
+
#
|
46
|
+
# @param duration [Integer] Amount of time to sleep.
|
47
|
+
def sleep(duration)
|
48
|
+
return Kernel.sleep(duration) unless supports_time_skipping?
|
49
|
+
|
50
|
+
request = Temporalio::Api::TestService::V1::SleepRequest.new(
|
51
|
+
duration: Google::Protobuf::Duration.new(seconds: duration),
|
52
|
+
)
|
53
|
+
connection.test_service.unlock_time_skipping_with_sleep(request)
|
54
|
+
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get the current time known to this environment.
|
59
|
+
#
|
60
|
+
# For non-time-skipping environments this is simply the system time. For time-skipping
|
61
|
+
# environments this is whatever time has been skipped to.
|
62
|
+
#
|
63
|
+
# @return [Time]
|
64
|
+
def current_time
|
65
|
+
return Time.now unless supports_time_skipping?
|
66
|
+
|
67
|
+
connection.test_service.get_current_time&.time&.to_time
|
68
|
+
end
|
69
|
+
|
70
|
+
# Whether this environment supports time skipping.
|
71
|
+
#
|
72
|
+
# @return [Boolean]
|
73
|
+
def supports_time_skipping?
|
74
|
+
server.has_test_service?
|
75
|
+
end
|
76
|
+
|
77
|
+
# Shut down this environment.
|
78
|
+
def shutdown
|
79
|
+
server.shutdown
|
80
|
+
end
|
81
|
+
|
82
|
+
# Unlock time skipping.
|
83
|
+
#
|
84
|
+
# This will have no effect in an environment that does not support time-skipping (e.g.
|
85
|
+
# Temporalite).
|
86
|
+
#
|
87
|
+
# @yield A block to be called once time skipping has been unlocked.
|
88
|
+
#
|
89
|
+
# @return [any] The return value of the block.
|
90
|
+
def with_time_skipping
|
91
|
+
return yield unless supports_time_skipping?
|
92
|
+
|
93
|
+
begin
|
94
|
+
# Unlock to start time skipping, lock again to stop it
|
95
|
+
connection.test_service.unlock_time_skipping(
|
96
|
+
Temporalio::Api::TestService::V1::UnlockTimeSkippingRequest.new,
|
97
|
+
)
|
98
|
+
|
99
|
+
yield
|
100
|
+
ensure
|
101
|
+
connection.test_service.lock_time_skipping(
|
102
|
+
Temporalio::Api::TestService::V1::LockTimeSkippingRequest.new,
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
attr_reader :server
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|