EndCustomFunctions when the batch finish

Alvaro Marin alvaro at hostalia.com
Fri Mar 4 10:24:53 GMT 2011


Hi Steve,

El 03/03/11 18:56, Steve Freegard escribió:
> Hi Alvaro,
>
> On 03/03/11 13:50, Alvaro Marin wrote:
>> The problem is that as I see in bin/Mailscanner, the End functions of
>> the "plugins" are called (with
>> MailScanner::Config::EndCustomFunctions()) only when the child has to be
>> restarted by "restartevery" variable:
>>
>> (time>=$StartTime && time<$RestartTime && !$BayesRebuild)
>>
>> The default value for "Restart Every" is 7200, so the MySQL connection
>> is kept open until that time without any use.
>>
>> So, Can I ad safely :
>>
>> # Close down all the user's custom functions
>> MailScanner::Config::EndCustomFunctions();
>>
>> inside that "while" to be executed every time that a Batch finish to
>> close the DB connection?
>>
>
> If you do that; your database handle will get destroyed and the next
> time DBPlug() is called it will fail to insert anything (and will return
> an error). It would also mean you'd have to hack MailScanner every time
> you upgrade it.
>
> If you want to connect/disconnect each time your code runs; then do
> everything in DBPlug() and not in the Init/End functions e.g.
>
> sub InitDBPlug {
> # Nothing here...
> }
>
> sub DBPlug {
> my $dbh = DBI->connect ...
> ...
> $dbh->commit;
> $dbh->disconnect;
> }
>
> sub EndDBPlug {
> # Nothing here either...
> }
>
> You only want to do database connect/disconnect in the Init/End
> functions if you want to keep your database connection for the life of
> the child process; this is more efficient if you are doing a lot of
> database work as connect/disconnect is expensive if you are doing it a lot.
>
> Hope that helps.
>
> Kind Regards,
> Steve.

Thank you for your answer. I was doing what you've said when you wrote 
me! It runs fine, MySQL server, until now, doesn't matter about the 
massive connect/disconnect.

Regards,

-- 
Alvaro Marín Illera
Hostalia Internet
www.hostalia.com



More information about the MailScanner mailing list