From 073402509cbdd3bfe09a0362166733d6c9cea8bf Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 30 Mar 2004 16:45:48 +0000 Subject: [PATCH] mutex the bill and collect functions per-customer --- FS/FS/cust_bill.pm | 21 +++++++++++++-------- FS/FS/cust_main.pm | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 6f2f01e33..591ae0c9c 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -879,15 +879,20 @@ sub realtime_bop { } ); my $error = $cust_pay->insert; if ( $error ) { - # gah, even with transactions. - my $e = 'WARNING: Card/ACH debited but database not updated - '. - 'error applying payment, invnum #' . $self->invnum. - " ($processor): $error"; - warn $e; - return $e; - } else { - return ''; + $cust_pay->invnum(''); #try again with no specific invnum + my $error2 = $cust_pay->insert; + if ( $error2 ) { + # gah, even with transactions. + my $e = 'WARNING: Card/ACH debited but database not updated - '. + "error inserting payment ($processor): $error2". + ' (previously tried insert with invnum #' . $self->invnum. + ": $error )"; + warn $e; + return $e; + } } + return ''; #no error + #} elsif ( $options{'report_badcard'} ) { } else { diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 53ed4c59b..390525405 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1082,6 +1082,8 @@ sub bill { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + $self->select_for_update; #mutex + # find the packages which are due for billing, find out how much they are # & generate invoice database. @@ -1479,6 +1481,8 @@ sub collect { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + $self->select_for_update; #mutex + my $balance = $self->balance; warn "collect customer". $self->custnum. ": balance $balance" if $DEBUG; unless ( $balance > 0 ) { #redundant????? @@ -2172,6 +2176,18 @@ sub cust_refund { qsearch( 'cust_refund', { 'custnum' => $self->custnum } ) } +=item select_for_update + +Selects this record with the SQL "FOR UPDATE" command. This can be useful as +a mutex. + +=cut + +sub select_for_update { + my $self = shift; + qsearch('cust_main', { 'custnum' => $self->custnum }, '*', 'FOR UPDATE' ); +} + =back =head1 SUBROUTINES -- 2.11.0