* Process the queue and archive tasks that are due
()
| 135 | * Process the queue and archive tasks that are due |
| 136 | */ |
| 137 | private async processQueue(): Promise<void> { |
| 138 | const queue = await this.getQueue(); |
| 139 | if (queue.length === 0) { |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | const now = Date.now(); |
| 144 | const toProcess: PendingAutoArchive[] = []; |
| 145 | const toKeep: PendingAutoArchive[] = []; |
| 146 | |
| 147 | // Separate items that are due for processing |
| 148 | for (const item of queue) { |
| 149 | if (now >= item.archiveAfterTimestamp) { |
| 150 | toProcess.push(item); |
| 151 | } else { |
| 152 | toKeep.push(item); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | if (toProcess.length === 0) { |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | // Process due items |
| 161 | const remainingItems: PendingAutoArchive[] = []; |
| 162 | |
| 163 | for (const item of toProcess) { |
| 164 | try { |
| 165 | const processed = await this.processItem(item); |
| 166 | if (!processed) { |
| 167 | // Keep item if it couldn't be processed |
| 168 | remainingItems.push(item); |
| 169 | } |
| 170 | } catch (error) { |
| 171 | tasknotesLogger.error(`Error processing auto-archive for ${item.taskPath}:`, { |
| 172 | category: "persistence", |
| 173 | operation: "processing-auto-archive", |
| 174 | error: error, |
| 175 | }); |
| 176 | // Keep item for retry on next cycle |
| 177 | remainingItems.push(item); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Save updated queue (items not processed + items to keep) |
| 182 | const updatedQueue = [...remainingItems, ...toKeep]; |
| 183 | await this.saveQueue(updatedQueue); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Process a single auto-archive item |
no test coverage detected