Class: ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/wayback_machine_downloader.rb

Constant Summary collapse

MAX_AGE =
300
CLEANUP_INTERVAL =
60
DEFAULT_TIMEOUT =
30
MAX_RETRIES =
3

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ ConnectionPool

Returns a new instance of ConnectionPool.



25
26
27
28
29
# File 'lib/wayback_machine_downloader.rb', line 25

def initialize(size)
  @pool = SizedQueue.new(size)
  size.times { @pool << nil }
  @cleanup_thread = schedule_cleanup
end

Instance Method Details

#shutdownObject



40
41
42
43
44
45
# File 'lib/wayback_machine_downloader.rb', line 40

def shutdown
  @cleanup_thread&.exit
  drain_pool do |entry|
    safe_finish(entry[:http]) if entry
  end
end

#with_connectionObject



31
32
33
34
35
36
37
38
# File 'lib/wayback_machine_downloader.rb', line 31

def with_connection
  entry = acquire_connection
  begin
    yield entry[:http]
  ensure
    release_connection(entry)
  end
end