更新热存储功能

This commit is contained in:
eatmoreapple 2023-01-10 19:08:33 +08:00
parent 87036e2c94
commit fb20b70ebf
2 changed files with 7 additions and 8 deletions

View File

@ -63,10 +63,8 @@ func (h *HotLogin) Login(bot *Bot) error {
if err := h.loginWrapper(bot); err != nil {
return err
}
if h.opt.syncDuration > 0 {
syncer := NewHotReloadStorageSyncer(bot, h.opt.syncDuration)
go func() { _ = syncer.Sync() }()
}
syncer := NewHotReloadStorageSyncer(bot, h.opt.syncDuration)
go func() { _ = syncer.Sync() }()
return nil
}
@ -153,10 +151,8 @@ func (p *PushLogin) Login(bot *Bot) error {
if err := p.loginWrapper(bot); err != nil {
return err
}
if p.opt.syncDuration > 0 {
syncer := NewHotReloadStorageSyncer(bot, p.opt.syncDuration)
go func() { _ = syncer.Sync() }()
}
syncer := NewHotReloadStorageSyncer(bot, p.opt.syncDuration)
go func() { _ = syncer.Sync() }()
return nil
}

View File

@ -84,6 +84,9 @@ type HotReloadStorageSyncer struct {
// Sync 定时同步数据到登陆存储中
func (h *HotReloadStorageSyncer) Sync() error {
if h.duration <= 0 {
return nil
}
// 定时器
ticker := time.NewTicker(h.duration)
for {