优化synclocker
This commit is contained in:
parent
97f8d8f92c
commit
d0bfccbff8
@ -139,7 +139,7 @@ export class ApiServer {
|
|||||||
private setFormatSend() {
|
private setFormatSend() {
|
||||||
this.server.addHook('preSerialization', async (req: FastifyRequest, reply: FastifyReply, payload) => {
|
this.server.addHook('preSerialization', async (req: FastifyRequest, reply: FastifyReply, payload) => {
|
||||||
reply.header('X-Powered-By', 'PHP/5.4.16')
|
reply.header('X-Powered-By', 'PHP/5.4.16')
|
||||||
new SyncLocker().unlock(req)
|
await new SyncLocker().unlock(req)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!payload.errcode) {
|
if (!payload.errcode) {
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -24,7 +24,7 @@ const redlock = new Redlock(
|
|||||||
|
|
||||||
// The max number of times Redlock will attempt to lock a resource
|
// The max number of times Redlock will attempt to lock a resource
|
||||||
// before erroring.
|
// before erroring.
|
||||||
retryCount: 10,
|
retryCount: 0,
|
||||||
|
|
||||||
// the time in ms between attempts
|
// the time in ms between attempts
|
||||||
retryDelay: 200, // time in ms
|
retryDelay: 200, // time in ms
|
||||||
@ -51,9 +51,9 @@ redlock.on('error', error => {
|
|||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
export class SyncLocker {
|
export class SyncLocker {
|
||||||
public unlock(req: IRequest) {
|
public async unlock(req: IRequest) {
|
||||||
if (req.lock) {
|
if (req.lock) {
|
||||||
req.lock.release()
|
await req.lock.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user