mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
改进退出程序时关闭数据库写入
This commit is contained in:
@@ -504,6 +504,10 @@ func (this *FileListDB) CleanAll() error {
|
||||
}
|
||||
|
||||
func (this *FileListDB) Close() error {
|
||||
if this.isClosed {
|
||||
return nil
|
||||
}
|
||||
|
||||
this.isClosed = true
|
||||
this.isReady = false
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
remotelogs.Println("CACHE", "quiting cache manager")
|
||||
SharedManager.UpdatePolicies([]*serverconfigs.HTTPCachePolicy{})
|
||||
})
|
||||
|
||||
@@ -24,6 +24,11 @@ func On(event Event, callback func()) {
|
||||
OnKey(event, nil, callback)
|
||||
}
|
||||
|
||||
func OnClose(callback func()) {
|
||||
On(EventQuit, callback)
|
||||
On(EventTerminated, callback)
|
||||
}
|
||||
|
||||
// OnKey 使用Key增加事件回调
|
||||
func OnKey(event Event, key interface{}, callback func()) {
|
||||
if key == nil {
|
||||
|
||||
@@ -161,7 +161,7 @@ ON "` + this.itemTableName + `" (
|
||||
this.db = db
|
||||
|
||||
goman.New(func() {
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
_ = this.Close()
|
||||
this.cleanTicker.Stop()
|
||||
})
|
||||
|
||||
@@ -29,7 +29,7 @@ func init() {
|
||||
SharedIPListManager.Start()
|
||||
})
|
||||
})
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
SharedIPListManager.Stop()
|
||||
})
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
SharedManager.Quit()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -27,10 +27,9 @@ func init() {
|
||||
sharedOCSPTask.Start()
|
||||
})
|
||||
})
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
sharedOCSPTask.Stop()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// OCSPUpdateTask 更新OCSP任务
|
||||
|
||||
@@ -26,7 +26,7 @@ func init() {
|
||||
sharedSyncAPINodesTask.Start()
|
||||
})
|
||||
})
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
sharedSyncAPINodesTask.Stop()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func init() {
|
||||
})
|
||||
})
|
||||
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
SharedBandwidthStatManager.Cancel()
|
||||
|
||||
err := SharedBandwidthStatManager.Save()
|
||||
|
||||
@@ -30,7 +30,7 @@ type DB struct {
|
||||
func NewDB(path string) *DB {
|
||||
var db = &DB{path: path}
|
||||
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
_ = db.Close()
|
||||
})
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ func (this *Batch) OnFail(callback func(err error)) {
|
||||
}
|
||||
|
||||
func (this *Batch) Add(query string, args ...any) {
|
||||
if this.isClosed {
|
||||
return
|
||||
}
|
||||
this.queue <- &batchItem{
|
||||
query: query,
|
||||
args: args,
|
||||
@@ -139,6 +142,10 @@ func (this *Batch) beginTx() *sql.Tx {
|
||||
}
|
||||
|
||||
func (this *Batch) execItem(tx *sql.Tx, item *batchItem) error {
|
||||
if this.isClosed {
|
||||
return nil
|
||||
}
|
||||
|
||||
if this.enableStat {
|
||||
defer SharedQueryStatManager.AddQuery(item.query).End()
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func init() {
|
||||
SharedFreeHoursManager.Start()
|
||||
})
|
||||
})
|
||||
events.On(events.EventQuit, func() {
|
||||
events.OnClose(func() {
|
||||
SharedFreeHoursManager.Stop()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user