Queue

A queue service to run tasks in the background or schedule them to run at a certain time.

Available:

  • Bee

  • Bull

  • Kue

  • Fake

Jobs:

The structure is simple, it should be a class with a static key method to retrieve its key and a public handle method to perform the task. All other OOP features for distributing logic are allowed.

export class Example {
  public static get key(): Capitalize<string> {
    return 'Example';
  }

  public async handle({ data }: { data: { message: string } }): Promise<void> {
    return console.log(`I have a message for you: ${data.message}`);
  }
}

Methods:

Execute: Runs a task in the background, if it fails it repeats a certain number of times.

await this.queueProvider.execute<{ message: string }>(
  Example.key,
  {
    message: 'This is the message',
  },
  3,
);

Schedule: Schedules a task in the background, if it fails it repeats a certain number of times.

await this.queueProvider.schedule<{ message: string }>(
  Example.key,
  {
    message: 'This is the message',
  },
  '30min',
  3,
);

Last updated