testing-job-queue-strategy.ts 745 B

1234567891011121314151617181920212223242526
  1. import { InMemoryJobQueueStrategy } from './in-memory-job-queue-strategy';
  2. import { Job } from './job';
  3. import { JobData } from './types';
  4. /**
  5. * @description
  6. * An in-memory {@link JobQueueStrategy} design for testing purposes.
  7. */
  8. export class TestingJobQueueStrategy extends InMemoryJobQueueStrategy {
  9. async prePopulate(jobs: Job[]) {
  10. for (const job of jobs) {
  11. await this.add(job);
  12. }
  13. }
  14. override async stop<Data extends JobData<Data> = object>(
  15. queueName: string,
  16. process: (job: Job<Data>) => Promise<any>,
  17. ) {
  18. const active = this.activeQueues.getAndDelete(queueName, process);
  19. if (!active) {
  20. return;
  21. }
  22. await active.stop(1_000);
  23. }
  24. }