From 2e72da5717e7c05d03fffe237e0ff9f2d72766be Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 2 Nov 2011 10:05:48 -0600 Subject: [PATCH] Use new style Retry in CopyRowsInsertSelect.pm. --- lib/CopyRowsInsertSelect.pm | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/CopyRowsInsertSelect.pm b/lib/CopyRowsInsertSelect.pm index d1fd6331..078eda1d 100644 --- a/lib/CopyRowsInsertSelect.pm +++ b/lib/CopyRowsInsertSelect.pm @@ -85,24 +85,23 @@ sub copy { wait => sub { sleep 1; }, tries => 3, try => sub { - my ( %args ) = @_; - eval { - $dbh->do($sql); - }; - if ( $EVAL_ERROR ) { - MKDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/Lock wait timeout exceeded/ ) { - $error = $EVAL_ERROR; - if ( $args{tryno} > 1 ) { - $msg->("Lock wait timeout exceeded; retrying $sql"); - } - return; - } - die $EVAL_ERROR; - } - return 1; + $dbh->do($sql); + return; + }, + fail => sub { + my (%args) = @_; + my $error = $args{error}; + MKDEBUG && _d($error); + if ( $error =~ m/Lock wait timeout exceeded/ ) { + $msg->("Lock wait timeout exceeded; retrying $sql"); + return 1; # call wait, call try + } + return 0; # call final_fail + }, + final_fail => sub { + my (%args) = @_; + die $args{error}; }, - on_failure => sub { die $error; }, ); }