From 7fe3e661023001526269616f9496176d4b5f4bb2 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Sat, 18 Feb 2023 00:10:06 +0800 Subject: [PATCH] fix bug --- src/common/queue-task.ts | 15 ++++++++------- src/storage/SLIStorage.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/queue-task.ts b/src/common/queue-task.ts index f96ac9c..5900432 100644 --- a/src/common/queue-task.ts +++ b/src/common/queue-task.ts @@ -10,12 +10,8 @@ export class QueueTask { checkPointWait!: Promise checkPointResolve: any - constructor({ - maxRetry = 10, - queueInterval = 0, - maxPending = 0, - retryInterval = 0, - }) { + index: number = 0 + constructor({ maxRetry = 10, queueInterval = 0, maxPending = 0, retryInterval = 0 }) { this.maxRetry = maxRetry this.queueInterval = queueInterval this.maxPending = maxPending @@ -58,7 +54,12 @@ export class QueueTask { async run(func: Function, retry: number = this.maxRetry): Promise { let lastError for (let i = 0; i < retry; i++) { + this.index++ + let start = Date.now().valueOf() + console.error("wait-" + this.index) await this.tickThread() + console.log("run-" + this.index, Date.now().valueOf() - start, "ms") + this.pending++ try { let res = await func() @@ -69,7 +70,7 @@ export class QueueTask { lastError = err this.pending-- this.checkPointResolve(true) - new Promise((r) => setTimeout(r, this.retryInterval)) + await new Promise((r) => setTimeout(r, this.retryInterval)) } } if (lastError) throw lastError diff --git a/src/storage/SLIStorage.ts b/src/storage/SLIStorage.ts index a09fd6d..13e50d9 100644 --- a/src/storage/SLIStorage.ts +++ b/src/storage/SLIStorage.ts @@ -193,7 +193,7 @@ export class SLIStorage implements Storage { async storeIPFS(data: Buffer): Promise { const TIMEOUT = 30 try { - let cid = this.storageTask.run(async () => { + let cid = await this.storageTask.run(async () => { let response = await axios.post("https://api.nft.storage/upload", data, { headers: { "Content-Type": "application/octet-stream",