Module: Mongo::Operation::Timed Private
- Included in:
- OpMsgBase
- Defined in:
- lib/mongo/operation/shared/timed.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.
Defines the behavior of operations that have the default timeout behavior described by the client-side operation timeouts (CSOT) spec.
Instance Method Summary collapse
-
#apply_relevant_timeouts_to(spec, connection) ⇒ Hash
private
If a timeout is active (as defined by the current context), and it has not yet expired, add :maxTimeMS to the spec.
-
#with_max_time(connection) ⇒ Hash
private
A helper method that computes the remaining timeout (in seconds) and yields it to the associated block.
Instance Method Details
#apply_relevant_timeouts_to(spec, connection) ⇒ Hash
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.
If a timeout is active (as defined by the current context), and it has not yet expired, add :maxTimeMS to the spec.
22 23 24 25 26 27 28 29 |
# 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
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.
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.
40 41 42 43 44 45 46 47 48 49 |
# 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 |