0.0.4 • Published 2 years ago

adonis-jobs v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

adonis-jobs 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 adonis-jobs

Next, configure the package by running the following command.

node ace configure adonis-jobs

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', {...});

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

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;
  }
}
0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago