mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'semaphore' into test-semaphore
This commit is contained in:
commit
cf99410971
@ -166,13 +166,13 @@ export class TransactionLinkResolver {
|
|||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||||
const user = getUser(context)
|
const user = getUser(context)
|
||||||
const now = new Date()
|
|
||||||
|
|
||||||
if (code.match(/^CL-/)) {
|
if (code.match(/^CL-/)) {
|
||||||
// acquire lock
|
// acquire lock
|
||||||
const releaseLock = await TRANSACTIONS_LOCK.acquire()
|
const releaseLock = await TRANSACTIONS_LOCK.acquire()
|
||||||
console.log(`locked for redeemTransactionLink ${code}`)
|
console.log(`locked for redeemTransactionLink ${code}`)
|
||||||
logger.info('redeem contribution link...')
|
logger.info('redeem contribution link...')
|
||||||
|
const now = new Date()
|
||||||
const queryRunner = getConnection().createQueryRunner()
|
const queryRunner = getConnection().createQueryRunner()
|
||||||
await queryRunner.connect()
|
await queryRunner.connect()
|
||||||
await queryRunner.startTransaction('REPEATABLE READ')
|
await queryRunner.startTransaction('REPEATABLE READ')
|
||||||
@ -277,7 +277,7 @@ export class TransactionLinkResolver {
|
|||||||
.select('transaction')
|
.select('transaction')
|
||||||
.from(DbTransaction, 'transaction')
|
.from(DbTransaction, 'transaction')
|
||||||
.where('transaction.userId = :id', { id: user.id })
|
.where('transaction.userId = :id', { id: user.id })
|
||||||
.orderBy('transaction.balanceDate', 'DESC')
|
.orderBy('transaction.id', 'DESC')
|
||||||
.getOne()
|
.getOne()
|
||||||
let newBalance = new Decimal(0)
|
let newBalance = new Decimal(0)
|
||||||
|
|
||||||
@ -318,6 +318,7 @@ export class TransactionLinkResolver {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
const now = new Date()
|
||||||
const transactionLink = await DbTransactionLink.findOneOrFail({ code })
|
const transactionLink = await DbTransactionLink.findOneOrFail({ code })
|
||||||
const linkedUser = await DbUser.findOneOrFail(
|
const linkedUser = await DbUser.findOneOrFail(
|
||||||
{ id: transactionLink.userId },
|
{ id: transactionLink.userId },
|
||||||
@ -328,6 +329,9 @@ export class TransactionLinkResolver {
|
|||||||
throw new Error('Cannot redeem own transaction link.')
|
throw new Error('Cannot redeem own transaction link.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: The now check should be done within the semaphore lock,
|
||||||
|
// since the program might wait a while till it is ready to proceed
|
||||||
|
// writing the transaction.
|
||||||
if (transactionLink.validUntil.getTime() < now.getTime()) {
|
if (transactionLink.validUntil.getTime() < now.getTime()) {
|
||||||
throw new Error('Transaction Link is not valid anymore.')
|
throw new Error('Transaction Link is not valid anymore.')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user