Module: Mongo::Operation::Timed Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
Aggregate::OpMsg ,
Command::OpMsg ,
Count::OpMsg ,
Create::OpMsg ,
CreateIndex::OpMsg ,
CreateSearchIndexes::OpMsg ,
CreateUser::OpMsg ,
Delete::OpMsg ,
Distinct::OpMsg ,
Drop::OpMsg ,
DropDatabase::OpMsg ,
DropIndex::OpMsg ,
DropSearchIndex::OpMsg ,
Explain::OpMsg ,
Find::OpMsg ,
GetMore::OpMsg ,
Indexes::OpMsg ,
Insert::OpMsg ,
KillCursors::OpMsg ,
ListCollections::OpMsg ,
MapReduce::OpMsg ,
OpMsgBase ,
ParallelScan::OpMsg ,
RemoveUser::OpMsg ,
Update::OpMsg ,
UpdateSearchIndex::OpMsg ,
UpdateUser::OpMsg ,
UsersInfo::OpMsg ,
WriteCommand::OpMsg
| |
Defined in: | lib/mongo/operation/shared/timed.rb |
Overview
Defines the behavior of operations that have the default timeout behavior described by the client-side operation timeouts (CSOT) spec.
Instance Method Summary
-
#apply_relevant_timeouts_to(spec, connection) ⇒ Hash
Internal use only
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
Internal use only
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
If a timeout is active (as defined by the current context), and it has not yet expired, add :maxTimeMS
to the spec.
# 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.
# 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