Class: ActiveRecord::Bogacs::Reaper

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/bogacs/reaper.rb

Overview

Note:

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.

Configure the frequency by setting ‘:reaping_frequency` in your database.yml.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool, frequency) ⇒ Reaper

‘Reaper.new(pool, spec.config).run`



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/bogacs/reaper.rb', line 21

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

#frequencyObject (readonly)

Returns the value of attribute frequency.



16
17
18
# File 'lib/active_record/bogacs/reaper.rb', line 16

def frequency
  @frequency
end

#poolObject (readonly)

Returns the value of attribute pool.



16
17
18
# File 'lib/active_record/bogacs/reaper.rb', line 16

def pool
  @pool
end

#retry_errorObject

Returns the value of attribute retry_error.



17
18
19
# File 'lib/active_record/bogacs/reaper.rb', line 17

def retry_error
  @retry_error
end

Instance Method Details

#runObject



32
33
34
35
# File 'lib/active_record/bogacs/reaper.rb', line 32

def run
  return unless frequency
  @running = true; start
end

#running?Boolean

Returns:

  • (Boolean)


41
# File 'lib/active_record/bogacs/reaper.rb', line 41

def running?; @running end

#start(delay = nil) ⇒ Object



37
38
39
# File 'lib/active_record/bogacs/reaper.rb', line 37

def start(delay = nil)
  Thread.new { exec(delay) }
end