| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- @echo off
- chcp 65001 >nul
- REM ============================================================
- REM 自动任务调度脚本启动器
- REM ============================================================
- REM 功能:启动核心任务调度脚本 auto_execute_tasks.py
- REM 支持前台运行、后台运行、单次执行等多种模式
- REM ============================================================
- setlocal enabledelayedexpansion
- REM 切换到项目根目录
- cd /d %~dp0..
- echo.
- echo ========================================================
- echo 自动任务调度脚本启动器
- echo ========================================================
- echo.
- REM 检查 Python 是否安装
- python --version >nul 2>&1
- if errorlevel 1 (
- echo [错误] 未找到 Python,请先安装 Python
- pause
- exit /b 1
- )
- REM 检查脚本文件是否存在
- if not exist "scripts\auto_execute_tasks.py" (
- echo [错误] 未找到脚本文件: scripts\auto_execute_tasks.py
- pause
- exit /b 1
- )
- REM 检查数据库配置是否存在
- if not exist "mcp-servers\task-manager\config.json" (
- echo [错误] 未找到数据库配置: mcp-servers\task-manager\config.json
- pause
- exit /b 1
- )
- REM 创建 logs 目录
- if not exist "logs" mkdir logs
- echo [信息] 当前目录: %cd%
- echo.
- echo 请选择运行模式:
- echo.
- echo 1. 前台运行(可以看到实时日志,按 Ctrl+C 停止)
- echo 2. 后台运行(无窗口,日志输出到 logs\auto_execute.log)
- echo 3. 执行一次(只检查一次 pending 任务)
- echo 4. 前台运行 + 启用自动 Chat
- echo 5. 后台运行 + 启用自动 Chat
- echo 6. 查看服务状态
- echo 7. 停止服务
- echo 0. 退出
- echo.
- set /p choice="请输入选择 [1-7, 0]: "
- if "%choice%"=="1" goto :run_foreground
- if "%choice%"=="2" goto :run_background
- if "%choice%"=="3" goto :run_once
- if "%choice%"=="4" goto :run_foreground_chat
- if "%choice%"=="5" goto :run_background_chat
- if "%choice%"=="6" goto :check_status
- if "%choice%"=="7" goto :stop_service
- if "%choice%"=="0" goto :exit
- echo [错误] 无效的选择,请重新运行
- pause
- exit /b 1
- :run_foreground
- echo.
- echo [启动] 前台运行模式(检查间隔: 5分钟)
- echo [提示] 按 Ctrl+C 可停止服务
- echo.
- python scripts\auto_execute_tasks.py --interval 300
- pause
- goto :exit
- :run_background
- echo.
- echo [启动] 后台运行模式(检查间隔: 5分钟)
- echo [信息] 日志输出到: logs\auto_execute.log
- start /B "" python scripts\auto_execute_tasks.py --interval 300 > logs\auto_execute.log 2>&1
- echo.
- echo [成功] 服务已在后台启动!
- echo.
- echo [提示] 相关命令:
- echo - 查看日志: type logs\auto_execute.log
- echo - 停止服务: 再次运行此脚本选择 7
- echo.
- pause
- goto :exit
- :run_once
- echo.
- echo [执行] 单次检查模式
- echo.
- python scripts\auto_execute_tasks.py --once
- echo.
- pause
- goto :exit
- :run_foreground_chat
- echo.
- set /p chat_pos="请输入 Chat 输入框位置 (格式: x,y,直接回车使用默认): "
- echo.
- echo [启动] 前台运行模式 + 自动 Chat
- if "%chat_pos%"=="" (
- python scripts\auto_execute_tasks.py --interval 300 --enable-chat
- ) else (
- python scripts\auto_execute_tasks.py --interval 300 --enable-chat --chat-input-pos "%chat_pos%"
- )
- pause
- goto :exit
- :run_background_chat
- echo.
- set /p chat_pos="请输入 Chat 输入框位置 (格式: x,y,直接回车使用默认): "
- echo.
- echo [启动] 后台运行模式 + 自动 Chat
- echo [信息] 日志输出到: logs\auto_execute.log
- if "%chat_pos%"=="" (
- start /B "" python scripts\auto_execute_tasks.py --interval 300 --enable-chat > logs\auto_execute.log 2>&1
- ) else (
- start /B "" python scripts\auto_execute_tasks.py --interval 300 --enable-chat --chat-input-pos "%chat_pos%" > logs\auto_execute.log 2>&1
- )
- echo.
- echo [成功] 服务已在后台启动!
- echo.
- pause
- goto :exit
- :check_status
- echo.
- echo ========================================================
- echo 服务状态检查
- echo ========================================================
- echo.
- echo [进程状态]
- 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 }"
- echo.
- echo ========================================================
- echo 最近日志(最后 20 行)
- echo ========================================================
- echo.
- if exist "logs\auto_execute.log" (
- powershell -Command "Get-Content logs\auto_execute.log -Tail 20 -ErrorAction SilentlyContinue"
- ) else (
- echo [提示] 日志文件不存在
- )
- echo.
- echo ========================================================
- echo pending_tasks.json 状态
- echo ========================================================
- echo.
- if exist ".cursor\pending_tasks.json" (
- echo [文件存在] .cursor\pending_tasks.json
- 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 ' [空] 没有待处理任务' }"
- ) else (
- echo [提示] pending_tasks.json 不存在
- )
- echo.
- pause
- goto :exit
- :stop_service
- echo.
- echo [操作] 正在停止服务...
- 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 }"
- echo.
- pause
- goto :exit
- :exit
- endlocal
- exit /b 0
|