teableio/teable

View on GitHub
apps/nestjs-backend/src/event-emitter/event-job/fallback/local-queue.provider.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { getQueueToken } from '@nestjs/bullmq';
import type { Provider } from '@nestjs/common';
import { getRandomString } from '@teable/core';
import type { JobsOptions } from 'bullmq';
import { localQueueEventEmitter } from './event-emitter';

export const createLocalQueueProvider = (queueName: string): Provider => ({
  provide: getQueueToken(queueName),
  useFactory: async () => {
    return {
      add: (name: string, data: unknown, opts?: JobsOptions) => {
        localQueueEventEmitter.emit('handle-listener', {
          id: getRandomString(10),
          name,
          data,
          opts,
          queueName,
        });
      },
    };
  },
});