Ensure unique transaction IDs
Long overdue :)
This commit is contained in:
parent
44d17e6ae0
commit
922f8dc8f6
2 changed files with 6 additions and 4 deletions
|
@ -83,9 +83,8 @@ sub checkout($self, $user) {
|
||||||
for $entry, $entry->contras;
|
for $entry, $entry->contras;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $transaction_id = time() - 1300000000;
|
|
||||||
|
|
||||||
RevBank::FileIO::with_lock {
|
RevBank::FileIO::with_lock {
|
||||||
|
my $transaction_id = time() - 1300000000;
|
||||||
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
|
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
|
||||||
|
|
||||||
for my $account (reverse sort keys %deltas) {
|
for my $account (reverse sort keys %deltas) {
|
||||||
|
@ -96,11 +95,12 @@ sub checkout($self, $user) {
|
||||||
}
|
}
|
||||||
|
|
||||||
RevBank::Plugins::call_hooks("checkout_done", $self, $user, $transaction_id);
|
RevBank::Plugins::call_hooks("checkout_done", $self, $user, $transaction_id);
|
||||||
|
|
||||||
|
sleep 1; # look busy (and ensure new id for next transaction :))
|
||||||
};
|
};
|
||||||
|
|
||||||
$self->empty;
|
$self->empty;
|
||||||
|
|
||||||
sleep 1; # Ensure new timestamp/id for new transaction
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,15 @@ sub get_lock() {
|
||||||
|
|
||||||
open $lockfh, ">", $lockfn;
|
open $lockfh, ">", $lockfn;
|
||||||
my $attempt = 1;
|
my $attempt = 1;
|
||||||
|
|
||||||
|
my $debug = !!$ENV{REVBANK_DEBUG};
|
||||||
FLOCK: {
|
FLOCK: {
|
||||||
if (flock $lockfh, LOCK_EX | LOCK_NB) {
|
if (flock $lockfh, LOCK_EX | LOCK_NB) {
|
||||||
syswrite $lockfh, $$;
|
syswrite $lockfh, $$;
|
||||||
return ++$lockcount;
|
return ++$lockcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($attempt % 50) == 0) {
|
if (($attempt % 50) == 0 or $debug) {
|
||||||
warn "Another revbank instance has the global lock. Waiting for it to finish...\n"
|
warn "Another revbank instance has the global lock. Waiting for it to finish...\n"
|
||||||
}
|
}
|
||||||
sleep .1;
|
sleep .1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue