DBIx::Roles::AutoReconnect - restart DBI calls after reconnecting on failure


DBIx-Roles documentation  | view source Contained in the DBIx-Roles distribution.

Index


NAME

Top

DBIx::Roles::AutoReconnect - restart DBI calls after reconnecting on failure

DESCRIPTION

Top

The role wraps all calls to DBI methods call so that any operation with DB connection handle that fails due to connection break ( server shutdown, tcp reset etc etc), is automatically reconnected.

The role is useful when a little more robustness is desired for a cheap price; the proper DB failure resistance should of course be inherent to the program logic.

SYNOPSIS

Top

     use DBIx::Roles qw(AutoReconnect);

     my $dbh = DBI-> connect(
           "dbi:Pg:dbname=template1",
	   "postgres",
	   "password",
	   {
	   	PrintError => 0,
		ReconnectTimeout => 5,
		ReconnectFailure => sub { warn "oops!" },
	   },
     );

Attributes

Top

ReconnectFailure &SUB

Called when a DBI method fails.

ReconnectTimeout $SECONDS

Seconds to sleep after reconnection attempt fails.

Default: 60

ReconnectMaxTries $INTEGER

Max number of tries before giving up. The connections are tried indefinitely if undef.

Default: 5

NOTES

Top

Transactions are not restarted if connection breaks or AutoCommit is not set.

RaiseError is not called when a connection is restarted, but rather when ReconnectMaxTries tries are exhausted, and depending on RaiseError, the code dies or returns undef from the connect call. All other error-related attributes (PrintError, HandleError) are not affected.

SEE ALSO

Top

DBI, DBIx::Roles, DBIx::AutoReconnect.

COPYRIGHT

Top

AUTHOR

Top

Dmitry Karasik <dk@catpipe.net>


DBIx-Roles documentation  | view source Contained in the DBIx-Roles distribution.