Initial idea to reconnect if needed
This commit is contained in:
@ -18,6 +18,7 @@ sub add {
|
||||
my $self = shift;
|
||||
my $params = shift;
|
||||
die "No params" unless $params;
|
||||
$self->{'config'}->db_connect();
|
||||
$self->{'dbh'} = $self->{'config'}->get_dbh unless($self->{'dbh'});
|
||||
my $return = {};
|
||||
$return = $self->addtoblacklist($params) if($params->{'list'} eq 'black');
|
||||
|
||||
@ -120,6 +120,30 @@ 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()) {
|
||||
#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";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#Never connected?
|
||||
$self->{'config'}->{'fetchers'}->{'db'}->init();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_dbh {
|
||||
my $self = shift;
|
||||
my $dbh = $self->{'config'}->{'fetchers'}->{'db'}->{'dbh'};
|
||||
|
||||
Reference in New Issue
Block a user