Class: Mongo::CsotTimeoutHolder Private
- Inherits:
-
Object
- Object
- Mongo::CsotTimeoutHolder
- Defined in:
- lib/mongo/csot_timeout_holder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This class stores operation timeout and provides corresponding helper methods.
Direct Known Subclasses
Instance Attribute Summary collapse
- #deadline ⇒ Object readonly private
- #operation_timeouts ⇒ Object readonly private
- #timeout_sec ⇒ Object readonly private
Instance Method Summary collapse
-
#check_timeout! ⇒ Object
private
Check whether the operation timeout expired, and raises an appropriate error if yes.
-
#csot? ⇒ true | false
private
Whether CSOT is enabled for the operation.
-
#initialize(session: nil, operation_timeouts: {}) ⇒ CsotTimeoutHolder
constructor
private
A new instance of CsotTimeoutHolder.
-
#remaining_timeout_ms ⇒ Integer | nil
private
Returns the remaining milliseconds of the timeout set for the operation; if no timeout is set, or the timeout is 0 (means unlimited) returns nil.
- #remaining_timeout_ms! ⇒ Object private
-
#remaining_timeout_sec ⇒ Float | nil
private
Returns the remaining seconds of the timeout set for the operation; if no timeout is set, or the timeout is 0 (means unlimited) returns nil.
- #remaining_timeout_sec! ⇒ Object private
-
#timeout? ⇒ true | false
private
Returns false if CSOT is not enabled, or if CSOT is set to 0 (means unlimited), otherwise true.
-
#timeout_expired? ⇒ true | false
private
Whether the timeout for the operation expired.
Constructor Details
#initialize(session: nil, operation_timeouts: {}) ⇒ CsotTimeoutHolder
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 a new instance of CsotTimeoutHolder.
22 23 24 25 26 |
# File 'lib/mongo/csot_timeout_holder.rb', line 22 def initialize(session: nil, operation_timeouts: {}) @deadline = calculate_deadline(operation_timeouts, session) @operation_timeouts = operation_timeouts @timeout_sec = (@deadline - Utils.monotonic_time if @deadline) end |
Instance Attribute Details
#deadline ⇒ Object (readonly)
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.
28 29 30 |
# File 'lib/mongo/csot_timeout_holder.rb', line 28 def deadline @deadline end |
#operation_timeouts ⇒ Object (readonly)
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.
28 29 30 |
# File 'lib/mongo/csot_timeout_holder.rb', line 28 def operation_timeouts @operation_timeouts end |
#timeout_sec ⇒ Object (readonly)
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.
28 29 30 |
# File 'lib/mongo/csot_timeout_holder.rb', line 28 def timeout_sec @timeout_sec end |
Instance Method Details
#check_timeout! ⇒ 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.
Check whether the operation timeout expired, and raises an appropriate error if yes.
84 85 86 87 88 |
# 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 |
#csot? ⇒ true | false
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 Whether CSOT is enabled for the operation.
31 32 33 |
# File 'lib/mongo/csot_timeout_holder.rb', line 31 def csot? !deadline.nil? end |
#remaining_timeout_ms ⇒ Integer | 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 remaining milliseconds of the timeout set for the operation; if no timeout is set, or the timeout is 0 (means unlimited) returns nil.
58 59 60 61 62 63 |
# 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! ⇒ 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.
65 66 67 68 |
# File 'lib/mongo/csot_timeout_holder.rb', line 65 def remaining_timeout_ms! check_timeout! remaining_timeout_ms end |
#remaining_timeout_sec ⇒ Float | 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 remaining seconds of the timeout set for the operation; if no timeout is set, or the timeout is 0 (means unlimited) returns nil.
44 45 46 47 48 |
# File 'lib/mongo/csot_timeout_holder.rb', line 44 def remaining_timeout_sec return nil unless timeout? deadline - Utils.monotonic_time end |
#remaining_timeout_sec! ⇒ 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.
50 51 52 53 |
# File 'lib/mongo/csot_timeout_holder.rb', line 50 def remaining_timeout_sec! check_timeout! remaining_timeout_sec end |
#timeout? ⇒ true | false
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 false if CSOT is not enabled, or if CSOT is set to 0 (means unlimited), otherwise true.
37 38 39 |
# File 'lib/mongo/csot_timeout_holder.rb', line 37 def timeout? ![ nil, 0 ].include?(@deadline) end |
#timeout_expired? ⇒ true | false
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 Whether the timeout for the operation expired. If no timeout set, this method returns false.
72 73 74 75 76 77 78 |
# File 'lib/mongo/csot_timeout_holder.rb', line 72 def timeout_expired? if timeout? Utils.monotonic_time >= deadline else false end end |