Disable auto-reconnect, and handle db/dbh centrally-ish

This commit is contained in:
2025-07-01 20:11:57 +02:00
parent 999bc6c8c8
commit 7b7083adca
6 changed files with 51 additions and 41 deletions

View File

@@ -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;
}