Class: ConnectionPool
- Inherits:
-
Object
- Object
- ConnectionPool
- 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
-
#initialize(size) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #shutdown ⇒ Object
- #with_connection(&block) ⇒ Object
Constructor Details
#initialize(size) ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
22 23 24 25 26 27 |
# File 'lib/wayback_machine_downloader.rb', line 22 def initialize(size) @size = size @pool = Concurrent::Map.new @creation_times = Concurrent::Map.new @cleanup_thread = schedule_cleanup end |
Instance Method Details
#shutdown ⇒ Object
38 39 40 41 42 43 |
# File 'lib/wayback_machine_downloader.rb', line 38 def shutdown @cleanup_thread&.exit @pool.each_value { |conn| conn.finish if conn&.started? } @pool.clear @creation_times.clear end |
#with_connection(&block) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/wayback_machine_downloader.rb', line 29 def with_connection(&block) conn = acquire_connection begin yield conn ensure release_connection(conn) end end |