diff --git a/lib/db.pm b/lib/db.pm index fc71862..ca3445e 100644 --- a/lib/db.pm +++ b/lib/db.pm @@ -17,8 +17,6 @@ sub new { sub init { my $self = shift; - my $parser = shift; ## not needed for this module as the db-connection is for all modules - $self->connect() || die "Could not connect to db"; return $self->{'config'}->get_dbh(); } @@ -31,18 +29,18 @@ sub connect { my $db = $config->get_as_single_val('config','db'); my $dbh; if($usr && $pwd && $host && $db) { + my $logstr = 'Connecting to DB...'; my $i = 0; - $self->{'config'}->{'logger'}->log('Connecting to DB'); while(1) { last if($dbh = DBI->connect("DBI:mysql:database=$db;host=$host",$usr,$pwd, { PrintError => 1, mysql_auto_reconnect=>0, AutoCommit => 1 })); sleep($i); $i++; unless ($i % 10) { - $self->{'config'}->{'logger'}->log('Cannot connect to DB, reconnect retry '.$i); + $self->{'config'}->{'logger'}->log($logstr.'timed out, retry #'.$i); } } $config->set_dbh($dbh); - #$self->{'config'}->{'logger'}->log("Sucsessfully connected to db"); FIXME add debug to config? + $self->{'config'}->{'logger'}->log($logstr.'done'); return $config->get_dbh(); } else { $self->{'config'}->{'logger'}->log("Unable to connect to db, not enough parameters"); diff --git a/lib/parser.pm b/lib/parser.pm index 46b0eb2..739fe77 100644 --- a/lib/parser.pm +++ b/lib/parser.pm @@ -20,7 +20,6 @@ sub new { $self->{'localcheck'} = My::parser::localcheck->new; $self->{'block'} = My::parser::block->new($self->{'config'}); $self->{'db'} = My::parser::db->new($self->{'config'}); - $self->{'db'}->init(); $self->{'config'}->set_db($self->{'db'}); return $self; }