mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 01:25:10 +00:00
Fix retry
Adding multiple contracts had broken the retry loop Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
parent
3667dd9322
commit
19e28d817b
2 changed files with 6 additions and 2 deletions
|
|
@ -160,6 +160,10 @@ export const startRetryLoop = (contract: Contract, redis: Redis): void => {
|
||||||
pendingTransactionCount
|
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(
|
const transactionIds = await (redis as Redis).zrange(
|
||||||
'index:txn:timestamp',
|
'index:txn:timestamp',
|
||||||
-1,
|
-1,
|
||||||
|
|
@ -309,7 +313,7 @@ const retryTransaction = async (
|
||||||
await clearTransactionDetails(redis, transactionId);
|
await clearTransactionDetails(redis, transactionId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isDuplicateTransaction(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);
|
await clearTransactionDetails(redis, transactionId);
|
||||||
} else {
|
} else {
|
||||||
// TODO check for retry limit and update timestamp
|
// TODO check for retry limit and update timestamp
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { createServer } from './server';
|
||||||
async function main() {
|
async function main() {
|
||||||
const app = await createServer();
|
const app = await createServer();
|
||||||
|
|
||||||
const contract: Contract = app.get('contract');
|
const contract: Contract = app.get('contracts').contract;
|
||||||
const redis: Redis = app.get('redis');
|
const redis: Redis = app.get('redis');
|
||||||
startRetryLoop(contract, redis);
|
startRetryLoop(contract, redis);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue