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

No event fired when Job added to Queue with no Worker #122

Closed
rhinodavid opened this issue Jan 29, 2020 · 12 comments
Closed

No event fired when Job added to Queue with no Worker #122

rhinodavid opened this issue Jan 29, 2020 · 12 comments

Comments

@rhinodavid
Copy link
Contributor

rhinodavid commented Jan 29, 2020

Team,

I'm not sure if this is intended behavior or not, but I have a listener on a QueueEvents instance and I am trying to execute an event handler when a Job is added to the associated Queue. If there is a Worker instance assigned to the queue then a waiting event is fired from the QueueEvents instance when a new Job is added. However, with no Worker assigned, there is no event fired as far as I can tell. I threw the kitchen sink at it and am listening for the following on the QueueEvents instance:

    "global:waiting",
    "",
    "active",
    "wait",
    "waiting",
    "paused",
    "resumed",
    "active",
    "id",
    "delayed",
    "priority",
    "stalled-check",
    "completed",
    "failed",
    "stalled",
    "repeat",
    "limiter",
    "drained",
    "progress",
    "meta",
    "events",
    "delay"
@manast
Copy link
Contributor

manast commented Jan 29, 2020

thats definitively not intended. However I do not understand how having a worker or not can affect it, could you paste a small test case that reproduces this?

@rhinodavid
Copy link
Contributor Author

rhinodavid commented Jan 30, 2020 via email

@rhinodavid
Copy link
Contributor Author

rhinodavid commented Jan 30, 2020

Ok... well I've done a ton of troubleshooting and this is super weird. So it turns out I only have this problem if there is no worker AND I use the reusable connection pattern from the docs:

import { Queue, Worker } from 'bullmq';
import IORedis from 'ioredis';

const connection = new IORedis();

// Reuse the redis instance
const myQueue = new Queue('myqueue', { connection });
const myWorker = new Worker('myworker', { connection });

So I dug and dug and it seems like a problem with the options. If I set the Redis instance to be the client like so, it works fine. (EDIT: Read further.. it was not fine)

// ....
const client = new IORedis("redis://127.0.0.1:6379");

const myQueue = new Queue('myqueue', { client });
const myWorker = new Worker('myworker', { client });

🤷🏾‍♀️

@rhinodavid
Copy link
Contributor Author

Side note... from the example, don't the name of the Queue and the name of the Worker need to match?

If I name them different things, I don't get the event from the QueueEvents when a new job is added.

@rhinodavid
Copy link
Contributor Author

Ok so now.. it seems that the reason it works when the key is set to client is because that key isn't valid and the default logic is being invoked.

@manast
Copy link
Contributor

manast commented Jan 31, 2020

if you are able to write a minimal test case that I can run and demonstrates the issue I can debug it myself.

@andrisi
Copy link

andrisi commented Mar 7, 2021

so is there an event that is fired when a job is added?

@manast
Copy link
Contributor

manast commented Mar 7, 2021

@andrisi there is an event called "waiting" that is emitted when the job is added to the waiting list.

@andrisi
Copy link

andrisi commented Mar 8, 2021

Ah, ok. And that is never fired later on I presume. Failed jobs get stalled, but not in the waiting list, right?

@manast
Copy link
Contributor

manast commented Mar 8, 2021

If they are stalled they will go back to the waiting list and emit the "waiting" event again.

@andrisi
Copy link

andrisi commented Mar 9, 2021

Then perhaps an "added" event would be helpful sometimes later on so clients could act on it without houskeepking.

@roggervalf
Copy link
Collaborator

Hey guys, could you please try last version, added event was added xd

manast pushed a commit that referenced this issue Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants