Files
autoAiWorkSys/api/middleware/schedule/config.js
张成 c083494fce 1
2025-12-12 17:13:00 +08:00

127 lines
4.1 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.workHours = {
start: 6,
end: 23
};
// 频率限制配置(毫秒)
this.rateLimits = {
search: 30 * 60 * 1000, // 搜索间隔30分钟
apply: 5 * 60 * 1000, // 投递间隔5分钟
chat: 1 * 60 * 1000, // 聊天间隔1分钟
};
// 单日操作限制
this.dailyLimits = {
maxSearch: 20, // 每天最多搜索20次
maxApply: 50, // 每天最多投递50份简历默认值
maxChat: 100, // 每天最多发送100条聊天
};
// 平台特定的每日投递限制
this.platformDailyLimits = {
boss: 150, // Boss直聘每天最多投递150次
liepin: 50 // 猎聘每天最多投递50次默认值
};
// 任务超时配置(毫秒)
this.taskTimeouts = {
auto_deliver: 30 * 60 * 1000, // 自动投递任务30分钟包含多个子任务
auto_chat: 15 * 60 * 1000, // 自动沟通任务15分钟
auto_active_account: 10 * 60 * 1000 // 自动活跃账号任务10分钟
};
// 任务优先级配置
this.taskPriorities = {
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分钟
autoDeliver: '0 */1 * * * *', // 自动投递任务每1分钟执行一次
autoChat: '0 */15 * * * *' // 自动沟通任务每15分钟执行一次
};
}
/**
* 检查是否在工作时间
* @returns {boolean}
*/
isWorkingHours() {
const now = dayjs();
const hour = now.hour();
return hour >= this.workHours.start && hour < this.workHours.end;
}
/**
* 获取任务超时时间
* @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 - 操作类型
* @returns {number} 间隔时间(毫秒)
*/
getRateLimit(operation) {
return this.rateLimits[operation] || 0;
}
/**
* 获取日限制
* @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;