feat: 聚合模式增加闲时监控,支持获取指定域名的Cookie

This commit is contained in:
foxhui
2025-12-13 16:35:42 +08:00
Unverified
parent e0c4c80739
commit d3129d0641
8 changed files with 94 additions and 15 deletions
+12 -2
View File
@@ -51,7 +51,7 @@ import {
*/
export function createQueueManager(queueConfig, callbacks) {
const { maxConcurrent, maxQueueSize, keepaliveMode } = queueConfig;
const { initBrowser, generateImage, config } = callbacks;
const { initBrowser, generateImage, config, navigateToMonitor } = callbacks;
/** @type {TaskContext[]} */
const queue = [];
@@ -149,7 +149,13 @@ export function createQueueManager(queueConfig, callbacks) {
*/
async function processQueue() {
// 如果正在处理的任务已满,或队列为空,则停止
if (processingCount >= maxConcurrent || queue.length === 0) return;
if (processingCount >= maxConcurrent || queue.length === 0) {
// 队列空闲时,触发监控跳转
if (processingCount === 0 && queue.length === 0 && navigateToMonitor) {
navigateToMonitor().catch(() => { });
}
return;
}
// 取出下一个任务
const task = queue.shift();
@@ -201,6 +207,10 @@ export function createQueueManager(queueConfig, callbacks) {
*/
async function initializeBrowser() {
browserContext = await initBrowser(config);
// 初始化完成后,触发首次监控跳转
if (navigateToMonitor) {
navigateToMonitor().catch(() => { });
}
return browserContext;
}