mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
fix: timeout waiting for maxmind db on shutdown
This commit is contained in:
parent
8ef8015a7f
commit
797d88772f
2 changed files with 5 additions and 7 deletions
|
@ -12,9 +12,6 @@ func SetInstance(parent task.Parent, cfg *Config) gperr.Error {
|
|||
if err := newInstance.LoadMaxMindDB(parent); err != nil {
|
||||
return err
|
||||
}
|
||||
if instance != nil {
|
||||
instance.task.Finish("updated")
|
||||
}
|
||||
instance = newInstance
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
type MaxMind struct {
|
||||
*Config
|
||||
lastUpdate time.Time
|
||||
task *task.Task
|
||||
db struct {
|
||||
*maxminddb.Reader
|
||||
sync.RWMutex
|
||||
|
@ -70,7 +69,9 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
cfg.task = parent.Subtask("maxmind_db", true)
|
||||
init := parent.Subtask("maxmind_db", true)
|
||||
defer init.Finish(nil)
|
||||
|
||||
path := dbPath(cfg)
|
||||
reader, err := maxmindDBOpen(path)
|
||||
valid := true
|
||||
|
@ -95,7 +96,7 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
|
|||
} else {
|
||||
cfg.Logger().Info().Msg("MaxMind DB loaded")
|
||||
cfg.db.Reader = reader
|
||||
go cfg.scheduleUpdate(cfg.task)
|
||||
go cfg.scheduleUpdate(parent)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -114,7 +115,7 @@ func (cfg *MaxMind) setLastUpdate(t time.Time) {
|
|||
}
|
||||
|
||||
func (cfg *MaxMind) scheduleUpdate(parent task.Parent) {
|
||||
task := parent.Subtask("schedule_update", true)
|
||||
task := parent.Subtask("maxmind_schedule_update", true)
|
||||
ticker := time.NewTicker(updateInterval)
|
||||
|
||||
cfg.loadLastUpdate()
|
||||
|
|
Loading…
Add table
Reference in a new issue