| Previous · Next | |
| User | Message |
|
arjan
|
Date: 8/11/2011 10:56 am · Subject: rebuildLineage · Rating: 0
Hi all,Today I tried to rebuild the lineage of a rather large site. To do this I had to change a few things in the rebuildLineage helper script, because several steps in this script take so much time, that the connection to the database is lost, which results in a fatal error. First of all I took the call to the getDescendants method out of the while loop, and stored the orphans in a temporary array. I added a reconnect method to Session as quoted below. Since the while loop iterates through the results of a statement handler, it's not possible (nor needed) to reconnect while iterating through this loop, because that would invalidate an active connection. However it is necessary to reconnect between several other steps, like after this while loop and before iterating through the orphans. I had this problem more often with helper scripts and also in another project of mine. There I solved the problem in a more fundamental way. If the database is called from the web, it works like it does in WebGUI, if it's called from a script or a daemon, it clears the connection and reconnects. It's written in Moose and goes like below. Perhaps it's an idea to do something like this in WebGUI to prevent this kind of problem. has 'db' => ( (...) build => '_build_db', ); around 'db' => sub { my $orig = shift; my $self = shift; # Reconnect if called from script or Daemon, not from web return $self->$orig( @_ ) if $0 =~ /httpd/; # Not if in a transaction return $self->$orig( @_ ) if ( $self->has_db && $self->$orig->dbh->{ AutoCommit } == 0 ); if( $self->has_db ) { $self->clear_db; } return $self->$orig( @_ ); } ------------------------------------------------------------------------------------------------------------------ added to rebuildLineage: package WebGUI::Session; sub reconnect { my $self = shift; if ( defined $self->{ _db } ) { $self->db->disconnect; undef $self->{ _db }; my $db = WebGUI::SQL->connect( $self, $self->config->get( "dsn" ),$self->config->get( "dbuser" ),$self->config->get( "dbpass" ) ); if ( defined $db ) { my $auto_reconnect = $db->{mysql_auto_reconnect}; if( !$auto_reconnect ) { $db->{mysql_auto_reconnect} = 1; $auto_reconnect = $db->{mysql_auto_reconnect}; } $self->{ _db } = $db; } } } package main; -- Recent: http://www.lomcongres.nl/ Congres- en nieuwsbriefportaal met relatiebeheer systeem voor het Landelijk Overleg Milieuhandhaving Setting Standards, a a Delft University of Technology and United Knowledge simulation exercise on strategy and cooperation in standardization, http://www.setting-standards.com United Knowledge, internet voor de publieke sector Keizersgracht 74 1015 CT Amsterdam T +31 (0)20 52 18 300 F +31 (0)20 52 18 301 bureau@unitedknowledge.nl http://www.unitedknowledge.nl M +31 (0)6 2427 1444 E arjan@unitedknowledge.nl Bezoek onze site op: http://www.unitedknowledge.nl Of bekijk een van onze projecten: http://www.handhavingsportaal.nl/ http://www.setting-standards.com/ http://www.lomcongres.nl/ http://www.clubvanmaarssen.org/ |
| Back to Top |
Rate [ | ]
|