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 {
|
if err := newInstance.LoadMaxMindDB(parent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if instance != nil {
|
|
||||||
instance.task.Finish("updated")
|
|
||||||
}
|
|
||||||
instance = newInstance
|
instance = newInstance
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
type MaxMind struct {
|
type MaxMind struct {
|
||||||
*Config
|
*Config
|
||||||
lastUpdate time.Time
|
lastUpdate time.Time
|
||||||
task *task.Task
|
|
||||||
db struct {
|
db struct {
|
||||||
*maxminddb.Reader
|
*maxminddb.Reader
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
@ -70,7 +69,9 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.task = parent.Subtask("maxmind_db", true)
|
init := parent.Subtask("maxmind_db", true)
|
||||||
|
defer init.Finish(nil)
|
||||||
|
|
||||||
path := dbPath(cfg)
|
path := dbPath(cfg)
|
||||||
reader, err := maxmindDBOpen(path)
|
reader, err := maxmindDBOpen(path)
|
||||||
valid := true
|
valid := true
|
||||||
|
@ -95,7 +96,7 @@ func (cfg *MaxMind) LoadMaxMindDB(parent task.Parent) gperr.Error {
|
||||||
} else {
|
} else {
|
||||||
cfg.Logger().Info().Msg("MaxMind DB loaded")
|
cfg.Logger().Info().Msg("MaxMind DB loaded")
|
||||||
cfg.db.Reader = reader
|
cfg.db.Reader = reader
|
||||||
go cfg.scheduleUpdate(cfg.task)
|
go cfg.scheduleUpdate(parent)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -114,7 +115,7 @@ func (cfg *MaxMind) setLastUpdate(t time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *MaxMind) scheduleUpdate(parent task.Parent) {
|
func (cfg *MaxMind) scheduleUpdate(parent task.Parent) {
|
||||||
task := parent.Subtask("schedule_update", true)
|
task := parent.Subtask("maxmind_schedule_update", true)
|
||||||
ticker := time.NewTicker(updateInterval)
|
ticker := time.NewTicker(updateInterval)
|
||||||
|
|
||||||
cfg.loadLastUpdate()
|
cfg.loadLastUpdate()
|
||||||
|
|
Loading…
Add table
Reference in a new issue