plugin.ts 845 B

1234567891011121314151617181920212223242526
  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. })
  17. export class PubSubPlugin {
  18. private static options: PubSubOptions;
  19. static init(options: PubSubOptions): Type<PubSubPlugin> {
  20. this.options = options;
  21. return PubSubPlugin;
  22. }
  23. }