98 lines
3.3 KiB
JavaScript
98 lines
3.3 KiB
JavaScript
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_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分钟执行一次
|
||
};
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取任务超时时间
|
||
* @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; |