diff --git a/.gitignore b/.gitignore index cf8d3dd..59fb9cc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ @@ -159,4 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -node_modules \ No newline at end of file +node_modules +.DS_Store +hubcmdui/package-lock.json diff --git a/hubcmdui/lib/initScheduler.js b/hubcmdui/lib/initScheduler.js new file mode 100644 index 0000000..e9c0238 --- /dev/null +++ b/hubcmdui/lib/initScheduler.js @@ -0,0 +1,74 @@ +/** + * 初始化调度器 - 确保某些操作只执行一次 + */ +const logger = require('../logger'); + +// 用于跟踪已执行的任务 +const executedTasks = new Set(); + +async function executeOnce(taskId, taskFunction, context = null) { + try { + // 检查任务是否已经执行过 + if (executedTasks.has(taskId)) { + logger.debug(`任务 "${taskId}" 已经执行过,跳过执行`); + return null; + } + + logger.info(`开始执行一次性任务: ${taskId}`); + + // 执行任务 + let result; + if (typeof taskFunction === 'function') { + result = await taskFunction(context); + } else { + throw new Error('提供的任务不是一个函数'); + } + + // 标记任务为已执行 + executedTasks.add(taskId); + logger.success(`任务 "${taskId}" 执行完成`); + + return result; + } catch (error) { + logger.error(`任务 "${taskId}" 执行失败:`, error); + throw error; + } +} + +/** + * 检查任务是否已执行 + * @param {string} taskId - 任务唯一标识符 + * @returns {boolean} 是否已执行 + */ +function isTaskExecuted(taskId) { + return executedTasks.has(taskId); +} + +/** + * 重置任务执行状态(主要用于测试) + * @param {string} taskId - 任务唯一标识符,如果不提供则重置所有任务 + */ +function resetTaskStatus(taskId = null) { + if (taskId) { + executedTasks.delete(taskId); + logger.debug(`重置任务 "${taskId}" 的执行状态`); + } else { + executedTasks.clear(); + logger.debug('重置所有任务的执行状态'); + } +} + +/** + * 获取已执行的任务列表 + * @returns {Array} 已执行的任务ID列表 + */ +function getExecutedTasks() { + return Array.from(executedTasks); +} + +module.exports = { + executeOnce, + isTaskExecuted, + resetTaskStatus, + getExecutedTasks +}; diff --git a/hubcmdui/users.json b/hubcmdui/users.json index 3da8a86..de1cb5c 100644 --- a/hubcmdui/users.json +++ b/hubcmdui/users.json @@ -3,8 +3,8 @@ { "username": "root", "password": "$2b$10$HBYJPwEB1gdRxcc6Bm1mKukxCC8eyJOZC7sGJN5meghvsBfoQjKtW", - "loginCount": 0, - "lastLogin": "2025-05-10T11:37:31.774Z" + "loginCount": 2, + "lastLogin": "2025-07-11T02:17:50.457Z" } ] } \ No newline at end of file