Class: Philae::PostgreSQLProbe
- Inherits:
-
Object
- Object
- Philae::PostgreSQLProbe
- Defined in:
- lib/philae/pgsql_probe.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(name, connection_string) ⇒ PostgreSQLProbe
constructor
A new instance of PostgreSQLProbe.
Constructor Details
#initialize(name, connection_string) ⇒ PostgreSQLProbe
Returns a new instance of PostgreSQLProbe.
10 11 12 13 |
# File 'lib/philae/pgsql_probe.rb', line 10 def initialize(name, connection_string) @name = name @connection_string = connection_string end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/philae/pgsql_probe.rb', line 8 def name @name end |
Instance Method Details
#check ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/philae/pgsql_probe.rb', line 15 def check begin res = PG::Connection.ping(@connection_string) rescue return { healthy: false, comment: 'Unable to contact PostgreSQL' } end return { healthy: true, comment: '' } if res == PG::PQPING_OK # https://deveiate.org/code/pg/PG/Connection.html#method-c-ping reasons = { PG::PQPING_REJECT => 'server is alive but rejecting connections', PG::PQPING_NO_RESPONSE => 'could not establish connection', PG::PQPING_NO_ATTEMPT => 'connection not attempted (bad params)', } return { healthy: false, comment: "Ping to PostgreSQL failed with the following reason: #{reasons[res]}" } end |