feat(background-agent): implement per-key queue processor
This commit is contained in:
parent
481770e599
commit
54f448583c
@ -130,7 +130,36 @@ export class BackgroundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async processKey(key: string): Promise<void> {
|
private async processKey(key: string): Promise<void> {
|
||||||
// TODO: Implement in Task 4
|
if (this.processingKeys.has(key)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.processingKeys.add(key)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const queue = this.queuesByKey.get(key)
|
||||||
|
while (queue && queue.length > 0) {
|
||||||
|
const item = queue[0]
|
||||||
|
|
||||||
|
await this.concurrencyManager.acquire(key)
|
||||||
|
|
||||||
|
if (item.task.status === "cancelled") {
|
||||||
|
this.concurrencyManager.release(key)
|
||||||
|
queue.shift()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.startTask(item)
|
||||||
|
} catch (error) {
|
||||||
|
log("[background-agent] Error starting task:", error)
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.shift()
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.processingKeys.delete(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async startTask(item: QueueItem): Promise<void> {
|
private async startTask(item: QueueItem): Promise<void> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user