优雅退出

This commit is contained in:
2026-04-11 23:12:13 +08:00
parent 0ad7c866d6
commit 079a4c6291
2 changed files with 92 additions and 16 deletions
+13 -2
View File
@@ -185,6 +185,17 @@ func main() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit
log.Println("shutdown signal received, flushing index...")
searchSrv.Flush() // 退出前刷盘,不丢数据
log.Println("shutdown signal received, initiating graceful shutdown...")
// 通知爬虫停止(不阻塞,等待爬虫内部协调)
crawl.Stop()
// 等待爬虫完全停止(包括 priority worker
crawl.WaitUntilStopped()
log.Println("crawler stopped")
// 最后刷盘,确保数据不丢失
log.Println("flushing index...")
searchSrv.Flush()
log.Println("shutdown complete")
}