Module: DatabaseHealthChecker
- Defined in:
- lib/admin/postgres_check.rb
Class Method Summary collapse
- .active_db_connection ⇒ Object
- .get_and_put_operations ⇒ Object
- .postgres_up ⇒ Object
- .user_account_exists ⇒ Object
Class Method Details
.active_db_connection ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/admin/postgres_check.rb', line 43 def self.active_db_connection # Test 3: Check Connection if ActiveRecord::Base.connection.active? true else Rails.logger.info({ message: 'ARGO CD UPGRADE - PG TEST: Connection is NOT active.' }) false # Return false if the connection is not active end end |
.get_and_put_operations ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/admin/postgres_check.rb', line 19 def self.get_and_put_operations # Test 2: Perform GET and PUT operations and roll back transaction # so the changes aren't persisted. UserAccount.transaction do icn = 'abc123' UserAccount.create!(icn:) user = UserAccount.find_by(icn:) unless user Rails.logger.info({ message: "ARGO CD UPGRADE - PG TEST: No UserAccount found with ICN #{icn}" }) raise ActiveRecord::Rollback end user.update(icn: 'xyz789') raise ActiveRecord::Rollback end true rescue => e Rails.logger.info( { message: "ARGO CD UPGRADE - PG TEST: Error in GET/PUT operations. Error: #{e.}" } ) false # Return false if connectivity issues are detected end |
.postgres_up ⇒ Object
4 5 6 |
# File 'lib/admin/postgres_check.rb', line 4 def self.postgres_up user_account_exists && get_and_put_operations && active_db_connection end |
.user_account_exists ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/admin/postgres_check.rb', line 8 def self.user_account_exists # Test 1: Access Records UserAccount.exists? true # Return true if no exception occurs rescue => e Rails.logger.info( { message: "ARGO CD UPGRADE - PG TEST: Failed to access UserAccount. Error: #{e.}" } ) false end |