start_task_scheduler.bat 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. @echo off
  2. chcp 65001 >nul
  3. REM ============================================================
  4. REM 自动任务调度脚本启动器
  5. REM ============================================================
  6. REM 功能:启动核心任务调度脚本 auto_execute_tasks.py
  7. REM 支持前台运行、后台运行、单次执行等多种模式
  8. REM ============================================================
  9. setlocal enabledelayedexpansion
  10. REM 切换到项目根目录
  11. cd /d %~dp0..
  12. echo.
  13. echo ========================================================
  14. echo 自动任务调度脚本启动器
  15. echo ========================================================
  16. echo.
  17. REM 检查 Python 是否安装
  18. python --version >nul 2>&1
  19. if errorlevel 1 (
  20. echo [错误] 未找到 Python,请先安装 Python
  21. pause
  22. exit /b 1
  23. )
  24. REM 检查脚本文件是否存在
  25. if not exist "scripts\auto_execute_tasks.py" (
  26. echo [错误] 未找到脚本文件: scripts\auto_execute_tasks.py
  27. pause
  28. exit /b 1
  29. )
  30. REM 检查数据库配置是否存在
  31. if not exist "mcp-servers\task-manager\config.json" (
  32. echo [错误] 未找到数据库配置: mcp-servers\task-manager\config.json
  33. pause
  34. exit /b 1
  35. )
  36. REM 创建 logs 目录
  37. if not exist "logs" mkdir logs
  38. echo [信息] 当前目录: %cd%
  39. echo.
  40. echo 请选择运行模式:
  41. echo.
  42. echo 1. 前台运行(可以看到实时日志,按 Ctrl+C 停止)
  43. echo 2. 后台运行(无窗口,日志输出到 logs\auto_execute.log)
  44. echo 3. 执行一次(只检查一次 pending 任务)
  45. echo 4. 前台运行 + 启用自动 Chat
  46. echo 5. 后台运行 + 启用自动 Chat
  47. echo 6. 查看服务状态
  48. echo 7. 停止服务
  49. echo 0. 退出
  50. echo.
  51. set /p choice="请输入选择 [1-7, 0]: "
  52. if "%choice%"=="1" goto :run_foreground
  53. if "%choice%"=="2" goto :run_background
  54. if "%choice%"=="3" goto :run_once
  55. if "%choice%"=="4" goto :run_foreground_chat
  56. if "%choice%"=="5" goto :run_background_chat
  57. if "%choice%"=="6" goto :check_status
  58. if "%choice%"=="7" goto :stop_service
  59. if "%choice%"=="0" goto :exit
  60. echo [错误] 无效的选择,请重新运行
  61. pause
  62. exit /b 1
  63. :run_foreground
  64. echo.
  65. echo [启动] 前台运行模式(检查间隔: 5分钟)
  66. echo [提示] 按 Ctrl+C 可停止服务
  67. echo.
  68. python scripts\auto_execute_tasks.py --interval 300
  69. pause
  70. goto :exit
  71. :run_background
  72. echo.
  73. echo [启动] 后台运行模式(检查间隔: 5分钟)
  74. echo [信息] 日志输出到: logs\auto_execute.log
  75. start /B "" python scripts\auto_execute_tasks.py --interval 300 > logs\auto_execute.log 2>&1
  76. echo.
  77. echo [成功] 服务已在后台启动!
  78. echo.
  79. echo [提示] 相关命令:
  80. echo - 查看日志: type logs\auto_execute.log
  81. echo - 停止服务: 再次运行此脚本选择 7
  82. echo.
  83. pause
  84. goto :exit
  85. :run_once
  86. echo.
  87. echo [执行] 单次检查模式
  88. echo.
  89. python scripts\auto_execute_tasks.py --once
  90. echo.
  91. pause
  92. goto :exit
  93. :run_foreground_chat
  94. echo.
  95. set /p chat_pos="请输入 Chat 输入框位置 (格式: x,y,直接回车使用默认): "
  96. echo.
  97. echo [启动] 前台运行模式 + 自动 Chat
  98. if "%chat_pos%"=="" (
  99. python scripts\auto_execute_tasks.py --interval 300 --enable-chat
  100. ) else (
  101. python scripts\auto_execute_tasks.py --interval 300 --enable-chat --chat-input-pos "%chat_pos%"
  102. )
  103. pause
  104. goto :exit
  105. :run_background_chat
  106. echo.
  107. set /p chat_pos="请输入 Chat 输入框位置 (格式: x,y,直接回车使用默认): "
  108. echo.
  109. echo [启动] 后台运行模式 + 自动 Chat
  110. echo [信息] 日志输出到: logs\auto_execute.log
  111. if "%chat_pos%"=="" (
  112. start /B "" python scripts\auto_execute_tasks.py --interval 300 --enable-chat > logs\auto_execute.log 2>&1
  113. ) else (
  114. start /B "" python scripts\auto_execute_tasks.py --interval 300 --enable-chat --chat-input-pos "%chat_pos%" > logs\auto_execute.log 2>&1
  115. )
  116. echo.
  117. echo [成功] 服务已在后台启动!
  118. echo.
  119. pause
  120. goto :exit
  121. :check_status
  122. echo.
  123. echo ========================================================
  124. echo 服务状态检查
  125. echo ========================================================
  126. echo.
  127. echo [进程状态]
  128. powershell -Command "$processes = Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -like '*auto_execute_tasks.py*' }; if ($processes) { Write-Host '[运行中] 找到以下进程:' -ForegroundColor Green; $processes | ForEach-Object { Write-Host (' 进程ID: ' + $_.ProcessId) } } else { Write-Host '[未运行] 未找到 auto_execute_tasks.py 进程' -ForegroundColor Yellow }"
  129. echo.
  130. echo ========================================================
  131. echo 最近日志(最后 20 行)
  132. echo ========================================================
  133. echo.
  134. if exist "logs\auto_execute.log" (
  135. powershell -Command "Get-Content logs\auto_execute.log -Tail 20 -ErrorAction SilentlyContinue"
  136. ) else (
  137. echo [提示] 日志文件不存在
  138. )
  139. echo.
  140. echo ========================================================
  141. echo pending_tasks.json 状态
  142. echo ========================================================
  143. echo.
  144. if exist ".cursor\pending_tasks.json" (
  145. echo [文件存在] .cursor\pending_tasks.json
  146. powershell -Command "$tasks = Get-Content '.cursor\pending_tasks.json' -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json; if ($tasks) { Write-Host (' 任务数量: ' + $tasks.Count); $tasks | ForEach-Object { Write-Host (' - [' + $_.task_id + '] ' + $_.task_name + ' (' + $_.status + ')') } } else { Write-Host ' [空] 没有待处理任务' }"
  147. ) else (
  148. echo [提示] pending_tasks.json 不存在
  149. )
  150. echo.
  151. pause
  152. goto :exit
  153. :stop_service
  154. echo.
  155. echo [操作] 正在停止服务...
  156. powershell -Command "$processes = Get-WmiObject Win32_Process | Where-Object { $_.CommandLine -like '*auto_execute_tasks.py*' }; if ($processes) { Write-Host '[找到] 以下进程将被停止:' -ForegroundColor Yellow; $processes | ForEach-Object { Write-Host (' 进程ID: ' + $_.ProcessId); Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }; Write-Host '[完成] 进程已停止' -ForegroundColor Green } else { Write-Host '[提示] 未找到运行中的进程' -ForegroundColor Cyan }"
  157. echo.
  158. pause
  159. goto :exit
  160. :exit
  161. endlocal
  162. exit /b 0