Przeglądaj źródła

fix: 修复缺失initScheduler模块的问题

dqzboy 3 miesięcy temu
rodzic
commit
8bdbf6a48c
3 zmienionych plików z 79 dodań i 4 usunięć
  1. 3 2
      .gitignore
  2. 74 0
      hubcmdui/lib/initScheduler.js
  3. 2 2
      hubcmdui/users.json

+ 3 - 2
.gitignore

@@ -14,7 +14,6 @@ dist/
 downloads/
 downloads/
 eggs/
 eggs/
 .eggs/
 .eggs/
-lib/
 lib64/
 lib64/
 parts/
 parts/
 sdist/
 sdist/
@@ -159,4 +158,6 @@ cython_debug/
 #  and can be added to the global gitignore or merged into this file.  For a more nuclear
 #  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.
 #  option (not recommended) you can uncomment the following to ignore the entire idea folder.
 #.idea/
 #.idea/
-node_modules
+node_modules
+.DS_Store
+hubcmdui/package-lock.json

+ 74 - 0
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<string>} 已执行的任务ID列表
+ */
+function getExecutedTasks() {
+  return Array.from(executedTasks);
+}
+
+module.exports = {
+  executeOnce,
+  isTaskExecuted,
+  resetTaskStatus,
+  getExecutedTasks
+};

+ 2 - 2
hubcmdui/users.json

@@ -3,8 +3,8 @@
     {
     {
       "username": "root",
       "username": "root",
       "password": "$2b$10$HBYJPwEB1gdRxcc6Bm1mKukxCC8eyJOZC7sGJN5meghvsBfoQjKtW",
       "password": "$2b$10$HBYJPwEB1gdRxcc6Bm1mKukxCC8eyJOZC7sGJN5meghvsBfoQjKtW",
-      "loginCount": 0,
-      "lastLogin": "2025-05-10T11:37:31.774Z"
+      "loginCount": 2,
+      "lastLogin": "2025-07-11T02:17:50.457Z"
     }
     }
   ]
   ]
 }
 }