优雅退出
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user