进程退出时停止上传带宽数据

This commit is contained in:
GoEdgeLab
2023-04-05 11:34:15 +08:00
parent d13018c51f
commit 31d1fc229c

View File

@@ -36,6 +36,8 @@ func init() {
})
events.On(events.EventQuit, func() {
SharedBandwidthStatManager.Cancel()
err := SharedBandwidthStatManager.Save()
if err != nil {
remotelogs.Error("STAT", "save bandwidth stats failed: "+err.Error())
@@ -277,6 +279,11 @@ func (this *BandwidthStatManager) Save() error {
return os.WriteFile(this.cacheFile, data, 0666)
}
// Cancel 取消上传
func (this *BandwidthStatManager) Cancel() {
this.ticker.Stop()
}
// 从本地缓存文件中恢复数据
func (this *BandwidthStatManager) recover() {
cacheData, err := os.ReadFile(this.cacheFile)