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,124 @@
|
|
1
|
+
require 'temporal/sdk/core/activity_task/activity_task_pb'
|
2
|
+
require 'temporal/sdk/core/core_interface_pb'
|
3
|
+
require 'temporal/sdk/core/workflow_activation/workflow_activation_pb'
|
4
|
+
require 'temporal/sdk/core/workflow_completion/workflow_completion_pb'
|
5
|
+
|
6
|
+
module Temporalio
|
7
|
+
class Worker
|
8
|
+
# This is a wrapper class for the Core Worker (provided via the Bridge) to abstract
|
9
|
+
# away its async nature allowing other modules/classes to interact with it without
|
10
|
+
# any callbacks (simplifying the code).
|
11
|
+
#
|
12
|
+
# CAUTION: This class will block the thread its running in unless it is used from
|
13
|
+
# within an Async reactor.
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
class SyncWorker
|
17
|
+
def initialize(core_worker)
|
18
|
+
@core_worker = core_worker
|
19
|
+
end
|
20
|
+
|
21
|
+
def poll_activity_task
|
22
|
+
with_queue do |done|
|
23
|
+
core_worker.poll_activity_task do |task, error|
|
24
|
+
done.call(task && Temporalio::Bridge::Api::ActivityTask::ActivityTask.decode(task), error)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def complete_activity_task_with_success(task_token, payload)
|
30
|
+
result = Temporalio::Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
31
|
+
completed: Temporalio::Bridge::Api::ActivityResult::Success.new(result: payload),
|
32
|
+
)
|
33
|
+
|
34
|
+
complete_activity_task(task_token, result)
|
35
|
+
end
|
36
|
+
|
37
|
+
def complete_activity_task_with_failure(task_token, failure)
|
38
|
+
result = Temporalio::Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
39
|
+
failed: Temporalio::Bridge::Api::ActivityResult::Failure.new(failure: failure),
|
40
|
+
)
|
41
|
+
|
42
|
+
complete_activity_task(task_token, result)
|
43
|
+
end
|
44
|
+
|
45
|
+
def complete_activity_task_with_cancellation(task_token, failure)
|
46
|
+
result = Temporalio::Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
47
|
+
cancelled: Temporalio::Bridge::Api::ActivityResult::Cancellation.new(failure: failure),
|
48
|
+
)
|
49
|
+
|
50
|
+
complete_activity_task(task_token, result)
|
51
|
+
end
|
52
|
+
|
53
|
+
def record_activity_heartbeat(task_token, payloads)
|
54
|
+
proto = Temporalio::Bridge::Api::CoreInterface::ActivityHeartbeat.new(
|
55
|
+
task_token: task_token,
|
56
|
+
details: payloads,
|
57
|
+
)
|
58
|
+
encoded_proto = Temporalio::Bridge::Api::CoreInterface::ActivityHeartbeat.encode(proto)
|
59
|
+
|
60
|
+
core_worker.record_activity_heartbeat(encoded_proto)
|
61
|
+
end
|
62
|
+
|
63
|
+
def poll_workflow_activation
|
64
|
+
with_queue do |done|
|
65
|
+
core_worker.poll_workflow_activation do |task, error|
|
66
|
+
done.call(task && Temporalio::Bridge::Api::WorkflowActivation::WorkflowActivation.decode(task), error)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def complete_workflow_activation_with_success(run_id, commands)
|
72
|
+
proto = Temporalio::Bridge::Api::WorkflowCompletion::WorkflowActivationCompletion.new(
|
73
|
+
run_id: run_id,
|
74
|
+
successful: Temporalio::Bridge::Api::WorkflowCompletion::Success.new(commands: commands),
|
75
|
+
)
|
76
|
+
|
77
|
+
complete_workflow_activation(proto)
|
78
|
+
end
|
79
|
+
|
80
|
+
def complete_workflow_activation_with_failure(run_id, failure)
|
81
|
+
proto = Temporalio::Bridge::Api::WorkflowCompletion::WorkflowActivationCompletion.new(
|
82
|
+
run_id: run_id,
|
83
|
+
failed: Temporalio::Bridge::Api::WorkflowCompletion::Failure.new(failure: failure),
|
84
|
+
)
|
85
|
+
|
86
|
+
complete_workflow_activation(proto)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
attr_reader :core_worker
|
92
|
+
|
93
|
+
def with_queue(&block)
|
94
|
+
queue = Queue.new
|
95
|
+
done = ->(result, error = nil) { queue << [result, error] }
|
96
|
+
block.call(done)
|
97
|
+
(result, exception) = queue.pop
|
98
|
+
raise exception if exception
|
99
|
+
|
100
|
+
result
|
101
|
+
end
|
102
|
+
|
103
|
+
def complete_activity_task(task_token, result)
|
104
|
+
proto = Temporalio::Bridge::Api::CoreInterface::ActivityTaskCompletion.new(
|
105
|
+
task_token: task_token,
|
106
|
+
result: result,
|
107
|
+
)
|
108
|
+
encoded_proto = Temporalio::Bridge::Api::CoreInterface::ActivityTaskCompletion.encode(proto)
|
109
|
+
|
110
|
+
with_queue do |done|
|
111
|
+
core_worker.complete_activity_task(encoded_proto, &done)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def complete_workflow_activation(proto)
|
116
|
+
encoded_proto = Temporalio::Bridge::Api::WorkflowCompletion::WorkflowActivationCompletion.encode(proto)
|
117
|
+
|
118
|
+
with_queue do |done|
|
119
|
+
core_worker.complete_workflow_activation(encoded_proto, &done)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Temporalio
|
2
|
+
class Worker
|
3
|
+
# A generic fixed thread pool.
|
4
|
+
#
|
5
|
+
# This is used to execute multiple activities concurrently and independenty of each other.
|
6
|
+
#
|
7
|
+
# @note This is a fixed thread pool that allocated threads eagerly and has an infinite buffer.
|
8
|
+
class ThreadPoolExecutor
|
9
|
+
# Generate new thread pool executor.
|
10
|
+
#
|
11
|
+
# @param size [Integer] Number of concurrently executing threads.
|
12
|
+
def initialize(size)
|
13
|
+
@queue = Queue.new
|
14
|
+
@pool = Array.new(size) do
|
15
|
+
Thread.new { poll }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Execute a block of code inside of the threads.
|
20
|
+
#
|
21
|
+
# @yield Block of code to be executed.
|
22
|
+
def schedule(&block)
|
23
|
+
queue << block
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stop the thread pool and wait for all threads to finish work.
|
27
|
+
def shutdown
|
28
|
+
pool.size.times do
|
29
|
+
schedule { throw EXIT_SYMBOL }
|
30
|
+
end
|
31
|
+
|
32
|
+
pool.each(&:join)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :queue, :pool
|
38
|
+
|
39
|
+
EXIT_SYMBOL = :exit
|
40
|
+
|
41
|
+
def poll
|
42
|
+
catch(EXIT_SYMBOL) do
|
43
|
+
loop do
|
44
|
+
job = queue.pop
|
45
|
+
job.call
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'async'
|
2
|
+
require 'temporalio/bridge'
|
3
|
+
require 'temporalio/data_converter'
|
4
|
+
require 'temporalio/runtime'
|
5
|
+
require 'temporalio/worker/activity_worker'
|
6
|
+
require 'temporalio/worker/runner'
|
7
|
+
require 'temporalio/worker/sync_worker'
|
8
|
+
require 'temporalio/worker/thread_pool_executor'
|
9
|
+
|
10
|
+
module Temporalio
|
11
|
+
# Worker to process activities.
|
12
|
+
#
|
13
|
+
# Once created, workers can be run and shutdown explicitly via {#run} and {#shutdown}.
|
14
|
+
class Worker
|
15
|
+
# Run multiple workers and wait for them to be shut down.
|
16
|
+
#
|
17
|
+
# This will not return until shutdown is complete (and all running activities in all workers
|
18
|
+
# finished) and will raise if any of the workers raises a fatal error.
|
19
|
+
#
|
20
|
+
# @param workers [Array<Temporalio::Worker>] A list of the workers to be run.
|
21
|
+
# @param shutdown_signals [Array<String>] A list of process signals for the worker to stop on.
|
22
|
+
# This argument can not be used with a custom block.
|
23
|
+
#
|
24
|
+
# @yield Optionally you can provide a block by the end of which all the workers will be shut
|
25
|
+
# down. Any errors raised from this block will be re-raised by this method.
|
26
|
+
def self.run(*workers, shutdown_signals: [], &block)
|
27
|
+
unless shutdown_signals.empty?
|
28
|
+
if block
|
29
|
+
raise ArgumentError, 'Temporalio::Worker.run accepts :shutdown_signals or a block, but not both'
|
30
|
+
end
|
31
|
+
|
32
|
+
signal_queue = Queue.new
|
33
|
+
|
34
|
+
shutdown_signals.each do |signal|
|
35
|
+
Signal.trap(signal) { signal_queue.close }
|
36
|
+
end
|
37
|
+
|
38
|
+
block = -> { signal_queue.pop }
|
39
|
+
end
|
40
|
+
|
41
|
+
Runner.new(*workers).run(&block)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create a worker to process activities.
|
45
|
+
#
|
46
|
+
# @param connection [Temporalio::Connection] A connection to be used for this worker.
|
47
|
+
# @param namespace [String] A namespace.
|
48
|
+
# @param task_queue [String] A task queue.
|
49
|
+
# @param activities [Array<Class>] A list of activities (subclasses of {Temporalio::Activity}).
|
50
|
+
# @param data_converter [Temporalio::DataConverter] Data converter to use for all data conversions
|
51
|
+
# to/from payloads.
|
52
|
+
# @param activity_executor [ThreadPoolExecutor] Concurrent executor for all activities. Defaults
|
53
|
+
# to a {ThreadPoolExecutor} with `:max_concurrent_activities` available threads.
|
54
|
+
# @param interceptors [Array<Temporalio::Interceptor::ActivityInbound, Temporalio::Interceptor::ActivityOutbound>]
|
55
|
+
# Collection of interceptors for this worker.
|
56
|
+
# @param max_concurrent_activities [Integer] Number of concurrently running activities.
|
57
|
+
# @param graceful_shutdown_timeout [Integer] Amount of time (in seconds) activities are given
|
58
|
+
# after a shutdown to complete before they are cancelled. A default value of `nil` means that
|
59
|
+
# activities are never cancelled when handling a shutdown.
|
60
|
+
#
|
61
|
+
# @raise [ArgumentError] When no activities have been provided.
|
62
|
+
def initialize(
|
63
|
+
connection,
|
64
|
+
namespace,
|
65
|
+
task_queue,
|
66
|
+
activities: [],
|
67
|
+
data_converter: Temporalio::DataConverter.new,
|
68
|
+
activity_executor: nil,
|
69
|
+
interceptors: [],
|
70
|
+
max_concurrent_activities: 100,
|
71
|
+
graceful_shutdown_timeout: nil
|
72
|
+
)
|
73
|
+
@started = false
|
74
|
+
@shutdown = false
|
75
|
+
@mutex = Mutex.new
|
76
|
+
@runtime = Temporalio::Runtime.instance
|
77
|
+
@activity_executor = activity_executor || ThreadPoolExecutor.new(max_concurrent_activities)
|
78
|
+
@core_worker = Temporalio::Bridge::Worker.create(
|
79
|
+
@runtime.core_runtime,
|
80
|
+
connection.core_connection,
|
81
|
+
namespace,
|
82
|
+
task_queue,
|
83
|
+
0, # maxCachedWorkflows disabled temporarily
|
84
|
+
# FIXME: expose enable_non_local_activities
|
85
|
+
activities.empty?,
|
86
|
+
)
|
87
|
+
sync_worker = Worker::SyncWorker.new(@core_worker)
|
88
|
+
@activity_worker =
|
89
|
+
unless activities.empty?
|
90
|
+
Worker::ActivityWorker.new(
|
91
|
+
task_queue,
|
92
|
+
sync_worker,
|
93
|
+
activities,
|
94
|
+
data_converter,
|
95
|
+
interceptors,
|
96
|
+
@activity_executor,
|
97
|
+
graceful_shutdown_timeout,
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
unless @activity_worker
|
102
|
+
raise ArgumentError, 'At least one activity must be specified'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Run the worker and wait on it to be shut down.
|
107
|
+
#
|
108
|
+
# This will not return until shutdown is complete (and all running activities finished) and will
|
109
|
+
# raise if there is a worker fatal error. To run multiple workers use the class method {.run}.
|
110
|
+
#
|
111
|
+
# @note A worker is only intended to be started once. Initialize a new worker should you need to
|
112
|
+
# run it again.
|
113
|
+
#
|
114
|
+
# @yield Optionally you can provide a block by the end of which the worker will shut itself
|
115
|
+
# down. You can use this to stop a worker after some time has passed or any other arbitrary
|
116
|
+
# implementation has completed. Any errors raised from this block will be re-raised by this
|
117
|
+
# method.
|
118
|
+
def run(&block)
|
119
|
+
Runner.new(self).run(&block)
|
120
|
+
end
|
121
|
+
|
122
|
+
# Start the worker asynchronously in a shared runtime.
|
123
|
+
#
|
124
|
+
# This is an internal method for advanced use-cases for those intended to implement their own
|
125
|
+
# worker runner.
|
126
|
+
#
|
127
|
+
# @note A worker is only intended to be started once. Initialize a new worker should you need to
|
128
|
+
# start it again.
|
129
|
+
#
|
130
|
+
# @api private
|
131
|
+
#
|
132
|
+
# @param runner [Temporalio::Worker::Runner] A runner to notify when the worker is shutting down.
|
133
|
+
def start(runner = nil)
|
134
|
+
mutex.synchronize do
|
135
|
+
raise 'Worker is already started' if started?
|
136
|
+
|
137
|
+
@started = true
|
138
|
+
end
|
139
|
+
|
140
|
+
@runner = runner
|
141
|
+
runtime.ensure_callback_loop
|
142
|
+
|
143
|
+
runtime.reactor.async do |task|
|
144
|
+
if activity_worker
|
145
|
+
task.async do |task|
|
146
|
+
activity_worker.run(task)
|
147
|
+
rescue StandardError => e
|
148
|
+
shutdown(e) # initiate shutdown because of a fatal error
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Initiate a worker shutdown and wait until complete.
|
155
|
+
#
|
156
|
+
# This can be called before the worker has even started and is safe for repeated invocations.
|
157
|
+
# This method will not return until the worker has completed shutting down.
|
158
|
+
#
|
159
|
+
# @param exception [Exception] An exception to be raised from {#run} or {.run} methods after a
|
160
|
+
# shutdown procedure has completed.
|
161
|
+
def shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown'))
|
162
|
+
mutex.synchronize do
|
163
|
+
return unless running?
|
164
|
+
|
165
|
+
# Let the runner know we're shutting down, so it can stop other workers.
|
166
|
+
# This will cause a reentrant call to this method, but the mutex above will block that call.
|
167
|
+
runner&.shutdown(exception)
|
168
|
+
|
169
|
+
# Initiate Core shutdown, which will start dropping poll requests
|
170
|
+
core_worker.initiate_shutdown
|
171
|
+
# Start the graceful activity shutdown timer, which will cancel activities after the timeout
|
172
|
+
activity_worker&.setup_graceful_shutdown_timer(runtime.reactor)
|
173
|
+
# Wait for workers to drain any outstanding tasks
|
174
|
+
activity_worker&.drain
|
175
|
+
activity_executor.shutdown
|
176
|
+
# Finalize the shutdown by stopping the Core
|
177
|
+
core_worker.finalize_shutdown
|
178
|
+
|
179
|
+
@shutdown = true
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Whether the worker has been started.
|
184
|
+
#
|
185
|
+
# @return [Boolean]
|
186
|
+
def started?
|
187
|
+
@started
|
188
|
+
end
|
189
|
+
|
190
|
+
# Whether the worker is running.
|
191
|
+
#
|
192
|
+
# This is only `true` if the worker has been started and not yet shut down.
|
193
|
+
#
|
194
|
+
# @return [Boolean]
|
195
|
+
def running?
|
196
|
+
@started && !@shutdown
|
197
|
+
end
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
attr_reader :mutex, :runtime, :activity_executor, :core_worker, :activity_worker,
|
202
|
+
:runner
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'temporalio/workflow/future'
|
2
|
+
|
3
|
+
module Temporalio
|
4
|
+
class Workflow
|
5
|
+
module Async
|
6
|
+
def self.run(&block)
|
7
|
+
Future.new do |future, resolve, reject|
|
8
|
+
Fiber.new do
|
9
|
+
Future.current = future
|
10
|
+
result = block.call
|
11
|
+
resolve.call(result)
|
12
|
+
rescue StandardError => e
|
13
|
+
reject.call(e)
|
14
|
+
end.resume
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.all(*futures)
|
19
|
+
Future.new do |future, resolve, _reject|
|
20
|
+
future.on_cancel { futures.each(&:cancel) }
|
21
|
+
|
22
|
+
futures.each do |f|
|
23
|
+
f.then do
|
24
|
+
# Resolve the aggregate once all futures have been fulfilled (resolved or rejected)
|
25
|
+
resolve.call(nil) if futures.none?(&:pending?)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.any(*futures)
|
32
|
+
# This future is never rejected
|
33
|
+
Future.new do |future, resolve, _reject|
|
34
|
+
future.on_cancel { futures.each(&:cancel) }
|
35
|
+
|
36
|
+
futures.each do |f|
|
37
|
+
# Resolve the aggregate once the first future fulfills (resolved or rejected)
|
38
|
+
# NOTE: The the first completed future will be the resolved value and all subsequent
|
39
|
+
# calls to `resolve` will have no effect.
|
40
|
+
f.then { resolve.call(f) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'temporalio/errors'
|
2
|
+
require 'temporalio/workflow/execution_status'
|
3
3
|
require 'google/protobuf/well_known_types'
|
4
4
|
|
5
|
-
module
|
5
|
+
module Temporalio
|
6
6
|
class Workflow
|
7
7
|
class ExecutionInfo < Struct.new(
|
8
8
|
:raw,
|
@@ -23,7 +23,7 @@ module Temporal
|
|
23
23
|
)
|
24
24
|
def self.from_raw(response, converter)
|
25
25
|
raw_info = response.workflow_execution_info
|
26
|
-
raise
|
26
|
+
raise Temporalio::Error::UnexpectedResponse, 'missing workflow_execution_info' unless raw_info
|
27
27
|
|
28
28
|
new(
|
29
29
|
raw: response,
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Temporalio
|
2
|
+
class Workflow
|
3
|
+
class Future
|
4
|
+
THREAD_KEY = :temporalio_workflow_future
|
5
|
+
|
6
|
+
class Rejected < StandardError; end
|
7
|
+
|
8
|
+
def self.current
|
9
|
+
Thread.current[THREAD_KEY]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.current=(future)
|
13
|
+
Thread.current[THREAD_KEY] = future
|
14
|
+
end
|
15
|
+
|
16
|
+
# Revist the reason for combining futures and cancellation scopes, maybe they are separate?
|
17
|
+
def initialize(&block)
|
18
|
+
@resolved = false
|
19
|
+
@value = nil
|
20
|
+
@rejected = false
|
21
|
+
@error = Rejected.new('Future rejected')
|
22
|
+
@cancel_requested = false
|
23
|
+
@blocked_fibers = []
|
24
|
+
@callbacks = []
|
25
|
+
@cancel_callbacks = []
|
26
|
+
|
27
|
+
# Chain cancellation into parent future if one exists
|
28
|
+
Future.current&.on_cancel { cancel }
|
29
|
+
|
30
|
+
# NOTE: resolve and reject methods are accessible via procs to avoid exposing
|
31
|
+
# them via the public interface.
|
32
|
+
block.call(
|
33
|
+
self,
|
34
|
+
->(value) { resolve(value) },
|
35
|
+
->(error) { reject(error) },
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def then(&block)
|
40
|
+
Future.new do |future, resolve, reject|
|
41
|
+
# @type var wrapped_block: ^() -> void
|
42
|
+
wrapped_block = -> do # rubocop:disable Style/Lambda
|
43
|
+
Fiber.new do
|
44
|
+
Future.current = future
|
45
|
+
# The block is provided the Future on which #then was called
|
46
|
+
result = block.call(self)
|
47
|
+
resolve.call(result)
|
48
|
+
rescue StandardError => e
|
49
|
+
reject.call(e)
|
50
|
+
end.resume
|
51
|
+
end
|
52
|
+
|
53
|
+
if pending?
|
54
|
+
callbacks << wrapped_block
|
55
|
+
else
|
56
|
+
wrapped_block.call
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_cancel(&block)
|
62
|
+
if pending? && !cancel_requested?
|
63
|
+
cancel_callbacks << block
|
64
|
+
else
|
65
|
+
block.call
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def pending?
|
70
|
+
!resolved? && !rejected?
|
71
|
+
end
|
72
|
+
|
73
|
+
def resolved?
|
74
|
+
@resolved
|
75
|
+
end
|
76
|
+
|
77
|
+
def rejected?
|
78
|
+
@rejected
|
79
|
+
end
|
80
|
+
|
81
|
+
def await
|
82
|
+
if pending?
|
83
|
+
blocked_fibers << Fiber.current
|
84
|
+
# yield into the parent fiber
|
85
|
+
Fiber.yield while pending?
|
86
|
+
end
|
87
|
+
|
88
|
+
raise error if rejected?
|
89
|
+
|
90
|
+
value
|
91
|
+
end
|
92
|
+
|
93
|
+
def cancel
|
94
|
+
return unless pending?
|
95
|
+
return if cancel_requested?
|
96
|
+
|
97
|
+
@cancel_requested = true
|
98
|
+
cancel_callbacks.each(&:call)
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
attr_reader :value, :error, :blocked_fibers, :callbacks, :cancel_callbacks
|
104
|
+
|
105
|
+
def cancel_requested?
|
106
|
+
@cancel_requested
|
107
|
+
end
|
108
|
+
|
109
|
+
# TODO: Run callbacks in a Fiber to allow blocking calls
|
110
|
+
def run_callbacks
|
111
|
+
callbacks.each(&:call)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Unblock every fiber that this future is awaited on
|
115
|
+
def resume_fibers
|
116
|
+
blocked_fibers.each(&:resume)
|
117
|
+
end
|
118
|
+
|
119
|
+
def resolve(value)
|
120
|
+
return unless pending?
|
121
|
+
|
122
|
+
@value = value
|
123
|
+
@resolved = true
|
124
|
+
run_callbacks
|
125
|
+
resume_fibers
|
126
|
+
end
|
127
|
+
|
128
|
+
def reject(error)
|
129
|
+
return unless pending?
|
130
|
+
|
131
|
+
@error = error
|
132
|
+
@rejected = true
|
133
|
+
run_callbacks
|
134
|
+
resume_fibers
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'temporal/api/enums/v1/workflow_pb'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Temporalio
|
4
4
|
class Workflow
|
5
5
|
# How already-in-use workflow IDs are handled on start.
|
6
6
|
#
|
7
|
-
# @see
|
7
|
+
# @see Temporalio::Api::Enums::V1::WorkflowIdReusePolicy
|
8
8
|
class IDReusePolicy
|
9
9
|
POLICIES = [
|
10
10
|
ALLOW_DUPLICATE = :ALLOW_DUPLICATE,
|
@@ -14,13 +14,13 @@ module Temporal
|
|
14
14
|
].freeze
|
15
15
|
|
16
16
|
API_MAP = {
|
17
|
-
|
17
|
+
Temporalio::Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE =>
|
18
18
|
ALLOW_DUPLICATE,
|
19
|
-
|
19
|
+
Temporalio::Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY =>
|
20
20
|
ALLOW_DUPLICATE_FAILED_ONLY,
|
21
|
-
|
21
|
+
Temporalio::Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE =>
|
22
22
|
REJECT_DUPLICATE,
|
23
|
-
|
23
|
+
Temporalio::Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING =>
|
24
24
|
TERMINATE_IF_RUNNING,
|
25
25
|
}.freeze
|
26
26
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Temporalio
|
2
|
+
class Workflow
|
3
|
+
# Class containing information about a workflow's parent.
|
4
|
+
class ParentInfo < Struct.new(
|
5
|
+
:namespace,
|
6
|
+
:run_id,
|
7
|
+
:workflow_id,
|
8
|
+
keyword_init: true,
|
9
|
+
)
|
10
|
+
# @!attribute [r] namespace
|
11
|
+
# @return [String] Namespace of the parent workflow.
|
12
|
+
# @!attribute [r] run_id
|
13
|
+
# @return [String] Run ID of the parent workflow.
|
14
|
+
# @!attribute [r] workflow_id
|
15
|
+
# @return [String] ID of the parent workflow.
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class containing information about a workflow.
|
19
|
+
class Info < Struct.new(
|
20
|
+
:attempt,
|
21
|
+
:continued_run_id,
|
22
|
+
:cron_schedule,
|
23
|
+
:execution_timeout,
|
24
|
+
:headers,
|
25
|
+
:namespace,
|
26
|
+
:parent,
|
27
|
+
:raw_memo,
|
28
|
+
:retry_policy,
|
29
|
+
:run_id,
|
30
|
+
:run_timeout,
|
31
|
+
:search_attributes,
|
32
|
+
:start_time,
|
33
|
+
:task_queue,
|
34
|
+
:task_timeout,
|
35
|
+
:workflow_id,
|
36
|
+
:workflow_type,
|
37
|
+
keyword_init: true,
|
38
|
+
)
|
39
|
+
# @!attribute [r] attempt
|
40
|
+
# @return [Integer] Attempt of executing the workflow.
|
41
|
+
# @!attribute [r] continued_run_id
|
42
|
+
# @return [String] Run id of the previous workflow which continued-as-new or retired or cron
|
43
|
+
# executed into this workflow, if any.
|
44
|
+
# @!attribute [r] cron_schedule
|
45
|
+
# @return [String] Cron schedule of the workflow.
|
46
|
+
# @!attribute [r] execution_timeout
|
47
|
+
# @return [Float] Execution timeout of the workflow (in seconds).
|
48
|
+
# @!attribute [r] headers
|
49
|
+
# @return [Hash<String, any>] Headers for the workflow.
|
50
|
+
# @!attribute [r] namespace
|
51
|
+
# @return [String] Namespace of the workflow.
|
52
|
+
# @!attribute [r] parent
|
53
|
+
# @return [Temporalio::Workflow::ParentInfo] Info of the parent workflow.
|
54
|
+
# @!attribute [r] raw_memo
|
55
|
+
# @return [Hash<String, any>] Memo for the workflow.
|
56
|
+
# @!attribute [r] retry_policy
|
57
|
+
# @return [Temporalio::RetryPolicy] RetryPolicy of the workflow.
|
58
|
+
# @!attribute [r] run_id
|
59
|
+
# @return [String] Run ID of the workflow.
|
60
|
+
# @!attribute [r] run_timeout
|
61
|
+
# @return [Float] Run timeout of the workflow (in seconds).
|
62
|
+
# @!attribute [r] search_attributes
|
63
|
+
# @return [Hash<String, String>] Search attributes of the workflow.
|
64
|
+
# @!attribute [r] start_time
|
65
|
+
# @return [Time] Start time of the workflow.
|
66
|
+
# @!attribute [r] task_queue
|
67
|
+
# @return [String] Task queue of the workflow.
|
68
|
+
# @!attribute [r] task_timeout
|
69
|
+
# @return [Float] Task timeout of the workflow (in seconds).
|
70
|
+
# @!attribute [r] workflow_id
|
71
|
+
# @return [String] ID of the workflow.
|
72
|
+
# @!attribute [r] workflow_type
|
73
|
+
# @return [String] Type of the workflow.
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|