DBIx::PgLink::Roles::Reconnect - detect connection loss, reconnect and restart DBI call
The role wraps some calls to DBI methods so that operation that fails due to connection break ( server shutdown, network troubles, etc), is automatically reconnected.
Failed operation will be repeated if AutoCommit mode on (no transaction). If transaction in progress than exception always raised, but connection has restored anyway.
DBI calls that needs protection must be executed via dbi_method in base Adapter class.
dbi_method
Adapter class that does the role must implement following methods:
Must check supplied exception and return true value for disconnection error and false for any 'normal' database error.
Must return true if there is transaction in progress.
Adapter class may implement following methods:
Return SQL query that always executed successfully ('SELECT 1').
Restore database session state (SET options, create temporary tables, etc).
$self->dbi_method($handle, $func_name, @_)
Execute $func_name method of $handle object (DBI database or statement handle). Check for disconnection error, reconnect and retry the function (unless in transaction).
$self->check_connection_error($exception)
Check if $exception is disconnection error and try to reconnect. If not $exception specified, can execute always_valid_query SQL query to ensure the valid connection status.
always_valid_query
$self->reconnect
Try to reconnect reconnect_retries times with reconnect_interval pause between attempts. Die if connection cannot be established or timed out.
reconnect_retries
reconnect_interval
Max number of tries before giving up.
Default: 3
Seconds to sleep after reconnection attempt fails
Default: 5
Timeout (in seconds) for waiting the database to accept connection.
Lazy prepare after reconnect (install subrole to Adapter::st)
Test reconnect timeout (SIGALRM) on different platforms
Alexey Sharafutdinov <alexey.s.v.br@gmail.com>
Based on DBIx::RetryOverDisconnects module by Oleg Pronin <syber@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install DBIx::PgLink, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::PgLink
CPAN shell
perl -MCPAN -e shell install DBIx::PgLink
For more information on module installation, please visit the detailed CPAN module installation guide.