make safer
This commit is contained in:
parent
ac1db5cf75
commit
8f38a1e601
13
main.go
13
main.go
@ -27,9 +27,14 @@ func LoadPatches(pl *PatchList, url string) {
|
|||||||
res, err := http.Get(url)
|
res, err := http.Get(url)
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("Got %v, retrying in 5s", err)
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
res, err = http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Got %v, not trying again", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
body, readErr := ioutil.ReadAll(res.Body)
|
body, readErr := ioutil.ReadAll(res.Body)
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
log.Fatal(readErr)
|
log.Fatal(readErr)
|
||||||
@ -101,6 +106,10 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
LoadPatches(&patch_list, *sourcePtr)
|
LoadPatches(&patch_list, *sourcePtr)
|
||||||
|
|
||||||
|
if len(patch_list.Patches) <= 0 {
|
||||||
|
log.Fatal("error getting initial patch list")
|
||||||
|
}
|
||||||
|
|
||||||
current_patch = patch_list.Patches[len(patch_list.Patches)-1]
|
current_patch = patch_list.Patches[len(patch_list.Patches)-1]
|
||||||
log.Println("Started bot, loaded patch list")
|
log.Println("Started bot, loaded patch list")
|
||||||
log.Printf("Starting on patch %v", current_patch.PatchNumber)
|
log.Printf("Starting on patch %v", current_patch.PatchNumber)
|
||||||
@ -114,6 +123,7 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
LoadPatches(&patch_list, *sourcePtr)
|
LoadPatches(&patch_list, *sourcePtr)
|
||||||
|
if len(patch_list.Patches) > 0 {
|
||||||
newest_patch := patch_list.Patches[len(patch_list.Patches)-1]
|
newest_patch := patch_list.Patches[len(patch_list.Patches)-1]
|
||||||
if newest_patch.PatchNumber != current_patch.PatchNumber {
|
if newest_patch.PatchNumber != current_patch.PatchNumber {
|
||||||
current_patch = newest_patch
|
current_patch = newest_patch
|
||||||
@ -124,5 +134,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user