Debian Codegraph @

lemonldap-ng-common/lib/Lemonldap/NG/Common/Lib/DBI.pm

raw
1 package Lemonldap::NG::Common::Lib::DBI;
2
3 use strict;
4 use Exporter 'import';
5
6 our $VERSION = '2.22.2';
7 our @EXPORT_OK = qw(check_dbh);
8
9 # Check if a DBI handle is still valid
10 # Returns the handle if valid, undef otherwise
11 # Also cleans up the handle if it's dead (can happen after Patroni failover)
12 sub check_dbh {
13 my ($dbh) = @_;
14 return unless $dbh;
15 return $dbh if eval { $dbh->ping };
16
17 # Connection is dead, clean up
18 eval { $dbh->disconnect };
19 return;
20 }
21
22 1;