Ensure unique transaction IDs

Long overdue :)
This commit is contained in:
Juerd Waalboer 2022-10-31 19:00:20 +01:00
parent 44d17e6ae0
commit 922f8dc8f6
2 changed files with 6 additions and 4 deletions

View file

@ -83,9 +83,8 @@ sub checkout($self, $user) {
for $entry, $entry->contras;
}
my $transaction_id = time() - 1300000000;
RevBank::FileIO::with_lock {
my $transaction_id = time() - 1300000000;
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
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);
sleep 1; # look busy (and ensure new id for next transaction :))
};
$self->empty;
sleep 1; # Ensure new timestamp/id for new transaction
return 1;
}

View file

@ -24,13 +24,15 @@ sub get_lock() {
open $lockfh, ">", $lockfn;
my $attempt = 1;
my $debug = !!$ENV{REVBANK_DEBUG};
FLOCK: {
if (flock $lockfh, LOCK_EX | LOCK_NB) {
syswrite $lockfh, $$;
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"
}
sleep .1;