| 71 | } |
| 72 | |
| 73 | public async enqueue( |
| 74 | url: string, |
| 75 | options: RequestInit, |
| 76 | type: QueuedRequest["type"] = "other", |
| 77 | operation?: string, |
| 78 | ): Promise<void> { |
| 79 | if (this.queue.size >= this.config.maxQueueSize) { |
| 80 | const oldestId = Array.from(this.queue.keys())[0] |
| 81 | if (oldestId) { |
| 82 | this.queue.delete(oldestId) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | const request: QueuedRequest = { |
| 87 | id: `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, |
| 88 | url, |
| 89 | options, |
| 90 | timestamp: Date.now(), |
| 91 | retryCount: 0, |
| 92 | type, |
| 93 | operation, |
| 94 | } |
| 95 | |
| 96 | this.queue.set(request.id, request) |
| 97 | await this.persistQueue() |
| 98 | |
| 99 | this.emit("request-queued", request) |
| 100 | this.log(`[RetryQueue] Queued request: ${url}`) |
| 101 | } |
| 102 | |
| 103 | public async retryAll(): Promise<void> { |
| 104 | if (this.isProcessing) { |