I'm trying to implement a Minon worker that needs access to a database via DBI.
Here is the code that I use :
use Mojolicious::Lite;
plugin Minion => { SQLite => 'sqlite:test.db' };
helper dbh => sub {
my $dbh = DBI->connect("dbi:Oracle:somedb", 'someuser', 'somepasswd');
return $dbh;
};
app->minion->add_task( mytask => \&mytask );
sub mytest {
my ($job, $arg) = @_;
my $dbh = $job->app->dbh;
my ($time) = $dbh->selectrow_array('select sysdate from dual');
$job->finish('documentation generation done');
}
app->start;
The problem that I have, is that the connection to the database is closed/reopened on every task execution, which is very slow, and not the behavior that I expect.
Using the same dbh helper on a Mojolicious app (not within minon task) works fine and opens one connection per worker.
I've already tried various setups with DBI's InactiveDestroy parameter or using DBIx::Connector but no success so far.