Parcourir la source

refactor(job-queue-plugin): Use new HealthCheckStrategy API for redis

Michael Bromley il y a 3 ans
Parent
commit
832cea7156

+ 3 - 5
packages/job-queue-plugin/src/bullmq/plugin.ts

@@ -1,7 +1,8 @@
-import { HealthCheckRegistryService, PluginCommonModule, VendurePlugin } from '@vendure/core';
+import { PluginCommonModule, VendurePlugin } from '@vendure/core';
 
 import { BullMQJobQueueStrategy } from './bullmq-job-queue-strategy';
 import { BULLMQ_PLUGIN_OPTIONS } from './constants';
+import { RedisHealthCheckStrategy } from './redis-health-check-strategy';
 import { RedisHealthIndicator } from './redis-health-indicator';
 import { RedisJobBufferStorageStrategy } from './redis-job-buffer-storage-strategy';
 import { BullMQPluginOptions } from './types';
@@ -101,6 +102,7 @@ import { BullMQPluginOptions } from './types';
     configuration: config => {
         config.jobQueueOptions.jobQueueStrategy = new BullMQJobQueueStrategy();
         config.jobQueueOptions.jobBufferStorageStrategy = new RedisJobBufferStorageStrategy();
+        config.systemOptions.healthChecks.push(new RedisHealthCheckStrategy());
         return config;
     },
     providers: [
@@ -119,8 +121,4 @@ export class BullMQJobQueuePlugin {
         this.options = options;
         return this;
     }
-
-    constructor(private registry: HealthCheckRegistryService, private redis: RedisHealthIndicator) {
-        registry.registerIndicatorFunction(() => this.redis.isHealthy('redis (job queue)'));
-    }
 }

+ 15 - 0
packages/job-queue-plugin/src/bullmq/redis-health-check-strategy.ts

@@ -0,0 +1,15 @@
+import { HealthIndicatorFunction } from '@nestjs/terminus';
+import { HealthCheckStrategy, Injector } from '@vendure/core';
+
+import { RedisHealthIndicator } from './redis-health-indicator';
+
+let indicator: RedisHealthIndicator;
+
+export class RedisHealthCheckStrategy implements HealthCheckStrategy {
+    init(injector: Injector) {
+        indicator = injector.get(RedisHealthIndicator);
+    }
+    getHealthIndicator(): HealthIndicatorFunction {
+        return () => indicator.isHealthy('redis (job queue)');
+    }
+}