Module: Mongo::Operation::Executable Private
- Includes:
- ResponseHandling
- Included in:
- OpMsgBase
- Defined in:
- lib/mongo/operation/shared/executable.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Shared executable behavior of operations.
Instance Attribute Summary collapse
-
#context ⇒ Operation::Context | nil
private
The operation context used to execute this operation.
Instance Method Summary collapse
- #do_execute(connection, context, options = {}) ⇒ Object private
- #execute(connection, context:, options: {}) ⇒ Object private
Instance Attribute Details
#context ⇒ Operation::Context | nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the operation context used to execute this operation.
30 31 32 |
# File 'lib/mongo/operation/shared/executable.rb', line 30 def context @context end |
Instance Method Details
#do_execute(connection, context, options = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mongo/operation/shared/executable.rb', line 32 def do_execute(connection, context, = {}) # Save the context on the instance, to avoid having to pass it as a # parameter to every single method. There are many legacy methods that # still accept it as a parameter, which are left as-is for now to # minimize the impact of this change. Moving forward, it may be # reasonable to refactor things so this saved reference is used instead. @context = context session&.materialize_if_needed unpin_maybe(session, connection) do add_error_labels(connection, context) do check_for_network_error do add_server_diagnostics(connection) do get_result(connection, context, ) do |result| if session if session.in_transaction? && connection.description.load_balancer? if session.pinned_connection_global_id unless session.pinned_connection_global_id == connection.global_id raise( Error::InternalDriverError, "Expected operation to use connection #{session.pinned_connection_global_id} but it used #{connection.global_id}" ) end elsif !session.committing_transaction? && !session.aborting_transaction? session.pin_to_connection(connection.global_id, connection: connection) connection.pin(:transaction) end end if session.snapshot? && !session. session. = result. end end if result.has_cursor_id? && connection.description.load_balancer? if result.cursor_id == 0 connection.unpin else connection.pin end end process_result(result, connection) end end end end end end |
#execute(connection, context:, options: {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 88 89 90 91 |
# File 'lib/mongo/operation/shared/executable.rb', line 83 def execute(connection, context:, options: {}) if Lint.enabled? && !connection.is_a?(Mongo::Server::Connection) raise Error::LintError, "Connection argument is of wrong type: #{connection}" end do_execute(connection, context, ).tap do |result| validate_result(result, connection, context) end end |