feat: v2.62.0 - Astra Autonomous Loop (AAL) foundation & enhanced file analysis
This commit is contained in:
+18
-6
@@ -2,11 +2,17 @@ import { logInfo, logError } from '../utils';
|
||||
|
||||
/**
|
||||
* ActionQueueManager: Manages large-scale tasks by processing them
|
||||
* sequentially to prevent resource exhaustion and I/O bottlenecks.
|
||||
* with a concurrency limit to prevent resource exhaustion and I/O bottlenecks
|
||||
* while maintaining high throughput under maximum load.
|
||||
*/
|
||||
export class ActionQueueManager {
|
||||
private queue: (() => Promise<void>)[] = [];
|
||||
private isProcessing: boolean = false;
|
||||
private activeCount: number = 0;
|
||||
private readonly concurrencyLimit: number;
|
||||
|
||||
constructor(concurrencyLimit: number = 3) {
|
||||
this.concurrencyLimit = concurrencyLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a task to the queue.
|
||||
@@ -26,28 +32,34 @@ export class ActionQueueManager {
|
||||
}
|
||||
|
||||
private async processNext() {
|
||||
if (this.isProcessing || this.queue.length === 0) return;
|
||||
if (this.activeCount >= this.concurrencyLimit || this.queue.length === 0) return;
|
||||
|
||||
this.isProcessing = true;
|
||||
this.activeCount++;
|
||||
const task = this.queue.shift();
|
||||
|
||||
if (task) {
|
||||
try {
|
||||
// Add a micro-delay to allow system breathing room between heavy I/O
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
await new Promise(r => setTimeout(r, 10));
|
||||
await task();
|
||||
} catch (error) {
|
||||
logError('Task in queue failed:', error);
|
||||
} finally {
|
||||
this.isProcessing = false;
|
||||
this.activeCount--;
|
||||
this.processNext();
|
||||
}
|
||||
} else {
|
||||
this.activeCount--;
|
||||
}
|
||||
}
|
||||
|
||||
public getPendingCount(): number {
|
||||
return this.queue.length;
|
||||
}
|
||||
|
||||
public getActiveCount(): number {
|
||||
return this.activeCount;
|
||||
}
|
||||
}
|
||||
|
||||
export const actionQueue = new ActionQueueManager();
|
||||
|
||||
Reference in New Issue
Block a user