Files
autoAiWorkSys/api/middleware/schedule/infrastructure/config.js
张成 65833dd32d 11
2025-12-30 15:46:18 +08:00

102 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const dayjs = require('dayjs');
/**
* 调度系统配置中心
* 统一管理所有配置参数
*/
class ScheduleConfig {
constructor() {
// 单日操作限制
this.dailyLimits = {
maxSearch: 20, // 每天最多搜索20次
maxApply: 50, // 每天最多投递50份简历默认值
maxChat: 100, // 每天最多发送100条聊天
};
// 平台特定的每日投递限制
this.platformDailyLimits = {
boss: 150, // Boss直聘每天最多投递150次
liepin: 50 // 猎聘每天最多投递50次默认值
};
// 任务超时配置(毫秒)
this.taskTimeouts = {
auto_search: 20 * 60 * 1000, // 自动搜索任务20分钟
auto_deliver: 30 * 60 * 1000, // 自动投递任务30分钟包含多个子任务
auto_chat: 15 * 60 * 1000, // 自动沟通任务15分钟
auto_active_account: 10 * 60 * 1000 // 自动活跃账号任务10分钟
};
// 任务优先级配置
this.taskPriorities = {
auto_search: 8, // 自动搜索任务(最高优先级,先搜索后投递)
auto_deliver: 7, // 自动投递任务
auto_chat: 6, // 自动沟通任务
auto_active_account: 5, // 自动活跃账号任务
cleanup: 1
};
// 监控配置
this.monitoring = {
heartbeatTimeout: 3 * 60 * 1000, // 心跳超时3分钟
offlineThreshold: 24 * 60 * 60 * 1000 // 离线设备清理24小时
};
// 定时任务配置
this.schedules = {
dailyReset: '0 0 * * *', // 每天凌晨重置统计
monitoringInterval: '*/1 * * * *', // 监控检查间隔1分钟
autoSearch: '0 0 */1 * * *', // 自动搜索任务每1小时执行一次
autoDeliver: '0 */1 * * * *', // 自动投递任务每1分钟执行一次
autoChat: '0 */15 * * * *', // 自动沟通任务每15分钟执行一次
autoActive: '0 0 */2 * * *' // 自动活跃任务每2小时执行一次
};
}
/**
* 获取任务超时时间
* @param {string} taskType - 任务类型
* @returns {number} 超时时间(毫秒)
*/
getTaskTimeout(taskType) {
return this.taskTimeouts[taskType] || 30000; // 默认30秒
}
/**
* 获取任务优先级
* @param {string} taskType - 任务类型
* @param {object} options - 选项
* @returns {number} 优先级1-10
*/
getTaskPriority(taskType, options = {}) {
let priority = this.taskPriorities[taskType] || 5;
if (options.urgent) {
priority = Math.min(10, priority + 2);
}
return priority;
}
/**
* 获取日限制
* @param {string} operation - 操作类型
* @param {string} platform - 平台类型(可选,用于平台特定的限制)
* @returns {number} 日限制次数
*/
getDailyLimit(operation, platform = null) {
// 如果是投递操作且指定了平台,使用平台特定的限制
if (operation === 'apply' && platform && this.platformDailyLimits[platform]) {
return this.platformDailyLimits[platform];
}
// 否则使用通用限制
return this.dailyLimits[`max${operation.charAt(0).toUpperCase() + operation.slice(1)}`] || Infinity;
}
}
// 导出单例
const scheduleConfig = new ScheduleConfig();
module.exports = scheduleConfig;