added lock to ipbl
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2021-12-28 00:11:12 +01:00
parent 8eecf6d52d
commit c5ab1fad2d
2 changed files with 26 additions and 22 deletions

View File

@ -17,6 +17,7 @@ import (
func main() { func main() {
var ctx context.Context var ctx context.Context
var cfg config.Config var cfg config.Config
var lock bool
cfg.GetConfig() cfg.GetConfig()
cfg.Options.Version = version cfg.Options.Version = version
@ -28,12 +29,12 @@ func main() {
defer cfg.Db.Close() defer cfg.Db.Close()
// Handles IP with no reverse DNS // Handles IP with no reverse DNS
go models.ScanIP(&cfg) go models.ScanIP(&cfg, &lock)
// Add cron task to handle them // Add cron task to handle them
cr := cron.New() cr := cron.New()
cr.AddFunc("0 * * * * *", func() { cr.AddFunc("0 * * * * *", func() {
models.ScanIP(&cfg) models.ScanIP(&cfg, &lock)
}) })
cr.Start() cr.Start()

View File

@ -64,7 +64,8 @@ func InsertIPBulk(cfg *config.Config, ips *[]IP) (numinserts int64, numfail int6
return return
} }
func ScanIP(cfg *config.Config) (err error) { func ScanIP(cfg *config.Config, lock *bool) (err error) {
if !*lock {
for { for {
var orphans = []IP{} var orphans = []IP{}
cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans) cfg.Db.Where("rdns IS NULL").Asc("ip").Find(&orphans)
@ -88,6 +89,8 @@ func ScanIP(cfg *config.Config) (err error) {
break break
} }
} }
}
*lock = false
return return
} }