[Perl-workflow-devel] RT #52558
Brought to you by:
jonasbn
From: Jonas B. N. <jo...@gm...> - 2010-01-30 19:34:29
|
Hello All and Danny, Danny asked a very interesting question, in relation to using a DBI bases persister and MySQL. He observed that the connection would go away to he wondered where one would code a reconnect. See the original ticket: https://rt.cpan.org/Ticket/Display.html?id=52558 Here is my shot at a possible solution: The actual database connection is made in Workflow::Persister::DBI lines 82-89, including logging. $dbh->{RaiseError} = 1; $dbh->{PrintError} = 0; $dbh->{ChopBlanks} = 1; $dbh->{AutoCommit} = $self->autocommit(); $self->handle($dbh); $log->is_debug && $log->debug( "Connected to database '", $self->dsn, "' and ", "assigned to persister ok" ); The interesting part is the association with $self, where the database handle $dbh is given to the getter: handle. We could move the database connectivity part to a separate private method with singleton behavior, so when accessing handle (this would be it) access to the database would be tested, if connectivity existing the handled would be returned else connection would be made or in some cases reconnected. I have used this pattern before and it seems to work quite nicely. DBI even has a ping method to check connectivity. http://search.cpan.org/~timb/DBI-1.609/DBI.pm#ping Does anybody have reflections, objections or anything? - else I will initiate implementation ASAP. jonasbn -- AIM: BjonasN Gtalk: jo...@gm... ICQ: 62401545 MSN: jo...@io... twitter: jonasbn blog: http://e-diot.dk/ |