A Mojolicious app w/ Minion::Backend::Pg always connects to PostgreSQL db on startup
augensalat opened this issue · comments
- Minion version: 10.22 and earlier
- Perl version: any
- Operating system: any
Problem description
When Minion::Backend::Pg
is instantiated inside Mojolicious::startup
(typically with Mojolicious::Plugin::Minion
) it connects to the PostgreSQL server to determine the server version.
This can cause trouble with application commands in isolated environments, i.e. in a CI/CD workflow where Minion and its database is not available and not needed.
The respective code is
minion/lib/Minion/Backend/Pg.pm
Lines 130 to 132 in f4bc5b2
Currrently I'm not able to find a reasonable workaround in my application code to avoid this immediate database connection attempt, see mojolicious/mojo#1886 .
Steps to reproduce the behavior
A Mojolicious application using Minion (with Mojolicious::Plugin::Minion
) fails at program start when the database is not accessible.
Basic application:
package MyApp;
use Mojo::Base 'Mojolicious', -signatures;
sub startup ($self) {
$self->plugin(Minion => {Pg => 'postgresql://user:pass@db/test'});
}
1;
my_app version
fails if the database is not accessible.
Expected behavior
my_app version
as any other command that is not related to Minion should work without the need to access the Minion Postgres database.
At least an option should exist to disable the check for the server version in the program startup.
$self->plugin(Minion => {Pg => $config->{database}, check_server_version => 0});
Actual behavior
$ my_app version
DBI connect('dbname=test;host=db','user',...) failed: could not translate host name "db" to address: Name does not resolve at /deps/local/lib/perl5/Mojo/Pg.pm line 73.
I kind of share your concern here - but what behavior would you expect if the app starts in production, but Minion has incorrect DB parameters and will never connect to DB? It might be harder / too late to diagnose comparing to failure to start service.
So, if your app is designed to work even if Minion is not able to connect - then you can just tolerate failure to load plugin at startup as well. Otherwise it is better if the failure happens sooner than later.
I'm testing a different strategy in minion.js, lets see how that works out.