adonisjs / lucid

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

Report feedback error #1029

Open NathaelB opened 6 months ago

NathaelB commented 6 months 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

RomainLanz commented 2 months ago

Hey @NathaelB! 👋🏻

Since you posted your message, a health check system was officially released.

Does that fixes your issue? 📚 https://docs.adonisjs.com/guides/digging-deeper/health-checks#dbcheck