mojolicious / minion

:octopus: Perl high performance job queue
https://metacpan.org/release/Minion
Artistic License 2.0
221 stars 55 forks source link

Dequeue should use PubSub rather than listen directly #102

Closed rabbiveesh closed 3 years ago

rabbiveesh commented 3 years ago

Summary

Change the lines where Minion waits for a minion.job message to use Mojo::Pg::PubSub

Motivation

I've been seeing an issue, which seems to be a race condition. In my app, when I'm using Minion::Notifier, for some reason, I get a crash on the first time that a job gets dequed. This happens unless There's a job ready when I start Minion.

Here's the error message

Mojo::Reactor::Poll: I/O watcher failed: Can't use an undefined value as an ARRAY reference at /home/veesh/.plenv/versions/5.32.0/lib/perl5/site_perl/5.32.0/Mojo/Pg/PubSub.pm line 21.
at /home/veesh/.plenv/versions/5.32.0/lib/perl5/site_perl/5.32.0/Minion/Command/minion/worker.pm line 26.

What seems to be the cause is that once Mojo::Pg::PubSub's db method has been called, it sets up a listener which will respond to any notification which comes down. The death here comes from the fact that it tries to respond to the 'minion.job' channel, and dies b/c it doesn't have any callbacks for it.

kraih commented 3 years ago

Minion::Notifier is not officially supported i'm afraid.

kraih commented 3 years ago

Looks like this is not a Minion issue at all. https://github.com/mojolicious/mojo-pg/compare/76144a45eca3...0a895d120828