mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-04-02 11:05:18 +08:00
改进退出程序时关闭数据库写入
This commit is contained in:
@@ -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