Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor readiness service to receive indicator list #4908

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { HealthIndicatorResult, HealthIndicatorStatus } from '@nestjs/terminus';
import { setTimeout } from 'timers/promises';

import { Worker } from '../bull-mq';

import { setTimeout } from 'timers/promises';
import { QueueHealthIndicator } from '../../health/queue-health-indicator.service';
import { IHealthIndicator } from '../../health';

export interface INovuWorker {
readonly DEFAULT_ATTEMPTS: number;
gracefulShutdown: () => Promise<void>;
Expand All @@ -20,7 +22,7 @@ const LOG_CONTEXT = 'ReadinessService';
export class ReadinessService {
constructor(
@Inject('QUEUE_HEALTH_INDICATORS')
private healthIndicators: QueueHealthIndicator[]
private healthIndicators: IHealthIndicator[]
) {}

async areQueuesEnabled(): Promise<boolean> {
Expand All @@ -37,10 +39,7 @@ export class ReadinessService {
}

Logger.warn(
{
attempt: i,
message: `Some health indicator returned false when checking if queues are enabled ${i}/${retries}`,
},
`Some health indicator returned false when checking if queues are enabled ${i}/${retries}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a small fix, looks like the new relic is not able to print messages of a warning log level, fixed it as a tmp solution.

LOG_CONTEXT
);

Expand All @@ -56,7 +55,11 @@ export class ReadinessService {
this.healthIndicators.map((health) => health.isHealthy())
);

return healths.every((health) => !!health === true);
const statuses = healths.map(
(health: HealthIndicatorResult) => Object.values(health)[0].status
);

return statuses.every((status: HealthIndicatorStatus) => status === 'up');
} catch (error) {
Logger.error(
error,
Expand Down
Loading