master
cyhhao 2 years ago
parent e1b38802b8
commit 7fe3e66102

@ -10,12 +10,8 @@ export class QueueTask {
checkPointWait!: Promise<void>
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<any> {
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

@ -193,7 +193,7 @@ export class SLIStorage implements Storage {
async storeIPFS(data: Buffer): Promise<string> {
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",

Loading…
Cancel
Save