bull-di
v1.0.6
Published
Bull queue with DI
Downloads
16
Maintainers
Readme
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;