Skip to content

Commit

Permalink
fix: readiness prob
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimanzurrashid committed Oct 1, 2022
1 parent 6798dbe commit f47f607
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const logger = Pino();
}

container.register('PGPool', { useValue: new Pool() });
container.register('PGClient', { useValue: new Client() });
container.register('PGClientFactory', { useValue: () => new Client() });
container.register('Logger', { useValue: logger });
})();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('HealthReadinessHandler', () => {
};

const handler = new HealthReadinessHandler(
postgreSQL as unknown as Client,
() => postgreSQL as unknown as Client,
jest.fn() as unknown as Logger
);

Expand Down Expand Up @@ -57,7 +57,7 @@ describe('HealthReadinessHandler', () => {
};

const handler = new HealthReadinessHandler(
postgreSQL as unknown as Client,
() => postgreSQL as unknown as Client,
logger as unknown as Logger
);

Expand Down
9 changes: 5 additions & 4 deletions src/features/health-readiness/health-readiness-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject, injectable } from 'tsyringe';
import { Client } from 'pg';
import type { Client } from 'pg';
import { Logger } from 'pino';

import handles from '../../infrastructure/handles';
Expand All @@ -13,16 +13,17 @@ export default class HealthReadinessHandler extends Handler<
boolean
> {
constructor(
@inject('PGClient') private readonly _pg: Client,
@inject('PGClientFactory') private readonly _pgFactory: () => Client,
@inject('Logger') private readonly _logger: Logger
) {
super();
}

async handle(request: HealthReadinessRequest): Promise<boolean> {
const pg = this._pgFactory();
try {
await this._pg.connect();
await this._pg.end();
await pg.connect();
await pg.end();

return true;
} catch (e) {
Expand Down

0 comments on commit f47f607

Please sign in to comment.