Class: ActiveRecord::Bogacs::Reaper
- Inherits:
-
Object
- Object
- ActiveRecord::Bogacs::Reaper
- Defined in:
- lib/active_record/bogacs/reaper.rb
Overview
This version is fail safe - raised errors won’t stop the reaping process.
Every frequency
seconds, the reaper will “reap” a pool it belongs to. Reaping means detecting stale cached connections in the pool - those that were checked-out by a thread but never checked back in after the thread finished/died.
Instead the thread will be restarted and reaping continues at the next tick.
Configure the frequency by setting ‘:reaping_frequency` in your database yaml file.
Instance Attribute Summary collapse
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#retry_error ⇒ Object
Returns the value of attribute retry_error.
Instance Method Summary collapse
-
#initialize(pool, frequency) ⇒ Reaper
constructor
Reaper.new(self, spec.config).run.
- #run ⇒ Object
- #running? ⇒ Boolean
- #start(delay = nil) ⇒ Object
Constructor Details
#initialize(pool, frequency) ⇒ Reaper
Reaper.new(self, spec.config).run
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_record/bogacs/reaper.rb', line 23 def initialize(pool, frequency) @pool = pool; if frequency frequency = frequency.to_f @frequency = frequency > 0.0 ? frequency : false else @frequency = nil end @retry_error = 1.5; @running = nil end |
Instance Attribute Details
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
18 19 20 |
# File 'lib/active_record/bogacs/reaper.rb', line 18 def frequency @frequency end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
18 19 20 |
# File 'lib/active_record/bogacs/reaper.rb', line 18 def pool @pool end |
#retry_error ⇒ Object
Returns the value of attribute retry_error.
19 20 21 |
# File 'lib/active_record/bogacs/reaper.rb', line 19 def retry_error @retry_error end |
Instance Method Details
#run ⇒ Object
34 35 36 37 |
# File 'lib/active_record/bogacs/reaper.rb', line 34 def run return unless frequency @running = true; start end |
#running? ⇒ Boolean
43 |
# File 'lib/active_record/bogacs/reaper.rb', line 43 def running?; @running end |
#start(delay = nil) ⇒ Object
39 40 41 |
# File 'lib/active_record/bogacs/reaper.rb', line 39 def start(delay = nil) Thread.new { exec(delay) } end |