Browse Source

fix(cli): retry download when panicing

Will retry to download plugins once if the zip lib panics.

closes #4068
bergquist 9 năm trước cách đây
mục cha
commit
f397d0ddd7
1 tập tin đã thay đổi với 14 bổ sung6 xóa
  1. 14 6
      pkg/cmd/grafana-cli/commands/install_command.go

+ 14 - 6
pkg/cmd/grafana-cli/commands/install_command.go

@@ -111,7 +111,21 @@ func RemoveGitBuildFromname(pluginname, filename string) string {
 	return r.ReplaceAllString(filename, pluginname+"/")
 }
 
+var retryCount = 0
+
 func downloadFile(pluginName, filepath, url string) (err error) {
+	defer func() {
+		if r := recover(); r != nil {
+			retryCount++
+			if retryCount == 1 {
+        log.Debug("\nFailed downloading. Will retry once.\n")
+				downloadFile(pluginName, filepath, url)
+			} else {
+        panic(r)
+      }
+		}
+	}()
+
 	resp, err := http.Get(url)
 	if err != nil {
 		return err
@@ -122,12 +136,6 @@ func downloadFile(pluginName, filepath, url string) (err error) {
 	if err != nil {
 		return err
 	}
-	log.Infof("Got statuscode %s from %s\n", resp.Status, url)
-
-	if resp.StatusCode == 302 || resp.StatusCode == 301 {
-		str, _ := ioutil.ReadAll(resp.Body)
-		log.Info("body %s\n\n", string(str))
-	}
 
 	r, err := zip.NewReader(bytes.NewReader(body), resp.ContentLength)
 	if err != nil {