Class: Sequel::ShardedSingleFailoverConnectionPool
- Inherits:
-
ShardedSingleConnectionPool
- Object
- ShardedSingleConnectionPool
- Sequel::ShardedSingleFailoverConnectionPool
- Defined in:
- lib/sequel/connection_pool/sharded_single_failover.rb
Class Attribute Summary collapse
-
.on_disconnect ⇒ Object
Returns the value of attribute on_disconnect.
Instance Method Summary collapse
-
#hold(server = :default, &block) ⇒ Object
Yields the connection to the supplied block for the given server.
-
#initialize(db, opts = OPTS) ⇒ ShardedSingleFailoverConnectionPool
constructor
A new instance of ShardedSingleFailoverConnectionPool.
- #pool_type ⇒ Object
Constructor Details
#initialize(db, opts = OPTS) ⇒ ShardedSingleFailoverConnectionPool
Returns a new instance of ShardedSingleFailoverConnectionPool.
5 6 7 8 9 |
# File 'lib/sequel/connection_pool/sharded_single_failover.rb', line 5 def initialize(db, opts = OPTS) super @pool_stick_timeout = opts[:pool_stick_timeout] || 15 @pool_retry_count = opts[:pool_retry_count] || 5 end |
Class Attribute Details
.on_disconnect ⇒ Object
Returns the value of attribute on_disconnect.
12 13 14 |
# File 'lib/sequel/connection_pool/sharded_single_failover.rb', line 12 def on_disconnect @on_disconnect end |
Instance Method Details
#hold(server = :default, &block) ⇒ Object
Yields the connection to the supplied block for the given server. This method simulates the ConnectionPool#hold API.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sequel/connection_pool/sharded_single_failover.rb', line 17 def hold(server=:default, &block) if server == :read_only && @stuck_at && Time.now.to_i - @stuck_at.to_i >= @pool_stick_timeout unstick(:read_only) end super(server, &block) rescue Sequel::DatabaseDisconnectError, Sequel::DatabaseConnectionError => e if server == :read_only && !@db.in_transaction?(server: :read_only) self.class.on_disconnect.call(e, self) if self.class.on_disconnect disconnect_server(server) @conns[server] = nil stick if @stuck_times >= @pool_retry_count unstick(server) raise end hold(server, &block) else raise end end |
#pool_type ⇒ Object
44 45 46 |
# File 'lib/sequel/connection_pool/sharded_single_failover.rb', line 44 def pool_type :sharded_single_failover end |