adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.02k stars 189 forks source link

Report feedback error #1029

Open NathaelB opened 1 month ago

NathaelB commented 1 month ago

Package version

^20.5.1

Describe the bug

I created a health module on my api and initialised a service.

At first I used a select * from users limit 1; to see if the connection on my postgres was good. In the meantime I learned about the await db.manager.report().

The report seems to work at first glance, but when I tried to check my health ready when my postgres container was switched off, I still had the connection: All connections are healthy

import db from '@adonisjs/lucid/services/db'
import HealthException, { HealthErrors } from '#apps/shared/exceptions/health_exception'

export default class HealthService {
  async checkDb(): Promise<{ displayName: string, health: { healthy: boolean, message: string }, meta: any[] }> {
    return db.manager.report()
  }

  async sendReport() {
    try {
      const reportDb = await this.checkDb()
      return {
        healthy: reportDb.health.healthy,
        report: {

          appKey: {
            displayName: 'App Key Check',
            health: {
              healthy: true,
            },
          },
          db: reportDb
        },
      }
    } catch (e) {
      throw e
    }
  }
}

Reproduction repo

No response