make safer
This commit is contained in:
parent
ac1db5cf75
commit
8f38a1e601
29
main.go
29
main.go
@ -27,8 +27,13 @@ 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)
|
||||||
return
|
time.Sleep(5 * time.Second)
|
||||||
|
res, err = http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Got %v, not trying again", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
body, readErr := ioutil.ReadAll(res.Body)
|
body, readErr := ioutil.ReadAll(res.Body)
|
||||||
if readErr != nil {
|
if readErr != nil {
|
||||||
@ -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,13 +123,15 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
LoadPatches(&patch_list, *sourcePtr)
|
LoadPatches(&patch_list, *sourcePtr)
|
||||||
newest_patch := patch_list.Patches[len(patch_list.Patches)-1]
|
if len(patch_list.Patches) > 0 {
|
||||||
if newest_patch.PatchNumber != current_patch.PatchNumber {
|
newest_patch := patch_list.Patches[len(patch_list.Patches)-1]
|
||||||
current_patch = newest_patch
|
if newest_patch.PatchNumber != current_patch.PatchNumber {
|
||||||
if *hookPtr != "" {
|
current_patch = newest_patch
|
||||||
Notify(current_patch, *hookPtr)
|
if *hookPtr != "" {
|
||||||
} else {
|
Notify(current_patch, *hookPtr)
|
||||||
log.Printf("Patch %v found, no webhook\n", current_patch.PatchNumber)
|
} else {
|
||||||
|
log.Printf("Patch %v found, no webhook\n", current_patch.PatchNumber)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user