Class: Temporalio::Internal::Client::Implementation
- Inherits:
-
Client::Interceptor::Outbound
- Object
- Client::Interceptor::Outbound
- Temporalio::Internal::Client::Implementation
- Defined in:
- lib/temporalio/internal/client/implementation.rb
Constant Summary collapse
- STANDALONE_ACTIVITY_RESOURCE_ID_PREFIX =
Proto routing convention for standalone activity completion: ‘*_by_id` requests carry `resource_id = “activity:<activity_id>”`. See the resource_id field comment on `RecordActivityTaskHeartbeatByIdRequest` (and the analogous Completed/Failed/Canceled requests) in `workflowservice/v1/request_response.proto`. Workflow-scheduled activities leave resource_id empty.
'activity:'
Instance Attribute Summary
Attributes inherited from Client::Interceptor::Outbound
Class Method Summary collapse
-
._activity_id_reference_request_fields(ref) ⇒ Object
Returns the activity_id / workflow_id / run_id / resource_id fields for a ‘*_by_id` async-completion request, depending on whether the reference is the standalone or workflow-bound form.
- .with_default_rpc_options(user_rpc_options) ⇒ Object
Instance Method Summary collapse
- #_start_workflow_request_from_with_start_options(klass, start_options) ⇒ Object
- #backfill_schedule(input) ⇒ Object
- #cancel_activity(input) ⇒ Object
- #cancel_workflow(input) ⇒ Object
- #complete_async_activity(input) ⇒ Object
- #count_activities(input) ⇒ Object
- #count_workflows(input) ⇒ Object
- #create_schedule(input) ⇒ Object
- #delete_schedule(input) ⇒ Object
- #describe_activity(input) ⇒ Object
- #describe_schedule(input) ⇒ Object
- #describe_workflow(input) ⇒ Object
- #fail_async_activity(input) ⇒ Object
-
#fetch_activity_outcome(input) ⇒ Object
Long-polls PollActivityExecution until the activity reaches a terminal state.
- #fetch_workflow_history_events(input) ⇒ Object
- #heartbeat_async_activity(input) ⇒ Object
-
#initialize(client) ⇒ Implementation
constructor
A new instance of Implementation.
- #list_activities(input) ⇒ Object
- #list_schedules(input) ⇒ Object
- #list_workflow_page(input) ⇒ Object
- #pause_schedule(input) ⇒ Object
- #poll_workflow_update(input) ⇒ Object
- #query_workflow(input) ⇒ Object
- #report_cancellation_async_activity(input) ⇒ Object
- #signal_with_start_workflow(input) ⇒ Object
- #signal_workflow(input) ⇒ Object
- #start_activity(input) ⇒ Object
- #start_update_with_start_workflow(input) ⇒ Object
- #start_workflow(input) ⇒ Object
- #start_workflow_update(input) ⇒ Object
- #terminate_activity(input) ⇒ Object
- #terminate_workflow(input) ⇒ Object
- #trigger_schedule(input) ⇒ Object
- #unpause_schedule(input) ⇒ Object
- #update_schedule(input) ⇒ Object
Constructor Details
#initialize(client) ⇒ Implementation
Returns a new instance of Implementation.
77 78 79 80 |
# File 'lib/temporalio/internal/client/implementation.rb', line 77 def initialize(client) super(nil) # steep:ignore @client = client end |
Class Method Details
._activity_id_reference_request_fields(ref) ⇒ Object
Returns the activity_id / workflow_id / run_id / resource_id fields for a ‘*_by_id` async-completion request, depending on whether the reference is the standalone or workflow-bound form. Splat into the request constructor’s kwargs alongside the request-specific fields.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/temporalio/internal/client/implementation.rb', line 44 def self._activity_id_reference_request_fields(ref) if ref.standalone? { workflow_id: nil, run_id: ref.activity_run_id, activity_id: ref.activity_id, resource_id: "#{STANDALONE_ACTIVITY_RESOURCE_ID_PREFIX}#{ref.activity_id}" } else { workflow_id: ref.workflow_id, run_id: ref.run_id, activity_id: ref.activity_id, resource_id: nil } end end |
.with_default_rpc_options(user_rpc_options) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/temporalio/internal/client/implementation.rb', line 62 def self.() # If the user did not provide an override_retry, we need to make sure # we use an option set that has it as "true" if .nil? = @always_retry_options ||= Temporalio::Client::RPCOptions.new(override_retry: true) elsif !.is_a?(Temporalio::Client::RPCOptions) raise ArgumentError, 'rpc_options must be RPCOptions' elsif .override_retry.nil? # Copy and set as true = .dup .override_retry = true end end |
Instance Method Details
#_start_workflow_request_from_with_start_options(klass, start_options) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/temporalio/internal/client/implementation.rb', line 340 def (klass, ) klass.new( request_id: SecureRandom.uuid, namespace: @client.namespace, workflow_type: Api::Common::V1::WorkflowType.new(name: .workflow), workflow_id: .id, task_queue: Api::TaskQueue::V1::TaskQueue.new(name: .task_queue.to_s), input: @client.data_converter.to_payloads(.args, hints: .arg_hints), workflow_execution_timeout: ProtoUtils.seconds_to_duration(.execution_timeout), workflow_run_timeout: ProtoUtils.seconds_to_duration(.run_timeout), workflow_task_timeout: ProtoUtils.seconds_to_duration(.task_timeout), identity: @client.connection.identity, workflow_id_reuse_policy: .id_reuse_policy, workflow_id_conflict_policy: .id_conflict_policy, retry_policy: .retry_policy&._to_proto, cron_schedule: .cron_schedule, memo: ProtoUtils.memo_to_proto(.memo, @client.data_converter), search_attributes: .search_attributes&._to_proto, workflow_start_delay: ProtoUtils.seconds_to_duration(.start_delay), user_metadata: ProtoUtils.( .static_summary, .static_details, @client.data_converter ), header: ProtoUtils.headers_to_proto(.headers, @client.data_converter), priority: .priority._to_proto ) end |
#backfill_schedule(input) ⇒ Object
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/temporalio/internal/client/implementation.rb', line 713 def backfill_schedule(input) @client.workflow_service.patch_schedule( Api::WorkflowService::V1::PatchScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, patch: Api::Schedule::V1::SchedulePatch.new( backfill_request: input.backfills.map(&:_to_proto) ), identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#cancel_activity(input) ⇒ Object
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1035 def cancel_activity(input) @client.workflow_service.request_cancel_activity_execution( Api::WorkflowService::V1::RequestCancelActivityExecutionRequest.new( namespace: @client.namespace, activity_id: input.activity_id, run_id: input.activity_run_id || '', identity: @client.connection.identity, request_id: SecureRandom.uuid, reason: input.reason ), rpc_options: Implementation.(input.) ) nil end |
#cancel_workflow(input) ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/temporalio/internal/client/implementation.rb', line 613 def cancel_workflow(input) @client.workflow_service.request_cancel_workflow_execution( Api::WorkflowService::V1::RequestCancelWorkflowExecutionRequest.new( namespace: @client.namespace, workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), first_execution_run_id: input.first_execution_run_id, identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#complete_async_activity(input) ⇒ Object
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 |
# File 'lib/temporalio/internal/client/implementation.rb', line 874 def complete_async_activity(input) ref = input.task_token_or_id_reference if ref.is_a?(Temporalio::Client::ActivityIDReference) @client.workflow_service.respond_activity_task_completed_by_id( Api::WorkflowService::V1::RespondActivityTaskCompletedByIdRequest.new( **Implementation._activity_id_reference_request_fields(ref), namespace: @client.namespace, identity: @client.connection.identity, result: @client.data_converter.to_payloads([input.result], hints: Array(input.result_hint)) ), rpc_options: Implementation.(input.) ) else @client.workflow_service.respond_activity_task_completed( Api::WorkflowService::V1::RespondActivityTaskCompletedRequest.new( task_token: ref, namespace: @client.namespace, identity: @client.connection.identity, result: @client.data_converter.to_payloads([input.result], hints: Array(input.result_hint)) ), rpc_options: Implementation.(input.) ) end nil end |
#count_activities(input) ⇒ Object
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1086 def count_activities(input) resp = @client.workflow_service.count_activity_executions( Api::WorkflowService::V1::CountActivityExecutionsRequest.new( namespace: @client.namespace, query: input.query || '' ), rpc_options: Implementation.(input.) ) Temporalio::Client::ActivityExecutionCount.new( resp.count, resp.groups.map do |group| Temporalio::Client::ActivityExecutionCount::AggregationGroup.new( group.count, group.group_values.map { |payload| SearchAttributes._value_from_payload(payload) } ) end ) end |
#count_workflows(input) ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/temporalio/internal/client/implementation.rb', line 387 def count_workflows(input) resp = @client.workflow_service.count_workflow_executions( Api::WorkflowService::V1::CountWorkflowExecutionsRequest.new( namespace: @client.namespace, query: input.query || '' ), rpc_options: Implementation.(input.) ) Temporalio::Client::WorkflowExecutionCount.new( resp.count, resp.groups.map do |group| Temporalio::Client::WorkflowExecutionCount::AggregationGroup.new( group.count, group.group_values.map { |payload| SearchAttributes._value_from_payload(payload) } ) end ) end |
#create_schedule(input) ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/temporalio/internal/client/implementation.rb', line 648 def create_schedule(input) if input.schedule.state.limited_actions && input.schedule.state.remaining_actions.zero? raise 'Must set limited actions to false if there are no remaining actions set' end if !input.schedule.state.limited_actions && !input.schedule.state.remaining_actions.zero? raise 'Must set limited actions to true if there are remaining actions set' end @client.workflow_service.create_schedule( Api::WorkflowService::V1::CreateScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, schedule: input.schedule._to_proto(@client.data_converter), initial_patch: if input.trigger_immediately || !input.backfills.empty? Api::Schedule::V1::SchedulePatch.new( trigger_immediately: if input.trigger_immediately Api::Schedule::V1::TriggerImmediatelyRequest.new( overlap_policy: input.schedule.policy.overlap ) end, backfill_request: input.backfills.map(&:_to_proto) ) end, identity: @client.connection.identity, request_id: SecureRandom.uuid, memo: ProtoUtils.memo_to_proto(input.memo, @client.data_converter), search_attributes: input.search_attributes&._to_proto ), rpc_options: Implementation.(input.) ) Temporalio::Client::ScheduleHandle.new(client: @client, id: input.id) rescue Error::RPCError => e # Unpack and raise already started if that's the error, otherwise default raise details = if e.code == Error::RPCError::Code::ALREADY_EXISTS && e.grpc_status.details.first e.grpc_status.details.first.unpack(Api::ErrorDetails::V1::WorkflowExecutionAlreadyStartedFailure) end raise Error::ScheduleAlreadyRunningError if details raise end |
#delete_schedule(input) ⇒ Object
729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/temporalio/internal/client/implementation.rb', line 729 def delete_schedule(input) @client.workflow_service.delete_schedule( Api::WorkflowService::V1::DeleteScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, identity: @client.connection.identity ), rpc_options: Implementation.(input.) ) nil end |
#describe_activity(input) ⇒ Object
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1023 def describe_activity(input) resp = @client.workflow_service.describe_activity_execution( Api::WorkflowService::V1::DescribeActivityExecutionRequest.new( namespace: @client.namespace, activity_id: input.activity_id, run_id: input.activity_run_id || '' ), rpc_options: Implementation.(input.) ) Temporalio::Client::ActivityExecution::Description.new(resp, @client.data_converter) end |
#describe_schedule(input) ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 752 753 |
# File 'lib/temporalio/internal/client/implementation.rb', line 741 def describe_schedule(input) Temporalio::Client::Schedule::Description.new( id: input.id, raw_description: @client.workflow_service.describe_schedule( Api::WorkflowService::V1::DescribeScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id ), rpc_options: Implementation.(input.) ), data_converter: @client.data_converter ) end |
#describe_workflow(input) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/temporalio/internal/client/implementation.rb', line 406 def describe_workflow(input) resp = @client.workflow_service.describe_workflow_execution( Api::WorkflowService::V1::DescribeWorkflowExecutionRequest.new( namespace: @client.namespace, execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ) ), rpc_options: Implementation.(input.) ) Temporalio::Client::WorkflowExecution::Description.new(resp, @client.data_converter) end |
#fail_async_activity(input) ⇒ Object
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
# File 'lib/temporalio/internal/client/implementation.rb', line 900 def fail_async_activity(input) last_heartbeat_details = if input.last_heartbeat_details.empty? nil else @client.data_converter.to_payloads( input.last_heartbeat_details, hints: input.last_heartbeat_detail_hints ) end ref = input.task_token_or_id_reference if ref.is_a?(Temporalio::Client::ActivityIDReference) @client.workflow_service.respond_activity_task_failed_by_id( Api::WorkflowService::V1::RespondActivityTaskFailedByIdRequest.new( **Implementation._activity_id_reference_request_fields(ref), namespace: @client.namespace, identity: @client.connection.identity, failure: @client.data_converter.to_failure(input.error), last_heartbeat_details: ), rpc_options: Implementation.(input.) ) else @client.workflow_service.respond_activity_task_failed( Api::WorkflowService::V1::RespondActivityTaskFailedRequest.new( task_token: ref, namespace: @client.namespace, identity: @client.connection.identity, failure: @client.data_converter.to_failure(input.error), last_heartbeat_details: ), rpc_options: Implementation.(input.) ) end nil end |
#fetch_activity_outcome(input) ⇒ Object
Long-polls PollActivityExecution until the activity reaches a terminal state. Returns the ActivityExecutionOutcome. The server’s long-poll deadline may expire before the activity completes; in that case PollActivityExecutionResponse comes back with an unpopulated ‘outcome` field and the call must be reissued.
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1109 def fetch_activity_outcome(input) req = Api::WorkflowService::V1::PollActivityExecutionRequest.new( namespace: @client.namespace, activity_id: input.activity_id, run_id: input.activity_run_id || '' ) loop do resp = @client.workflow_service.poll_activity_execution( req, rpc_options: Implementation.(input.) ) return resp.outcome if resp.outcome end end |
#fetch_workflow_history_events(input) ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/temporalio/internal/client/implementation.rb', line 420 def fetch_workflow_history_events(input) Enumerator.new do |yielder| req = Api::WorkflowService::V1::GetWorkflowExecutionHistoryRequest.new( namespace: @client.namespace, execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), wait_new_event: input.wait_new_event, history_event_filter_type: input.event_filter_type, skip_archival: input.skip_archival ) loop do resp = @client.workflow_service.get_workflow_execution_history( req, rpc_options: Implementation.(input.) ) resp.history&.events&.each { |event| yielder << event } break if resp.next_page_token.empty? req.next_page_token = resp.next_page_token end end end |
#heartbeat_async_activity(input) ⇒ Object
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/temporalio/internal/client/implementation.rb', line 842 def heartbeat_async_activity(input) ref = input.task_token_or_id_reference resp = if ref.is_a?(Temporalio::Client::ActivityIDReference) @client.workflow_service.record_activity_task_heartbeat_by_id( Api::WorkflowService::V1::RecordActivityTaskHeartbeatByIdRequest.new( **Implementation._activity_id_reference_request_fields(ref), namespace: @client.namespace, identity: @client.connection.identity, details: @client.data_converter.to_payloads(input.details, hints: input.detail_hints) ), rpc_options: Implementation.(input.) ) else @client.workflow_service.record_activity_task_heartbeat( Api::WorkflowService::V1::RecordActivityTaskHeartbeatRequest.new( task_token: ref, namespace: @client.namespace, identity: @client.connection.identity, details: @client.data_converter.to_payloads(input.details, hints: input.detail_hints) ), rpc_options: Implementation.(input.) ) end return unless resp.cancel_requested || resp.activity_paused || resp.activity_reset raise Error::AsyncActivityCanceledError, Activity::CancellationDetails.new( cancel_requested: resp.cancel_requested, paused: resp.activity_paused, reset: resp.activity_reset ) end |
#list_activities(input) ⇒ Object
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1065 def list_activities(input) Enumerator.new do |yielder| req = Api::WorkflowService::V1::ListActivityExecutionsRequest.new( namespace: @client.namespace, query: input.query || '' ) loop do resp = @client.workflow_service.list_activity_executions( req, rpc_options: Implementation.(input.) ) resp.executions.each do |raw_info| yielder << Temporalio::Client::ActivityExecution.new(raw_info) end break if resp.next_page_token.empty? req.next_page_token = resp.next_page_token end end end |
#list_schedules(input) ⇒ Object
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'lib/temporalio/internal/client/implementation.rb', line 689 def list_schedules(input) Enumerator.new do |yielder| req = Api::WorkflowService::V1::ListSchedulesRequest.new( namespace: @client.namespace, query: input.query || '' ) loop do resp = @client.workflow_service.list_schedules( req, rpc_options: Implementation.(input.) ) resp.schedules.each do |raw_entry| yielder << Temporalio::Client::Schedule::List::Description.new( raw_entry:, data_converter: @client.data_converter ) end break if resp.next_page_token.empty? req.next_page_token = resp.next_page_token end end end |
#list_workflow_page(input) ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/temporalio/internal/client/implementation.rb', line 367 def list_workflow_page(input) req = Api::WorkflowService::V1::ListWorkflowExecutionsRequest.new( namespace: @client.namespace, query: input.query || '', next_page_token: input.next_page_token, page_size: input.page_size ) resp = @client.workflow_service.list_workflow_executions( req, rpc_options: Implementation.(input.) ) executions = resp.executions.map do |raw_info| Temporalio::Client::WorkflowExecution.new(raw_info, @client.data_converter) end Temporalio::Client::ListWorkflowPage.new( executions: executions, next_page_token: resp.next_page_token ) end |
#pause_schedule(input) ⇒ Object
755 756 757 758 759 760 761 762 763 764 765 766 767 |
# File 'lib/temporalio/internal/client/implementation.rb', line 755 def pause_schedule(input) @client.workflow_service.patch_schedule( Api::WorkflowService::V1::PatchScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, patch: Api::Schedule::V1::SchedulePatch.new(pause: input.note), identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#poll_workflow_update(input) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/temporalio/internal/client/implementation.rb', line 580 def poll_workflow_update(input) req = Api::WorkflowService::V1::PollWorkflowExecutionUpdateRequest.new( namespace: @client.namespace, update_ref: Api::Update::V1::UpdateRef.new( workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), update_id: input.update_id ), identity: @client.connection.identity, wait_policy: Api::Update::V1::WaitPolicy.new( lifecycle_stage: Temporalio::Client::WorkflowUpdateWaitStage::COMPLETED ) ) # Continue polling as long as we have no outcome loop do resp = @client.workflow_service.poll_workflow_execution_update( req, rpc_options: Implementation.(input.) ) return resp.outcome if resp.outcome rescue Error::RPCError => e # Deadline exceeded or cancel is a special error type if e.code == Error::RPCError::Code::DEADLINE_EXCEEDED || e.code == Error::RPCError::Code::CANCELED raise Error::WorkflowUpdateRPCTimeoutOrCanceledError end raise end end |
#query_workflow(input) ⇒ Object
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/temporalio/internal/client/implementation.rb', line 464 def query_workflow(input) begin resp = @client.workflow_service.query_workflow( Api::WorkflowService::V1::QueryWorkflowRequest.new( namespace: @client.namespace, execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), query: Api::Query::V1::WorkflowQuery.new( query_type: input.query, query_args: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), header: Internal::ProtoUtils.headers_to_proto(input.headers, @client.data_converter) ), query_reject_condition: input.reject_condition || 0 ), rpc_options: Implementation.(input.) ) rescue Error::RPCError => e # If the status is INVALID_ARGUMENT, we can assume it's a query failed # error raise Error::WorkflowQueryFailedError, e. if e.code == Error::RPCError::Code::INVALID_ARGUMENT raise end unless resp.query_rejected.nil? raise Error::WorkflowQueryRejectedError.new(status: ProtoUtils.enum_to_int( Api::Enums::V1::WorkflowExecutionStatus, resp.query_rejected.status )) end results = @client.data_converter.from_payloads(resp.query_result, hints: Array(input.result_hint)) warn("Expected 0 or 1 query result, got #{results.size}") if results.size > 1 results&.first end |
#report_cancellation_async_activity(input) ⇒ Object
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 |
# File 'lib/temporalio/internal/client/implementation.rb', line 936 def report_cancellation_async_activity(input) ref = input.task_token_or_id_reference if ref.is_a?(Temporalio::Client::ActivityIDReference) @client.workflow_service.respond_activity_task_canceled_by_id( Api::WorkflowService::V1::RespondActivityTaskCanceledByIdRequest.new( **Implementation._activity_id_reference_request_fields(ref), namespace: @client.namespace, identity: @client.connection.identity, details: @client.data_converter.to_payloads(input.details, hints: input.detail_hints) ), rpc_options: Implementation.(input.) ) else @client.workflow_service.respond_activity_task_canceled( Api::WorkflowService::V1::RespondActivityTaskCanceledRequest.new( task_token: ref, namespace: @client.namespace, identity: @client.connection.identity, details: @client.data_converter.to_payloads(input.details, hints: input.detail_hints) ), rpc_options: Implementation.(input.) ) end nil end |
#signal_with_start_workflow(input) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/temporalio/internal/client/implementation.rb', line 288 def signal_with_start_workflow(input) raise ArgumentError, 'Start operation is required' unless input.start_workflow_operation # Try to mark used before using input.start_workflow_operation._mark_used # Build req = input.start_workflow_operation. req = ( Api::WorkflowService::V1::SignalWithStartWorkflowExecutionRequest, ) req.signal_name = input.signal req.signal_input = @client.data_converter.to_payloads(input.args, hints: input.arg_hints) # Send request begin resp = @client.workflow_service.signal_with_start_workflow_execution( req, rpc_options: Implementation.(input.) ) rescue Error::RPCError => e # Unpack and raise already started if that's the error, otherwise default raise if e.code == Error::RPCError::Code::ALREADY_EXISTS && e.grpc_status.details.first details = e.grpc_status.details.first.unpack( Api::ErrorDetails::V1::WorkflowExecutionAlreadyStartedFailure ) if details e = Error::WorkflowAlreadyStartedError.new( workflow_id: req.workflow_id, workflow_type: req.workflow_type.name, run_id: details.run_id ) end end # Before we raise here, we want to the start operation exception input.start_workflow_operation._set_workflow_handle(e) raise e end # Set handle and return handle handle = Temporalio::Client::WorkflowHandle.new( client: @client, id: .id, run_id: nil, result_run_id: resp.run_id, first_execution_run_id: resp.run_id, result_hint: .result_hint ) input.start_workflow_operation._set_workflow_handle(handle) handle end |
#signal_workflow(input) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/temporalio/internal/client/implementation.rb', line 445 def signal_workflow(input) @client.workflow_service.signal_workflow_execution( Api::WorkflowService::V1::SignalWorkflowExecutionRequest.new( namespace: @client.namespace, workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), signal_name: input.signal, input: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), header: Internal::ProtoUtils.headers_to_proto(input.headers, @client.data_converter), identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#start_activity(input) ⇒ Object
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/temporalio/internal/client/implementation.rb', line 962 def start_activity(input) raise ArgumentError, 'activity_id is required' if input.activity_id.nil? || input.activity_id.empty? raise ArgumentError, 'task_queue is required' if input.task_queue.nil? || input.task_queue.to_s.empty? if input.schedule_to_close_timeout.nil? && input.start_to_close_timeout.nil? raise ArgumentError, 'either schedule_to_close_timeout or start_to_close_timeout is required' end raise ArgumentError, 'start_delay must be non-negative' if input.start_delay&.negative? req = Api::WorkflowService::V1::StartActivityExecutionRequest.new( namespace: @client.namespace, identity: @client.connection.identity, request_id: SecureRandom.uuid, activity_id: input.activity_id, activity_type: Api::Common::V1::ActivityType.new(name: input.activity), task_queue: Api::TaskQueue::V1::TaskQueue.new(name: input.task_queue.to_s), input: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), schedule_to_close_timeout: ProtoUtils.seconds_to_duration(input.schedule_to_close_timeout), schedule_to_start_timeout: ProtoUtils.seconds_to_duration(input.schedule_to_start_timeout), start_to_close_timeout: ProtoUtils.seconds_to_duration(input.start_to_close_timeout), heartbeat_timeout: ProtoUtils.seconds_to_duration(input.heartbeat_timeout), id_reuse_policy: input.id_reuse_policy, id_conflict_policy: input.id_conflict_policy, retry_policy: input.retry_policy&._to_proto, search_attributes: input.search_attributes&._to_proto, user_metadata: ProtoUtils.( input.static_summary, input.static_details, @client.data_converter ), header: ProtoUtils.headers_to_proto(input.headers, @client.data_converter), priority: input.priority._to_proto, start_delay: ProtoUtils.seconds_to_duration(input.start_delay) ) begin resp = @client.workflow_service.start_activity_execution( req, rpc_options: Implementation.(input.) ) rescue Error::RPCError => e if e.code == Error::RPCError::Code::ALREADY_EXISTS && e.grpc_status.details.first details = e.grpc_status.details.first.unpack( Api::ErrorDetails::V1::ActivityExecutionAlreadyStartedFailure ) if details raise Error::ActivityAlreadyStartedError.new( activity_id: input.activity_id, activity_type: input.activity, activity_run_id: details.run_id ) end end raise end Temporalio::Client::ActivityHandle.new( client: @client, id: input.activity_id, run_id: resp.run_id, result_hint: input.result_hint ) end |
#start_update_with_start_workflow(input) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/temporalio/internal/client/implementation.rb', line 144 def start_update_with_start_workflow(input) raise ArgumentError, 'Start operation is required' unless input.start_workflow_operation if input.start_workflow_operation..id_conflict_policy == WorkflowIDConflictPolicy::UNSPECIFIED raise ArgumentError, 'ID conflict policy is required in start operation' end # Try to mark used before using input.start_workflow_operation._mark_used # Build request = input.start_workflow_operation. start_req = ( Api::WorkflowService::V1::StartWorkflowExecutionRequest, ) req = Api::WorkflowService::V1::ExecuteMultiOperationRequest.new( namespace: @client.namespace, operations: [ Api::WorkflowService::V1::ExecuteMultiOperationRequest::Operation.new(start_workflow: start_req), Api::WorkflowService::V1::ExecuteMultiOperationRequest::Operation.new( update_workflow: Api::WorkflowService::V1::UpdateWorkflowExecutionRequest.new( namespace: @client.namespace, workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: .id ), request: Api::Update::V1::Request.new( meta: Api::Update::V1::Meta.new( update_id: input.update_id, identity: @client.connection.identity ), input: Api::Update::V1::Input.new( name: input.update, args: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), header: Internal::ProtoUtils.headers_to_proto(input.headers, @client.data_converter) ) ), wait_policy: Api::Update::V1::WaitPolicy.new( lifecycle_stage: input.wait_for_stage ) ) ) ] ) # Continually try to start until an exception occurs, the user-asked stage is reached, or the stage is # accepted. But we will set the workflow handle as soon as we can. # @type var update_resp: untyped update_resp = nil run_id = nil begin loop do resp = @client.workflow_service.execute_multi_operation( req, rpc_options: Implementation.(input.) ) run_id = resp.responses.first.start_workflow.run_id # Set workflow handle (no-op if already set) input.start_workflow_operation._set_workflow_handle( Temporalio::Client::WorkflowHandle.new( client: @client, id: .id, run_id: nil, result_run_id: run_id, first_execution_run_id: run_id, result_hint: .result_hint ) ) update_resp = resp.responses.last.update_workflow # We're only done if the response stage is at least accepted if update_resp && Api::Enums::V1::UpdateWorkflowExecutionLifecycleStage.resolve(update_resp.stage) >= Temporalio::Client::WorkflowUpdateWaitStage::ACCEPTED break end end # If the user wants to wait until completed, we must poll until outcome if not already there if input.wait_for_stage == Temporalio::Client::WorkflowUpdateWaitStage::COMPLETED && !update_resp.outcome update_resp.outcome = @client._impl.poll_workflow_update( Temporalio::Client::Interceptor::PollWorkflowUpdateInput.new( workflow_id: .id, run_id:, update_id: input.update_id, rpc_options: input. ) ) end rescue Error => e # If this is a multi-operation failure, set exception to the first present, non-OK, non-aborted error if e.is_a?(Error::RPCError) multi_err = e.grpc_status.details&.first&.unpack(Api::ErrorDetails::V1::MultiOperationExecutionFailure) if multi_err non_aborted = multi_err.statuses.find do |s| # Exists, not-ok, not-aborted s && s.code != Error::RPCError::Code::OK && !s.details&.first&.is(Api::Failure::V1::MultiOperationExecutionAborted) end if non_aborted e = Error::RPCError.new( non_aborted., code: non_aborted.code, raw_grpc_status: Api::Common::V1::GrpcStatus.new( code: non_aborted.code, message: non_aborted., details: non_aborted.details.to_a ) ) end end end if e.is_a?(Error::RPCError) # Deadline exceeded or cancel is a special error type if e.code == Error::RPCError::Code::DEADLINE_EXCEEDED || e.code == Error::RPCError::Code::CANCELED e = Error::WorkflowUpdateRPCTimeoutOrCanceledError.new elsif e.code == Error::RPCError::Code::ALREADY_EXISTS && e.grpc_status.details.first # Unpack and set already started if that's the error details = e.grpc_status.details.first.unpack( Api::ErrorDetails::V1::WorkflowExecutionAlreadyStartedFailure ) if details e = Error::WorkflowAlreadyStartedError.new( workflow_id: .id, workflow_type: start_req.workflow_type.name, run_id: details.run_id ) end end end # Cancel is a special type e = Error::WorkflowUpdateRPCTimeoutOrCanceledError.new if e.is_a?(Error::CanceledError) # Before we raise here, we want to try to set the start operation exception (no-op if already set with a # handle) input.start_workflow_operation._set_workflow_handle(e) raise e end # Return handle Temporalio::Client::WorkflowUpdateHandle.new( client: @client, id: input.update_id, workflow_id: .id, workflow_run_id: run_id, known_outcome: update_resp.outcome, result_hint: input.result_hint ) end |
#start_workflow(input) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/temporalio/internal/client/implementation.rb', line 82 def start_workflow(input) req = Api::WorkflowService::V1::StartWorkflowExecutionRequest.new( request_id: SecureRandom.uuid, namespace: @client.namespace, workflow_type: Api::Common::V1::WorkflowType.new(name: input.workflow), workflow_id: input.workflow_id, task_queue: Api::TaskQueue::V1::TaskQueue.new(name: input.task_queue.to_s), input: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), workflow_execution_timeout: ProtoUtils.seconds_to_duration(input.execution_timeout), workflow_run_timeout: ProtoUtils.seconds_to_duration(input.run_timeout), workflow_task_timeout: ProtoUtils.seconds_to_duration(input.task_timeout), identity: @client.connection.identity, workflow_id_reuse_policy: input.id_reuse_policy, workflow_id_conflict_policy: input.id_conflict_policy, retry_policy: input.retry_policy&._to_proto, cron_schedule: input.cron_schedule, memo: ProtoUtils.memo_to_proto(input.memo, @client.data_converter), search_attributes: input.search_attributes&._to_proto, workflow_start_delay: ProtoUtils.seconds_to_duration(input.start_delay), request_eager_execution: input.request_eager_start, user_metadata: ProtoUtils.( input.static_summary, input.static_details, @client.data_converter ), header: ProtoUtils.headers_to_proto(input.headers, @client.data_converter), priority: input.priority._to_proto, versioning_override: input.versioning_override&._to_proto ) # Send request begin resp = @client.workflow_service.start_workflow_execution( req, rpc_options: Implementation.(input.) ) rescue Error::RPCError => e # Unpack and raise already started if that's the error, otherwise default raise if e.code == Error::RPCError::Code::ALREADY_EXISTS && e.grpc_status.details.first details = e.grpc_status.details.first.unpack( Api::ErrorDetails::V1::WorkflowExecutionAlreadyStartedFailure ) if details raise Error::WorkflowAlreadyStartedError.new( workflow_id: req.workflow_id, workflow_type: req.workflow_type.name, run_id: details.run_id ) end end raise end # Return handle Temporalio::Client::WorkflowHandle.new( client: @client, id: input.workflow_id, run_id: nil, result_run_id: resp.run_id, first_execution_run_id: resp.run_id, result_hint: input.result_hint ) end |
#start_workflow_update(input) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/temporalio/internal/client/implementation.rb', line 500 def start_workflow_update(input) if input.wait_for_stage == Temporalio::Client::WorkflowUpdateWaitStage::ADMITTED raise ArgumentError, 'ADMITTED wait stage not supported' end req = Api::WorkflowService::V1::UpdateWorkflowExecutionRequest.new( namespace: @client.namespace, workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), request: Api::Update::V1::Request.new( meta: Api::Update::V1::Meta.new( update_id: input.update_id, identity: @client.connection.identity ), input: Api::Update::V1::Input.new( name: input.update, args: @client.data_converter.to_payloads(input.args, hints: input.arg_hints), header: Internal::ProtoUtils.headers_to_proto(input.headers, @client.data_converter) ) ), wait_policy: Api::Update::V1::WaitPolicy.new( lifecycle_stage: input.wait_for_stage ) ) # Repeatedly try to invoke start until the update reaches user-provided # wait stage or is at least ACCEPTED (as of the time of this writing, # the user cannot specify sooner than ACCEPTED) # @type var resp: untyped resp = nil expected_stage = ProtoUtils.enum_to_int(Api::Enums::V1::UpdateWorkflowExecutionLifecycleStage, req.wait_policy.lifecycle_stage) accepted_stage = ProtoUtils.enum_to_int(Api::Enums::V1::UpdateWorkflowExecutionLifecycleStage, Temporalio::Client::WorkflowUpdateWaitStage::ACCEPTED) loop do resp = @client.workflow_service.update_workflow_execution( req, rpc_options: Implementation.(input.) ) # We're only done if the response stage is after the requested stage # or the response stage is accepted actual_stage = ProtoUtils.enum_to_int(Api::Enums::V1::UpdateWorkflowExecutionLifecycleStage, resp.stage) break if actual_stage >= expected_stage || actual_stage >= accepted_stage rescue Error::RPCError => e # Deadline exceeded or cancel is a special error type if e.code == Error::RPCError::Code::DEADLINE_EXCEEDED || e.code == Error::RPCError::Code::CANCELED raise Error::WorkflowUpdateRPCTimeoutOrCanceledError end raise rescue Error::CanceledError raise Error::WorkflowUpdateRPCTimeoutOrCanceledError end # If the user wants to wait until completed, we must poll until outcome # if not already there if input.wait_for_stage == Temporalio::Client::WorkflowUpdateWaitStage::COMPLETED && !resp.outcome resp.outcome = @client._impl.poll_workflow_update( Temporalio::Client::Interceptor::PollWorkflowUpdateInput.new( workflow_id: input.workflow_id, run_id: input.run_id, update_id: input.update_id, rpc_options: input. ) ) end Temporalio::Client::WorkflowUpdateHandle.new( client: @client, id: input.update_id, workflow_id: input.workflow_id, workflow_run_id: input.run_id, known_outcome: resp.outcome, result_hint: input.result_hint ) end |
#terminate_activity(input) ⇒ Object
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/temporalio/internal/client/implementation.rb', line 1050 def terminate_activity(input) @client.workflow_service.terminate_activity_execution( Api::WorkflowService::V1::TerminateActivityExecutionRequest.new( namespace: @client.namespace, activity_id: input.activity_id, run_id: input.activity_run_id || '', identity: @client.connection.identity, request_id: SecureRandom.uuid, reason: input.reason ), rpc_options: Implementation.(input.) ) nil end |
#terminate_workflow(input) ⇒ Object
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'lib/temporalio/internal/client/implementation.rb', line 630 def terminate_workflow(input) @client.workflow_service.terminate_workflow_execution( Api::WorkflowService::V1::TerminateWorkflowExecutionRequest.new( namespace: @client.namespace, workflow_execution: Api::Common::V1::WorkflowExecution.new( workflow_id: input.workflow_id, run_id: input.run_id || '' ), reason: input.reason || '', first_execution_run_id: input.first_execution_run_id, details: @client.data_converter.to_payloads(input.details), identity: @client.connection.identity ), rpc_options: Implementation.(input.) ) nil end |
#trigger_schedule(input) ⇒ Object
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 |
# File 'lib/temporalio/internal/client/implementation.rb', line 769 def trigger_schedule(input) @client.workflow_service.patch_schedule( Api::WorkflowService::V1::PatchScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, patch: Api::Schedule::V1::SchedulePatch.new( trigger_immediately: Api::Schedule::V1::TriggerImmediatelyRequest.new( overlap_policy: input.overlap || 0 ) ), identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#unpause_schedule(input) ⇒ Object
787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/temporalio/internal/client/implementation.rb', line 787 def unpause_schedule(input) @client.workflow_service.patch_schedule( Api::WorkflowService::V1::PatchScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, patch: Api::Schedule::V1::SchedulePatch.new(unpause: input.note), identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |
#update_schedule(input) ⇒ Object
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/temporalio/internal/client/implementation.rb', line 801 def update_schedule(input) # TODO(cretz): This is supposed to be a retry-conflict loop, but we do # not yet have a way to know update failure is due to conflict token # mismatch update = input.updater.call( Temporalio::Client::Schedule::Update::Input.new( description: Temporalio::Client::Schedule::Description.new( id: input.id, raw_description: @client.workflow_service.describe_schedule( Api::WorkflowService::V1::DescribeScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id ), rpc_options: Implementation.(input.) ), data_converter: @client.data_converter ) ) ) # Do nothing if update is nil, fail if not an expected update return nil if update.nil? unless update.is_a?(Temporalio::Client::Schedule::Update) raise TypeError, 'Expected result of update block to be a Schedule::Update' end @client.workflow_service.update_schedule( Api::WorkflowService::V1::UpdateScheduleRequest.new( namespace: @client.namespace, schedule_id: input.id, schedule: update.schedule._to_proto(@client.data_converter), search_attributes: update.search_attributes&._to_proto, identity: @client.connection.identity, request_id: SecureRandom.uuid ), rpc_options: Implementation.(input.) ) nil end |