Преглед изворни кода

chore(job-queue-plugin): Create scaffold for redis job buffer storage

Michael Bromley пре 4 година
родитељ
комит
e2e65b4011

+ 32 - 0
packages/job-queue-plugin/src/bullmq/redis-job-buffer-storage-strategy.ts

@@ -0,0 +1,32 @@
+import { Injector, Job, JobBufferStorageStrategy } from '@vendure/core';
+import Redis, { Cluster, RedisOptions } from 'ioredis';
+
+import { BULLMQ_PLUGIN_OPTIONS } from './constants';
+import { BullMQPluginOptions } from './types';
+
+export class RedisJobBufferStorageStrategy implements JobBufferStorageStrategy {
+    private redis: Redis.Redis | Redis.Cluster;
+
+    init(injector: Injector) {
+        const options = injector.get<BullMQPluginOptions>(BULLMQ_PLUGIN_OPTIONS);
+        if (options.connection instanceof Redis) {
+            this.redis = options.connection;
+        } else if (options.connection instanceof Cluster) {
+            this.redis = options.connection;
+        } else {
+            this.redis = new Redis(options.connection as RedisOptions);
+        }
+    }
+
+    async add(processorId: string, job: Job<any>): Promise<Job<any>> {
+        return job;
+    }
+
+    async bufferSize(bufferIds?: string[]): Promise<{ [bufferId: string]: number }> {
+        throw new Error('Method not implemented.');
+    }
+
+    async flush(bufferIds?: string[]): Promise<{ [bufferId: string]: Array<Job<any>> }> {
+        throw new Error('Method not implemented.');
+    }
+}