According to the DBIx::Connector's documentation, if the process has been 
forked, it will always generate a new connection which is consistent with 
what I get when I tested it.

I understand that connections cannot be shared between forked processes, 
but I thought there would be a solution to have a pool of connections and 
then having the forked processes use them (one at a time). Is this even 
possible ? 

Maybe it's not Mojo/Minon specific, but I was curious if anybody else had a 
good (or at least better) solution.

On Thursday, 16 June 2016 17:14:55 UTC+2, Dan Book wrote:
>
> This would be handled by storing a Mojo::SQLite object instead of the dbh, 
> or a DBIx::Connector object as you mentioned before.
>
> On Thu, Jun 16, 2016 at 11:09 AM, Joel Berger <[email protected] 
> <javascript:>> wrote:
>
>> Minion tasks are performed in forks to protect the integrity of the 
>> worker process. Once the task is forked (or indeed after any fork) there 
>> must be a new connection to the database, this is the only possible way to 
>> do anything sane. 
>>
>>
>> On Thursday, June 16, 2016 at 3:53:03 AM UTC-5, Yves 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> 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.

Reply via email to