aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MGA
diff options
context:
space:
mode:
authorOlivier Thauvin <nanardon@mageia.org>2010-11-05 18:30:58 +0000
committerOlivier Thauvin <nanardon@mageia.org>2010-11-05 18:30:58 +0000
commitb6a1e038f23f29127bfc97589b5663cebf4dcd76 (patch)
tree4a2db40cf67d71a88661340e77459ca0f0359e24 /lib/MGA
parentd9017d106190a0b32233b5176ef0f7a7e359b9b6 (diff)
downloadmgamirrors-b6a1e038f23f29127bfc97589b5663cebf4dcd76.tar
mgamirrors-b6a1e038f23f29127bfc97589b5663cebf4dcd76.tar.gz
mgamirrors-b6a1e038f23f29127bfc97589b5663cebf4dcd76.tar.bz2
mgamirrors-b6a1e038f23f29127bfc97589b5663cebf4dcd76.tar.xz
mgamirrors-b6a1e038f23f29127bfc97589b5663cebf4dcd76.zip
- reconnect automatically to database
Diffstat (limited to 'lib/MGA')
-rw-r--r--lib/MGA/Mirrors/DB.pm29
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/MGA/Mirrors/DB.pm b/lib/MGA/Mirrors/DB.pm
index ac37783..da0534a 100644
--- a/lib/MGA/Mirrors/DB.pm
+++ b/lib/MGA/Mirrors/DB.pm
@@ -20,18 +20,7 @@ sub new {
: Config::IniFiles->new(-file => configfile())
or return;
- my $db = DBI->connect(
- 'dbi:Pg:' . $conf->val('db', 'pgconn', ''),
- $conf->val('db', 'user') || undef,
- $conf->val('db', 'password') || undef,
- {
- AutoCommit => 0,
- PrintError => 1,
- }
- ) or return;
-
bless {
- db => $db,
conf => $conf,
}, $class;
}
@@ -51,7 +40,23 @@ sub host_ips {
@addresses;
}
-sub db { $_[0]->{db} }
+sub db {
+ my ($self) = @_;
+ if ($self->{db} && $self->{db}->ping) {
+ return $self->{db};
+ } else {
+ my $db = DBI->connect(
+ 'dbi:Pg:' . $self->{conf}->val('db', 'pgconn', ''),
+ $self->{conf}->val('db', 'user') || undef,
+ $self->{conf}->val('db', 'password') || undef,
+ {
+ AutoCommit => 0,
+ PrintError => 1,
+ }
+ ) or return;
+ return $self->{db} = $db;
+ }
+}
sub locate_ips {
my ($self, @ips) = @_;