From 3af538832b15cbde4bd102bee53abccdaf344637 Mon Sep 17 00:00:00 2001 From: Tommaso Bailetti Date: Tue, 17 Sep 2024 11:00:21 +0200 Subject: [PATCH] feat(api): added goroutine refresh geoip database --- api/main.go | 2 ++ api/routines/routines.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/api/main.go b/api/main.go index bc31f1a..0d60955 100644 --- a/api/main.go +++ b/api/main.go @@ -59,6 +59,8 @@ func main() { // init geoip utils.InitGeoIP() + // start geoip refresh loop + go routines.RefreshGeoIPDatabase() // starts remote info loop go routines.RefreshRemoteInfoLoop() diff --git a/api/routines/routines.go b/api/routines/routines.go index ab75777..386207d 100644 --- a/api/routines/routines.go +++ b/api/routines/routines.go @@ -10,6 +10,7 @@ package routines import ( + "github.com/NethServer/nethsecurity-controller/api/utils" "time" "github.com/NethServer/nethsecurity-controller/api/logs" @@ -33,3 +34,13 @@ func RefreshRemoteInfoLoop() { } } } + +func RefreshGeoIPDatabase() { + ticker := time.NewTicker(24 * time.Hour) + for range ticker.C { + err := utils.InitGeoIP() + if err != nil { + logs.Logs.Println("[ERR][ROUTINE] loop for geoip database failed: " + err.Error()) + } + } +}