JobQueueService

JobQueueService

The JobQueueService is used to create new JobQueue instances and access existing jobs.

Example

// A service which transcodes video files
class VideoTranscoderService {

  private jobQueue: JobQueue<{ videoId: string; }>;

  async onModuleInit() {
    // The JobQueue is created on initialization
    this.jobQueue = await this.jobQueueService.createQueue({
      name: 'transcode-video',
      process: async job => {
        return await this.transcodeVideo(job.data.videoId);
      },
    });
  }

  addToTranscodeQueue(videoId: string) {
    this.jobQueue.add({ videoId, })
  }

  private async transcodeVideo(videoId: string) {
    // e.g. call some external transcoding service
  }

}

Signature

class JobQueueService implements OnModuleDestroy {
  constructor(configService: ConfigService)
  async createQueue(options: CreateQueueOptions<Data>) => Promise<JobQueue<Data>>;
  async start() => Promise<void>;
  getJobQueues() => GraphQlJobQueue[];
}

Implements

  • OnModuleDestroy

Members

constructor

method
type:
(configService: ConfigService) => JobQueueService

createQueue

async method
type:
(options: CreateQueueOptions<Data>) => Promise<JobQueue<Data>>
Configures and creates a new JobQueue instance.

start

async method
type:
() => Promise<void>

getJobQueues

method
type:
() => GraphQlJobQueue[]
Returns an array of { name: string; running: boolean; } for each registered JobQueue.