Disable auto-reconnect, and handle db/dbh centrally-ish
This commit is contained in:
@@ -22,6 +22,7 @@ sub new {
|
||||
$self->parse if($self->load);
|
||||
$self->{'config'}->{'test'} = $test;
|
||||
$self->{'config'}->{'parse'} = $parse;
|
||||
$self->{'db'} = undef;
|
||||
return $self;
|
||||
}
|
||||
|
||||
@@ -122,38 +123,36 @@ sub get_fetcher_module {
|
||||
|
||||
sub db_connect {
|
||||
my $self = shift;
|
||||
if ($self->{'config'}->{'fetchers'}->{'db'}->{'dbh'}) {
|
||||
#We pretend to be connected
|
||||
if ($self->{'config'}->{'fetchers'}->{'db'}->{'dbh'}->ping()) {
|
||||
my $dbh = $self->get_dbh();
|
||||
if ($dbh) {
|
||||
if ($dbh->ping()) {
|
||||
return $self->get_dbh();
|
||||
#We can ping, all is good
|
||||
return 1;
|
||||
} else {
|
||||
#No can ping, time to reconnect
|
||||
if ($self->{'config'}->{'fetchers'}->{'db'}->connect()) {
|
||||
#all good
|
||||
return 1;
|
||||
} else {
|
||||
#can't connect??
|
||||
die "Can't connect to db";
|
||||
}
|
||||
return $self->{'db'}->connect();
|
||||
}
|
||||
} else {
|
||||
#Never connected?
|
||||
$self->{'config'}->{'fetchers'}->{'db'}->init();
|
||||
return $self->{'db'}->connect();
|
||||
}
|
||||
return 0;
|
||||
die "End of db_connect should never be reached";
|
||||
}
|
||||
|
||||
sub set_db {
|
||||
my $self = shift;
|
||||
$self->{'db'} = shift;
|
||||
}
|
||||
|
||||
sub get_dbh {
|
||||
my $self = shift;
|
||||
my $dbh = $self->{'config'}->{'fetchers'}->{'db'}->{'dbh'};
|
||||
return $dbh;
|
||||
return $self->{'db'}->{'dbh'};
|
||||
}
|
||||
|
||||
sub set_dbh {
|
||||
my $self = shift;
|
||||
my $dbh = shift;
|
||||
$self->{'config'}->{'fetchers'}->{'db'}->{'dbh'} = $dbh;
|
||||
$self->{'db'}->{'dbh'} = $dbh;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user