Module: Sequel::ConnectionExpiration
- Defined in:
- lib/sequel/extensions/connection_expiration.rb
Defined Under Namespace
Classes: Retry
Instance Attribute Summary collapse
-
#connection_expiration_random_delay ⇒ Object
The maximum number of seconds that will be added as a random delay to the expiration timeout Defaults to 0 seconds (no random delay).
-
#connection_expiration_timeout ⇒ Object
The number of seconds that need to pass since connection creation before expiring a connection.
Class Method Summary collapse
-
.extended(pool) ⇒ Object
Initialize the data structures used by this extension.
Instance Attribute Details
#connection_expiration_random_delay ⇒ Object
The maximum number of seconds that will be added as a random delay to the expiration timeout Defaults to 0 seconds (no random delay).
44 45 46 |
# File 'lib/sequel/extensions/connection_expiration.rb', line 44 def connection_expiration_random_delay @connection_expiration_random_delay end |
#connection_expiration_timeout ⇒ Object
The number of seconds that need to pass since connection creation before expiring a connection. Defaults to 14400 seconds (4 hours).
40 41 42 |
# File 'lib/sequel/extensions/connection_expiration.rb', line 40 def connection_expiration_timeout @connection_expiration_timeout end |
Class Method Details
.extended(pool) ⇒ Object
Initialize the data structures used by this extension.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sequel/extensions/connection_expiration.rb', line 47 def self.extended(pool) case pool.pool_type when :threaded, :sharded_threaded, :timed_queue, :sharded_timed_queue nil else raise Error, "cannot load connection_expiration extension if using single or sharded_single connection pool (or other unsupported connection pool)" end pool.instance_exec do sync do @connection_expiration_timestamps ||= {} @connection_expiration_timeout ||= 14400 @connection_expiration_random_delay ||= 0 # Record an expiration timestamp for any connections that already # exist in the pool, so that a connection opened before the extension # was loaded (e.g. via Sequel.connect) will eventually be expired. register = method(:register_connection_expiration_time) case pool_type when :timed_queue, :sharded_timed_queue register_queued_connections = lambda do |queue| conns = [] while conn = queue.pop(timeout: 0) conns << conn end conns.each do |conn| queue.push(register_connection_expiration_time(conn)) end end end case pool_type when :threaded @available_connections.each(®ister) @allocated.each_value(®ister) when :sharded_threaded @available_connections.each_value{|conns| conns.each(®ister)} @allocated.each_value{|threads| threads.each_value(®ister)} when :timed_queue register_queued_connections.call(@queue) @allocated.each_value(®ister) else # when :sharded_timed_queue @queues.each_value(®ister_queued_connections) @allocated.each_value{|threads| threads.each_value(®ister)} end end end end |