fix(lint): Delete wait group and Add retry

- Deleted wait group
- Added retry in cache
This commit is contained in:
Medzik 2021-08-11 11:09:08 +00:00
parent 3432a74d23
commit afaae89a9d
3 changed files with 13 additions and 14 deletions

View file

@ -1,17 +1,24 @@
package backend
import (
"time"
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
)
var cacheURL []string
func cache() {
func cache(retry int) {
cacheURL = cacheURL[:0]
results, err := mongo.GetAll()
if checkErr(err, "get keys from db") {
return
if retry == 5 {
time.Sleep(500 * time.Millisecond)
cache(retry + 1)
} else {
return
}
}
for _, value := range results {

View file

@ -3,7 +3,6 @@ package backend
import (
"context"
"net/http"
"sync"
"time"
"gitlab.com/gaming0skar123/go/pingbot/common"
@ -17,24 +16,17 @@ var (
func ping() {
if cacheRetry >= config.Toml.Backend.Cache {
cache()
cache(0)
cacheRetry = 0
}
cacheRetry++
var wg sync.WaitGroup
for _, url := range cacheURL {
go loop(wg, url)
go loop(url)
}
wg.Wait()
}
func loop(wg sync.WaitGroup, url string) {
wg.Add(1)
defer wg.Done()
func loop(url string) {
// Timeout 1 minute
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

View file

@ -8,7 +8,7 @@ import (
func Ticker() {
// On Start
cache()
cache(0)
ping()
ticker := time.NewTicker(config.Toml.Backend.Ping * time.Minute)