123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Operation::Timed Private

Do not use. This module is for internal use only.

Overview

Defines the behavior of operations that have the default timeout behavior described by the client-side operation timeouts (CSOT) spec.

Instance Method Summary

Instance Method Details

#apply_relevant_timeouts_to(spec, connection) ⇒ Hash

If a timeout is active (as defined by the current context), and it has not yet expired, add :maxTimeMS to the spec.

Parameters:

  • spec (Hash)

    The spec to modify

  • connection (Connection)

    The connection that will be used to execute the operation

Returns:

  • (Hash)

    the spec

[ GitHub ]

  
# File 'lib/mongo/operation/shared/timed.rb', line 22

def apply_relevant_timeouts_to(spec, connection)
  with_max_time(connection) do |max_time_sec|
    return spec if max_time_sec.nil?
    return spec if connection.description.mongocryptd?

    spec.tap { spec[:maxTimeMS] = (max_time_sec * 1_000).to_i }
  end
end

#with_max_time(connection) ⇒ Hash

A helper method that computes the remaining timeout (in seconds) and yields it to the associated block. If no timeout is present, yields nil. If the timeout has expired, raises Mongo::Error::TimeoutError.

Parameters:

  • connection (Connection)

    The connection that will be used to execute the operation

Returns:

  • (Hash)

    the result of yielding to the block (which must be a Hash)

[ GitHub ]

  
# File 'lib/mongo/operation/shared/timed.rb', line 40

def with_max_time(connection)
  if context&.timeout?
    max_time_sec = context.remaining_timeout_sec - connection.server.minimum_round_trip_time
    raise Mongo::Error::TimeoutError if max_time_sec <= 0

    yield max_time_sec
  else
    yield nil
  end
end