Skip to content

Commit

Permalink
No dynamic status
Browse files Browse the repository at this point in the history
Why are you like this Nest :(
  • Loading branch information
codetheweb committed Mar 21, 2024
1 parent 863af95 commit 8ab9194
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Controller, Get, Injectable, Res} from '@nestjs/common';
import {Controller, Get, Injectable} from '@nestjs/common';
import pTimeout from 'p-timeout';
import * as db from 'zapatos/db';
import {FastifyReply} from 'fastify';
import {PoolService} from '~/pool/pool.service';

@Controller('health')
Expand All @@ -10,18 +9,18 @@ export class HealthController {
constructor(private readonly pool: PoolService) {}

@Get()
async getHealth(@Res() reply: FastifyReply) {
async getHealth() {
const [canConnectToDatabase, arePendingJobs, haveJobsErrored] = await Promise.all([
this.canConnectToDatabase(),
this.arePendingJobs(),
this.haveJobsErrored()
].map(async p => pTimeout(p, 2000).catch(() => -1)));

await reply.status(canConnectToDatabase ? 200 : 503).send({
return {
canConnectToDatabase,
arePendingJobs,
haveJobsErrored,
});
};
}

private async canConnectToDatabase() {
Expand Down

0 comments on commit 8ab9194

Please sign in to comment.