This commit is contained in:
张成
2026-02-28 10:38:28 +08:00
parent 1a011bcc01
commit dfd3119163
44 changed files with 449 additions and 13555 deletions

View File

@@ -20,6 +20,14 @@ class ScheduledJobs {
this.taskQueue = components.taskQueue;
this.taskHandlers = taskHandlers;
this.jobs = [];
// 业务任务防重入标记(按任务类型存)
this._runningFlags = {
auto_search: false,
auto_deliver: false,
auto_chat: false,
auto_active: false
};
}
/**
@@ -90,7 +98,7 @@ class ScheduledJobs {
console.log('[定时任务] ✓ 已启动自动投递任务 (每1分钟)');
// 3. 自动沟通任务 - 每15分钟执行一次
const autoChatJob = node_schedule.scheduleJob(config.schedules.autoChat || '0 */15 * * * *', () => {
const autoChatJob = node_schedule.scheduleJob(config.schedules.autoChat || '0 */1 * * * *', () => {
this.runAutoChatTask();
});
this.jobs.push(autoChatJob);
@@ -120,6 +128,13 @@ class ScheduledJobs {
* 为所有启用自动搜索的账号添加搜索任务
*/
async runAutoSearchTask() {
const key = 'auto_search';
if (this._runningFlags[key]) {
console.log('[自动搜索调度] 上一次执行尚未完成,本次跳过');
return;
}
this._runningFlags[key] = true;
try {
const accounts = await this.getEnabledAccounts('auto_search');
@@ -146,6 +161,8 @@ class ScheduledJobs {
}
} catch (error) {
console.error('[自动搜索调度] 执行失败:', error);
} finally {
this._runningFlags[key] = false;
}
}
@@ -154,6 +171,13 @@ class ScheduledJobs {
* 为所有启用自动投递的账号添加投递任务
*/
async runAutoDeliverTask() {
const key = 'auto_deliver';
if (this._runningFlags[key]) {
console.log('[自动投递调度] 上一次执行尚未完成,本次跳过');
return;
}
this._runningFlags[key] = true;
try {
const accounts = await this.getEnabledAccounts('auto_deliver');
@@ -180,6 +204,8 @@ class ScheduledJobs {
}
} catch (error) {
console.error('[自动投递调度] 执行失败:', error);
} finally {
this._runningFlags[key] = false;
}
}
@@ -188,6 +214,13 @@ class ScheduledJobs {
* 为所有启用自动沟通的账号添加沟通任务
*/
async runAutoChatTask() {
const key = 'auto_chat';
if (this._runningFlags[key]) {
console.log('[自动沟通调度] 上一次执行尚未完成,本次跳过');
return;
}
this._runningFlags[key] = true;
try {
const accounts = await this.getEnabledAccounts('auto_chat');
@@ -214,6 +247,8 @@ class ScheduledJobs {
}
} catch (error) {
console.error('[自动沟通调度] 执行失败:', error);
} finally {
this._runningFlags[key] = false;
}
}
@@ -222,6 +257,13 @@ class ScheduledJobs {
* 为所有启用自动活跃的账号添加活跃任务
*/
async runAutoActiveTask() {
const key = 'auto_active';
if (this._runningFlags[key]) {
console.log('[自动活跃调度] 上一次执行尚未完成,本次跳过');
return;
}
this._runningFlags[key] = true;
try {
const accounts = await this.getEnabledAccounts('auto_active');
@@ -248,6 +290,8 @@ class ScheduledJobs {
}
} catch (error) {
console.error('[自动活跃调度] 执行失败:', error);
} finally {
this._runningFlags[key] = false;
}
}