[go: up one dir, main page]

Skip to content

KABBOUCHI/adonis-bull-queue

 
 

Repository files navigation

@setten/bull-queue

Download Version License

@setten/bull-queue is a queue system based on BullMQ for AdonisJS.

Note

You must have a Redis server running on your machine.


Getting Started

This package is available in the npm registry.

npm install @setten/bull-queue

Next, configure the package by running the following command.

node ace configure @setten/bull-queue

and... Voilà!

Usage

The Queue provider gives you access to the dispatch method. It will dispatch the linked job to the queue with the given payload.

import { Queue } from '@ioc:Setten/Queue';

Queue.dispatch('App/Jobs/RegisterStripeCustomer', {...});


Queue.dispatch('App/Jobs/RegisterStripeCustomer', {...}, {
  queueName: 'stripe',
});

Your Job can be stored anywhere in your application and is dispatched using its full path. It must have a handle method that will be executed by the queue worker.

// app/Jobs/RegisterStripeCustomer.ts

export type RegisterStripeCustomerPayload = {
  userId: string
}

export default class RegisterStripeCustomer {
  public async handle(payload: RegisterStripeCustomerPayload) {
    // ...
  }
}

Run the queue worker with the following ace command:

node ace queue:listen

# or

node ace queue:listen --queue=stripe

Once done, you will see the message Queue processing started.

Typings

You can define the payload's type for a given job inside the contracts/queue.ts file.

import type { RegisterStripeCustomerPayload } from 'App/Jobs/RegisterStripeCustomer'

declare module '@ioc:Setten/Queue' {
  interface JobsList {
    'App/Jobs/RegisterStripeCustomer': RegisterStripeCustomerPayload;
  }
}

About

Queue system based on BullMQ for AdonisJS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%