Class: Mongo::CsotTimeoutHolder Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
Mongo::Operation::Context
|
|
Inherits: | Object |
Defined in: | lib/mongo/csot_timeout_holder.rb |
Overview
This class stores operation timeout and provides corresponding helper methods.
Class Method Summary
- .new(session: nil, operation_timeouts: {}) ⇒ CsotTimeoutHolder constructor Internal use only
Instance Attribute Summary
- #csot? ⇒ true | false readonly Internal use only
- #deadline readonly Internal use only
- #operation_timeouts readonly Internal use only
- #timeout? ⇒ true | false readonly Internal use only
- #timeout_expired? ⇒ true | false readonly Internal use only
- #timeout_sec readonly Internal use only
Instance Method Summary
-
#check_timeout!
Internal use only
Check whether the operation timeout expired, and raises an appropriate error if yes.
- #remaining_timeout_ms ⇒ Integer | nil Internal use only
- #remaining_timeout_ms! Internal use only
- #remaining_timeout_sec ⇒ Float | nil Internal use only
- #remaining_timeout_sec! Internal use only
- #calculate_deadline(opts = {}, session = nil) private Internal use only
- #calculate_deadline_from_timeout_ms(operation_timeout_ms) private Internal use only
- #check_no_override_inside_transaction!(opts, session) private Internal use only
Instance Attribute Details
#csot? ⇒ true
| false
(readonly)
# File 'lib/mongo/csot_timeout_holder.rb', line 31
def csot? !deadline.nil? end
#deadline (readonly)
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 28
attr_reader :deadline, :timeout_sec, :operation_timeouts
#operation_timeouts (readonly)
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 28
attr_reader :deadline, :timeout_sec, :operation_timeouts
#timeout? ⇒ true
| false
(readonly)
# File 'lib/mongo/csot_timeout_holder.rb', line 37
def timeout? ![ nil, 0 ].include?(@deadline) end
#timeout_expired? ⇒ true
| false
(readonly)
#timeout_sec (readonly)
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 28
attr_reader :deadline, :timeout_sec, :operation_timeouts
Instance Method Details
#calculate_deadline(opts = {}, session = nil) (private)
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 92
def calculate_deadline(opts = {}, session = nil) check_no_override_inside_transaction!(opts, session) return session&.with_transaction_deadline if session&.with_transaction_deadline if (operation_timeout_ms = opts[:operation_timeout_ms]) calculate_deadline_from_timeout_ms(operation_timeout_ms) elsif (inherited_timeout_ms = opts[:inherited_timeout_ms]) calculate_deadline_from_timeout_ms(inherited_timeout_ms) end end
#calculate_deadline_from_timeout_ms(operation_timeout_ms) (private)
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 109
def calculate_deadline_from_timeout_ms(operation_timeout_ms) if operation_timeout_ms.positive? Utils.monotonic_time + (operation_timeout_ms / 1_000.0) elsif operation_timeout_ms.zero? 0 elsif operation_timeout_ms.negative? raise ArgumentError, "timeout_ms must be a non-negative integer but #{operation_timeout_ms} given" end end
#check_no_override_inside_transaction!(opts, session) (private)
# File 'lib/mongo/csot_timeout_holder.rb', line 103
def check_no_override_inside_transaction!(opts, session) return unless opts[:operation_timeout_ms] && session&.with_transaction_deadline raise ArgumentError, 'Cannot override timeout_ms inside with_transaction block' end
#check_timeout!
Check whether the operation timeout expired, and raises an appropriate error if yes.
# File 'lib/mongo/csot_timeout_holder.rb', line 84
def check_timeout! return unless timeout_expired? raise Error::TimeoutError, "Operation took more than #{timeout_sec} seconds" end
#remaining_timeout_ms ⇒ Integer
| nil
# File 'lib/mongo/csot_timeout_holder.rb', line 58
def remaining_timeout_ms seconds = remaining_timeout_sec return nil if seconds.nil? (seconds * 1_000).to_i end
#remaining_timeout_ms!
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 65
def remaining_timeout_ms! check_timeout! remaining_timeout_ms end
#remaining_timeout_sec ⇒ Float
| nil
#remaining_timeout_sec!
[ GitHub ]# File 'lib/mongo/csot_timeout_holder.rb', line 50
def remaining_timeout_sec! check_timeout! remaining_timeout_sec end