Class: Gitlab::Database::ConnectionTimer
- Inherits:
-
Object
- Object
- Gitlab::Database::ConnectionTimer
- Defined in:
- lib/gitlab/database/connection_timer.rb
Constant Summary collapse
- DEFAULT_INTERVAL =
3600
- RANDOMIZATION_INTERVAL =
600
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#starting_clock_value ⇒ Object
readonly
Returns the value of attribute starting_clock_value.
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
- .current_clock_value ⇒ Object
- .interval_with_randomization ⇒ Object
- .starting_now ⇒ Object
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize(interval, starting_clock_value) ⇒ ConnectionTimer
constructor
A new instance of ConnectionTimer.
- #reset! ⇒ Object
Constructor Details
#initialize(interval, starting_clock_value) ⇒ ConnectionTimer
Returns a new instance of ConnectionTimer.
36 37 38 39 |
# File 'lib/gitlab/database/connection_timer.rb', line 36 def initialize(interval, starting_clock_value) @interval = interval @starting_clock_value = starting_clock_value end |
Class Attribute Details
.interval ⇒ Object
21 22 23 |
# File 'lib/gitlab/database/connection_timer.rb', line 21 def interval @interval ||= DEFAULT_INTERVAL end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
34 35 36 |
# File 'lib/gitlab/database/connection_timer.rb', line 34 def interval @interval end |
#starting_clock_value ⇒ Object (readonly)
Returns the value of attribute starting_clock_value.
34 35 36 |
# File 'lib/gitlab/database/connection_timer.rb', line 34 def starting_clock_value @starting_clock_value end |
Class Method Details
.configure {|_self| ... } ⇒ Object
10 11 12 |
# File 'lib/gitlab/database/connection_timer.rb', line 10 def configure yield self end |
.current_clock_value ⇒ Object
29 30 31 |
# File 'lib/gitlab/database/connection_timer.rb', line 29 def current_clock_value Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
.interval_with_randomization ⇒ Object
25 26 27 |
# File 'lib/gitlab/database/connection_timer.rb', line 25 def interval_with_randomization interval + rand(RANDOMIZATION_INTERVAL) if interval > 0 end |
.starting_now ⇒ Object
14 15 16 17 |
# File 'lib/gitlab/database/connection_timer.rb', line 14 def starting_now # add a small amount of randomization to the interval, so reconnects don't all occur at once new(interval_with_randomization, current_clock_value) end |
Instance Method Details
#expired? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab/database/connection_timer.rb', line 41 def expired? interval&.positive? && self.class.current_clock_value > (starting_clock_value + interval) end |
#reset! ⇒ Object
45 46 47 |
# File 'lib/gitlab/database/connection_timer.rb', line 45 def reset! @starting_clock_value = self.class.current_clock_value end |