[Dbix-class] Connection Questions

Ash Berlin ash_cpan at firemirror.com
Wed Oct 15 15:22:46 BST 2008


On 15 Oct 2008, at 14:25, Brandi wrote:

> 2)
>
> I have some computation that might cause the connection to MySQL to
> timeout.  How can I reestablish a connection in my script, or in other
> words disconnect and reconnect again at a later time in my script?
>

Default timeout is 30s, and having a web request sit for 30s is bad  
form. But anyway:

use $schema->txn_do(sub {
     # Code goes here
});

If the connection times out at anypoint during that, the entire thing  
will be restarted and rexecuted. I wouldn't bother with explicitly  
disconnecting.

http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/Schema.pm#txn_do

-ash



More information about the DBIx-Class mailing list