taskforcesh / bullmq

BullMQ - Message Queue and Batch processing for NodeJS and Python based on Redis
https://bullmq.io
MIT License
5.89k stars 380 forks source link

Requesting Guidance on Configuring Lock Duration and Max Stalled Count in Bull Configuration. #2501

Open Jayshri-Intlon opened 5 months ago

Jayshri-Intlon commented 5 months ago

Issue:

In my project, I have a job queue named 'entityCreateQueue' that runs periodically to complete certain tasks within a specific timeframe. However, I've noticed that sometimes it generates duplicates shortly after completing a task. To address this issue, I've encountered recommendations to set a 'lockDuration' with a larger value and a 'maxStalledCount' to 0, as mentioned in the references I've consulted. However, I'm uncertain about where and how to configure these settings within my Bull queue in the Nest JS application.

Reference:

Code snippet

import { RedisConfigService } from '../app/config/redis-config.service';
import type { RegisterQueueOptions } from '@nestjs/bullmq';
import { BullModule } from '@nestjs/bullmq';

const redisConfigService = new RedisConfigService(process.env);
const bullOptions: RegisterQueueOptions = {
  name: 'entityCreateQueue',
  connection: redisConfigService.bullConfig.connection,
};

@Module({
  imports: [
    TypeOrmModule.forFeature([Entity, EntityStatusHistory]),
    BullModule.registerQueue(bullOptions),
  ],
sinasalek commented 4 months ago

There is almost no data regarding this issue with is very strange!

manast commented 3 months ago

Not sure what the issue is here. So, a job that is not keeping the event loop busy will not have any issues, you should not change the lockDuration setting unless you are very aware of why you need to do it. Most likely what you need to do is make sure your job is not keeping the event loop busy for more than a few milliseconds. This is documented in several places, also it is a standard NodeJS good practice: https://blog.searchmyexpert.com/nodejs-event-loop/