Fix retry

Adding multiple contracts had broken the retry loop

Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
James Taylor 2021-07-22 17:45:59 +01:00
parent 3667dd9322
commit 19e28d817b
2 changed files with 6 additions and 2 deletions

View file

@ -160,6 +160,10 @@ export const startRetryLoop = (contract: Contract, redis: Redis): void => {
pendingTransactionCount
);
// TODO pick a random transaction instead to reduce chances of
// clashing with other instances? Currently no zrandmember
// command though...
// https://github.com/luin/ioredis/issues/1374
const transactionIds = await (redis as Redis).zrange(
'index:txn:timestamp',
-1,
@ -309,7 +313,7 @@ const retryTransaction = async (
await clearTransactionDetails(redis, transactionId);
} catch (err) {
if (isDuplicateTransaction(err)) {
logger.debug('Transaction %s has already been committed', transactionId);
logger.warn('Transaction %s has already been committed', transactionId);
await clearTransactionDetails(redis, transactionId);
} else {
// TODO check for retry limit and update timestamp

View file

@ -12,7 +12,7 @@ import { createServer } from './server';
async function main() {
const app = await createServer();
const contract: Contract = app.get('contract');
const contract: Contract = app.get('contracts').contract;
const redis: Redis = app.get('redis');
startRetryLoop(contract, redis);