summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2004-03-30 16:43:52 +0000
committerivan <ivan>2004-03-30 16:43:52 +0000
commitdfcd6c6b704b9d1b5422bb0e8a7caf03639679f2 (patch)
tree9e556ce0765ed30dce8a864faecbfd9850f04485 /FS
parent5cd22361d181a4420000a22ee3782ae1104fceef (diff)
mutex the bill and collect functions per-customer
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_main.pm36
1 files changed, 28 insertions, 8 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 59e357055..74015de34 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1098,6 +1098,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.
@@ -1499,6 +1501,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?????
@@ -1875,15 +1879,19 @@ 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 #$options{'invnum'}" .
+ ": $error )";
+ warn $e;
+ return $e;
+ }
}
+ return ''; #no error
} else {
@@ -2473,6 +2481,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