MCPcopy
hub / github.com/callumalpass/tasknotes / processQueue

Method processQueue

src/services/AutoArchiveService.ts:137–184  ·  view source on GitHub ↗

* Process the queue and archive tasks that are due

()

Source from the content-addressed store, hash-verified

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

Calls 5

getQueueMethod · 0.95
processItemMethod · 0.95
saveQueueMethod · 0.95
nowMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected