bull-di
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Bull DI

npm version downloads size Coverage Status dependencies Status type license Code style

Installation

npm i bull-di
# or
yarn add bull-di

Example

Root File

import { loadQueues, subscribeGracefulShutdown } from 'bull-di';

loadQueues({
   queues: [TestQueue],
   redisUrl: 'redis://localhost',
   events: true, // true if it`s worker
});
subscribeGracefulShutdown();

Job File

import Bull from 'bull';
import { Queue, QueueInterface } from 'bull-di';

type IInputData = { userId: string };
type IResultData = { completedAt: Date };

@Service()
@Queue('subscription-expire')
class SubscriptionExpireQueue extends QueueInterface<IInputData, IResultData> {
   @Inject(() => EmailService)
   public emailService!: EmailService;

   public async onProcess(job: Bull.Job<IInputData>) {
      await this.emailService.subscriptionExpire(job.data.userId);

      return {
         completedAt: new Date(),
      };
   }
   public async onFailure(err: Error) {
      console.log(err);
   }

   public async onCompleted(job: Bull.Job<IInputData>, res: IResultData) {
      console.log(`Subscription-expire userId:${job.data.userId} at:${res.completedAt}`);
   }
}

export default SubscriptionExpireQueue;

License

MIT

Package Sidebar

Install

npm i bull-di

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

12.6 kB

Total Files

9

Last publish

Collaborators

  • muzikanto