plugin.ts 874 B

123456789101112131415161718192021222324252627
  1. import { PubSub } from '@google-cloud/pubsub';
  2. import { PluginCommonModule, Type, VendurePlugin } from '@vendure/core';
  3. import { PUB_SUB_OPTIONS } from './constants';
  4. import { PubSubOptions } from './options';
  5. import { PubSubJobQueueStrategy } from './pub-sub-job-queue-strategy';
  6. @VendurePlugin({
  7. imports: [PluginCommonModule],
  8. providers: [
  9. { provide: PUB_SUB_OPTIONS, useFactory: () => PubSubPlugin.options },
  10. { provide: PubSub, useFactory: () => new PubSub() },
  11. ],
  12. configuration: config => {
  13. config.jobQueueOptions.jobQueueStrategy = new PubSubJobQueueStrategy();
  14. return config;
  15. },
  16. compatibility: '^2.0.0',
  17. })
  18. export class PubSubPlugin {
  19. private static options: PubSubOptions;
  20. static init(options: PubSubOptions): Type<PubSubPlugin> {
  21. this.options = options;
  22. return PubSubPlugin;
  23. }
  24. }