Browse Source

feat(core): Add config for enabling/disabling worker health check

Closes #1112
Michael Bromley 4 years ago
parent
commit
f6205663ae

+ 1 - 0
packages/core/src/config/default-config.ts

@@ -144,6 +144,7 @@ export const defaultConfig: RuntimeVendureConfig = {
     jobQueueOptions: {
         jobQueueStrategy: new InMemoryJobQueueStrategy(),
         activeQueues: [],
+        enableWorkerHealthCheck: false,
     },
     customFields: {
         Address: [],

+ 14 - 0
packages/core/src/config/vendure-config.ts

@@ -743,6 +743,20 @@ export interface JobQueueOptions {
      * If its empty all queues will be run
      */
     activeQueues?: string[];
+    /**
+     * @description
+     * When set to `true`, a health check will be run on the worker. This is done by
+     * adding a `check-worker-health` job to the job queue, which, when successfully
+     * processed by the worker, indicates that it is healthy.
+     *
+     * **Important Note:** This health check is unreliable and can be affected by
+     * existing long running jobs, see [this issue](https://github.com/vendure-ecommerce/vendure/issues/1112)
+     * for further details. For this reason, the health check will be removed entirely in the next major version.
+     *
+     * @since 1.3.0
+     * @default false
+     */
+    enableWorkerHealthCheck?: boolean;
 }
 
 /**

+ 2 - 2
packages/core/src/health-check/health-check.module.ts

@@ -25,8 +25,8 @@ export class HealthCheckModule {
     ) {
         // Register the default health checks for database and worker
         this.healthCheckRegistryService.registerIndicatorFunction([() => this.typeOrm.pingCheck('database')]);
-        const { jobQueueStrategy } = this.configService.jobQueueOptions;
-        if (isInspectableJobQueueStrategy(jobQueueStrategy)) {
+        const { enableWorkerHealthCheck, jobQueueStrategy } = this.configService.jobQueueOptions;
+        if (enableWorkerHealthCheck && isInspectableJobQueueStrategy(jobQueueStrategy)) {
             this.healthCheckRegistryService.registerIndicatorFunction([() => this.worker.isHealthy()]);
         }
     }

+ 2 - 2
packages/core/src/health-check/worker-health-indicator.ts

@@ -17,8 +17,8 @@ export class WorkerHealthIndicator extends HealthIndicator implements OnModuleIn
     }
 
     async onModuleInit() {
-        const { jobQueueStrategy } = this.configService.jobQueueOptions;
-        if (isInspectableJobQueueStrategy(jobQueueStrategy)) {
+        const { jobQueueStrategy, enableWorkerHealthCheck } = this.configService.jobQueueOptions;
+        if (enableWorkerHealthCheck && isInspectableJobQueueStrategy(jobQueueStrategy)) {
             this.queue = await this.jobQueueService.createQueue({
                 name: WORKER_HEALTH_QUEUE_NAME,
                 process: async job => {