Open bonesoul opened 5 years ago
Hey
Looks like you're adding the ready
event listener after you do an async operation let tasks = await glob('src/tasks/definitions/**/*.js');
which means you may well miss the event.
If you add the listener first, then you should avoid the race condition.
Hey too, I am struggling too much on missing the ready event in tests cases.
For this kind of event, firing only once at start and useful only as a condition of further operations, can someone list the downsize of using a stateful event handler instead of an event easy to miss ?
I'm talking about a setup like this :
agenda.isReady = false;
agenda.onReady = (listener: (...args: any[]) => void) => {
if (agenda.isReady) return listener();
agenda.on('ready', () => { agenda.isReady = true; listener(); });
};
This way if ready
event is already passed, handler synchronously execute.
Could be made a promise auto-resolving instead as well.
Edit: I checked the internals, turns out there is a _ready
promise that I can use. This is so much reliable.
The ready
event isn't even necessary if you use agenda.mongo(...)
and handle the connection yourself :)
Hi,
turns out there is a
_ready
promise that I can use. This is so much reliable.
Definitely a hidden gem indeed, thank you so much for having shared it!
using agenda 2.0.2 on ubuntu 14.04
my code;
and here is the debug output
clearly
winston.info('[TASK_MANAGER] scheduled jobs..');
line is not fired...though it does on my windows setup.