Files
aiagent/scripts/startup/stop_aiagent.ps1
renjianbo 0606137d57 fix: schedule timezone bug + missing notifications + celery beat startup
- Timezone: compute_next_run now correctly interprets cron in the schedule's
  configured timezone (e.g., "0 8 * * *" with Asia/Shanghai = 8AM Beijing, not UTC)
- Notifications: agent_tasks now reuses pre-created execution records and calls
  notify_schedule_result on completion, so non-workflow agent schedules get
  DB notifications + Feishu webhook + Feishu app messages
- Duplicate execution: execute_agent_task accepts optional execution_id to reuse
  the record created by schedule_service instead of creating a second one
- Celery Beat: added to restart_backend_celery.ps1, stop_aiagent.ps1, and
  docker-compose.dev.yml; fixed repo-root path resolution in all PS1 scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-05 08:57:00 +08:00

88 lines
2.7 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$ErrorActionPreference = "SilentlyContinue"
Write-Host "== AIAgent stop ==" -ForegroundColor Cyan
function Get-PidsListeningOnPort([int]$Port) {
$pids = New-Object System.Collections.Generic.HashSet[int]
try {
netstat -ano | ForEach-Object {
$ln = $_.Trim()
if ($ln -notmatch "LISTENING") { return }
# 匹配 :8037 或 :3001 等端口后的 LISTENING 行末 PID
if ($ln -match ":$Port\s+.*LISTENING\s+(\d+)\s*$") {
[void]$pids.Add([int]$Matches[1])
}
}
} catch { }
return @($pids)
}
function Stop-OnPorts([int[]]$ports, [string]$name) {
$all = New-Object System.Collections.Generic.HashSet[int]
foreach ($p in $ports) {
foreach ($pid in (Get-PidsListeningOnPort $p)) {
[void]$all.Add($pid)
}
}
if ($all.Count -eq 0) {
Write-Host "[SKIP] ${name}: no listener on ports $($ports -join ',')" -ForegroundColor DarkGray
return
}
foreach ($pid in $all) {
if ($pid -le 4) { continue }
try {
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
Write-Host "[OK] stopped ${name} PID=$pid" -ForegroundColor Green
} catch {
Write-Host "[WARN] failed to stop ${name} PID=$pid" -ForegroundColor Yellow
}
}
}
# 后端 API8037 / 8041 备用)
Stop-OnPorts @(8037, 8041) "backend-api"
# 前端 Vite3001
Stop-OnPorts @(3001) "frontend-dev"
# Redis6379仅当监听在本地开发端口时结束若与其它项目共用请谨慎
Stop-OnPorts @(6379) "redis"
# Celery Worker / Beat不监听端口需要按命令行匹配
$celeryPatterns = @(
@{Pattern='celery\s+-A\s+app\.core\.celery_app\s+worker'; Name='celery-worker'},
@{Pattern='celery\s+-A\s+app\.core\.celery_app\s+beat'; Name='celery-beat'}
)
foreach ($cp in $celeryPatterns) {
$targets = Get-CimInstance Win32_Process | Where-Object {
$_.CommandLine -and $_.CommandLine -match $cp.Pattern
}
if (-not $targets) {
Write-Host "[SKIP] $($cp.Name): no matching process" -ForegroundColor DarkGray
}
foreach ($p in $targets) {
try {
Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue
Write-Host "[OK] stopped $($cp.Name) PID=$($p.ProcessId)" -ForegroundColor Green
} catch {
Write-Host "[WARN] failed to stop $($cp.Name) PID=$($p.ProcessId)" -ForegroundColor Yellow
}
}
}
Start-Sleep -Milliseconds 600
Write-Host ""
Write-Host "Port check:" -ForegroundColor Cyan
foreach ($port in 3001, 8037, 8041, 6379) {
$line = netstat -ano | Select-String ":$port\s+.*LISTENING" | Select-Object -First 1
if ($line) {
Write-Host " - ${port}: LISTEN" -ForegroundColor Yellow
} else {
Write-Host " - ${port}: free" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "DONE: stop script finished" -ForegroundColor Green