Your $dbh is only returned from the helper and not stored anywhere, so it disconnects as soon as it goes out of scope. Try declaring `my $dbh` in the global scope or using the `state` feature (roughly equivalent). A Mojo::SQLite object would be preferable to store over the dbh itself. See an example here: https://metacpan.org/source/DBOOK/Mojo-SQLite-0.021/examples/blog/lib/Blog.pm
On Thu, Jun 16, 2016 at 4:53 AM, Yves <[email protected]> wrote: > 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. > > -- > You received this message because you are subscribed to the Google Groups > "Mojolicious" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/mojolicious. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
