Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*drained* event emitting on intermittent basis #1121

Closed
obihill opened this issue Mar 8, 2022 · 1 comment · Fixed by #1123
Closed

*drained* event emitting on intermittent basis #1121

obihill opened this issue Mar 8, 2022 · 1 comment · Fixed by #1123
Labels

Comments

@obihill
Copy link

obihill commented Mar 8, 2022

Description

The drained event is emitting intermittently even when the queue is empty and idle.

Minimal, Working Test code to reproduce the issue.

# .env
DB_HOST="127.0.0.1"
DB_PORT=6379
// queue.js

import 'dotenv/config';
import { Queue } from 'bullmq';

const config = {connection: {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT
}}; 
const queue = new Queue('Birds', config);

queue.add('pigeon', {color: ['brown', 'grey']});
queue.add('swift', {color: ['brown', 'black']});
queue.add('lark', {color: ['brown', 'black']});
queue.add('finch', {color: ['yellow', 'black', 'green']});

await queue.close();
// worker.js

import 'dotenv/config';
import { Worker } from 'bullmq';

const config = {connection: {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT
}}; 
const worker = new Worker('Birds', async function(job){
    console.log('--WORKER--')
    console.log('job.id =', job.id);
    console.log('job.name =', job.name);
    console.log('job.data =', job.data);
    console.log('---');
}, config);

// monitor.js

import 'dotenv/config';
import { QueueEvents } from 'bullmq';

const config = {connection: {
    host: process.env.DB_HOST,
    port: process.env.DB_PORT
}}; 

const queueEvents = new QueueEvents('Birds', config);

queueEvents.on('completed', function(job){
    console.log('--ON-JOB-COMPLETED--')
    console.log('job.id =', job.id);
    console.log('job.name =', job.name);
    console.log('---');
});

queueEvents.on('drained', function(){
    console.log('--ON-QUEUE-COMPLETED--');
});

  1. Open three terminal windows
  2. Run node queue, node worker, and node monitor in corresponding windows
  3. Notice on the third window [monitor] that the console.log message is emitted intermittently

I understand that the drained event is supposed to emit when there are no more tasks to process. Should this not happen once for each salvo of jobs i.e. after active jobs, and not repeatedly on an idle and empty queue?

Bull version

1.76.1

Additional information

github-actions bot pushed a commit that referenced this issue Mar 10, 2022
## [1.76.3](v1.76.2...v1.76.3) (2022-03-10)

### Bug Fixes

* **drained:** emit event only once when queue has drained the waiting list ([#1123](#1123)) fixes [#1121](#1121) ref [#1070](#1070) ([b89b4e8](b89b4e8))
@github-actions
Copy link

🎉 This issue has been resolved in version 1.76.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant