Class: PgEventstore::Connection
- Inherits:
-
Object
- Object
- PgEventstore::Connection
- Defined in:
- lib/pg_eventstore/connection.rb
Instance Attribute Summary collapse
- #pool_size ⇒ Integer writeonly
- #pool_timeout ⇒ Integer writeonly
- #uri ⇒ String writeonly
Instance Method Summary collapse
-
#initialize(uri:, pool_size: 5, pool_timeout: 5) ⇒ Connection
constructor
A new instance of Connection.
- #shutdown ⇒ void
-
#with {|connection| ... } ⇒ Object
A shorthand from ConnectionPool#with.
Constructor Details
#initialize(uri:, pool_size: 5, pool_timeout: 5) ⇒ Connection
Returns a new instance of Connection.
56 57 58 59 60 61 |
# File 'lib/pg_eventstore/connection.rb', line 56 def initialize(uri:, pool_size: 5, pool_timeout: 5) @uri = uri @pool_size = pool_size @pool_timeout = pool_timeout init_pool end |
Instance Attribute Details
#pool_size=(value) ⇒ Integer
46 47 48 |
# File 'lib/pg_eventstore/connection.rb', line 46 def pool_size @pool_size end |
#pool_timeout=(value) ⇒ Integer
49 50 51 |
# File 'lib/pg_eventstore/connection.rb', line 49 def pool_timeout @pool_timeout end |
#uri=(value) ⇒ String
43 44 45 |
# File 'lib/pg_eventstore/connection.rb', line 43 def uri @uri end |
Instance Method Details
#shutdown ⇒ void
This method returns an undefined value.
82 83 84 |
# File 'lib/pg_eventstore/connection.rb', line 82 def shutdown @pool.shutdown(&:close) end |
#with {|connection| ... } ⇒ Object
A shorthand from ConnectionPool#with.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/pg_eventstore/connection.rb', line 66 def with(&_blk) should_retry = true @pool.with do |conn| yield conn rescue PG::ConnectionBad, PG::UnableToSend # Recover a connection after fork or when we lost a connection to PostgreSQL. We retry only once and without any # delay. conn.sync_reset raise unless should_retry should_retry = false retry end end |