This commit is contained in:
2026-09-11 14:35:22 -04:00
parent aba185d80a
commit cc182f2ef1
10 changed files with 86 additions and 17 deletions
+5 -2
View File
@@ -3,6 +3,7 @@ export class QvacScheduler {
this.concurrency = Math.max(1, concurrency);
this.running = 0;
this.queue = [];
this.completed = 0; this.failed = 0; this.totalDurationMs = 0; this.byLane = {};
}
run(task, { lane = 'background', signal } = {}) {
@@ -19,8 +20,9 @@ export class QvacScheduler {
while (this.running < this.concurrency && this.queue.length) {
const job = this.queue.shift();
if (job.signal?.aborted) { job.reject(new Error('QVAC job cancelled before start')); continue; }
this.running += 1;
Promise.resolve().then(() => job.task(job.signal)).then(job.resolve, job.reject).finally(() => {
this.running += 1; const started = Date.now();
Promise.resolve().then(() => job.task(job.signal)).then((value) => { this.completed += 1; job.resolve(value); }, (error) => { this.failed += 1; job.reject(error); }).finally(() => {
this.totalDurationMs += Date.now() - started; this.byLane[job.lane] = (this.byLane[job.lane] || 0) + 1;
this.running -= 1;
this.pump();
});
@@ -37,4 +39,5 @@ export class QvacScheduler {
}
status() { return { running: this.running, queued: this.queue.map((j) => j.lane) }; }
metrics() { return { completed: this.completed, failed: this.failed, total_duration_ms: this.totalDurationMs, by_lane: { ...this.byLane } }; }
}