diff options
author | Markus Grüneis <gimpf@gimpf.org> | 2014-10-24 19:47:57 +0200 |
---|---|---|
committer | Markus Grüneis <gimpf@gimpf.org> | 2014-10-24 19:47:57 +0200 |
commit | 5555e1c5c0f1c8faeac01a78aa3f427206c1d8a0 (patch) | |
tree | 416e7bb4374dd48c650dbb3827f98580ad638014 /src/hub/src | |
parent | hub: Change viz-dir default. (diff) |
hub: Retry on GET /lastupdate error instead of panic.
Diffstat (limited to 'src/hub/src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvForward.go | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForward.go b/src/hub/src/spreadspace.org/sfive/s5srvForward.go index 4707dd5..b5ff45a 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvForward.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvForward.go @@ -20,33 +20,39 @@ func findMaxId(values []StatisticsData) int { return maxId } -func (self StatsSinkServer) getLastUpdate(baseurl string, client *http.Client) (latestId int, storeId string) { - storeId, err := self.store.GetStoreId() +func (self StatsSinkServer) getLastUpdate(baseurl string, client *http.Client) (latestId int, storeId string, err error) { + storeId, err = self.store.GetStoreId() if err != nil { - s5l.Panicf("fwd: failed to get own hubid: %v\n", err) + s5l.Printf("fwd: failed to get own hubid: %v\n", err) + return } resp, err := client.Get(baseurl + "/lastupdate/" + storeId) if err != nil { - s5l.Panicf("fwd: failed to query for lastupdate: %v\n", err) + s5l.Printf("fwd: failed to query for lastupdate: %v\n", err) + return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - s5l.Panicf("fwd: server failed to fulfill query for lastupdate: %v\n", resp.StatusCode) + s5l.Printf("fwd: server failed to fulfill query for lastupdate: %v\n", resp.StatusCode) + return } body, err := ioutil.ReadAll(resp.Body) if err != nil { - s5l.Panicf("fwd: failed to read lastupdate response: %v\n", err) + s5l.Printf("fwd: failed to read lastupdate response: %v\n", err) + return } if len(body) == 0 { latestId = -1 } else { - tid, err := strconv.ParseInt(string(body), 10, 32) - if err != nil { - s5l.Panicf("fwd: invalid lastupdate response: %v\n", err) + tid, errl := strconv.ParseInt(string(body), 10, 32) + if errl != nil { + s5l.Printf("fwd: invalid lastupdate response: %v\n", err) + err = errl + return } latestId = int(tid) } @@ -58,7 +64,12 @@ func (self StatsSinkServer) handleForwarding(baseurl string, client *http.Client url := baseurl + "/updates" tryResync: for { - lastId, _ := self.getLastUpdate(baseurl, client) + lastId, _, err := self.getLastUpdate(baseurl, client) + + if err != nil { + time.Sleep(5 * time.Second) + continue tryResync + } nextBatch: for { @@ -90,7 +101,7 @@ tryResync: lastId = findMaxId(updates) s5tl.Printf("fwd: new lastid: %d", lastId) - time.Sleep(100 * time.Millisecond) + time.Sleep(2 * time.Second) } } } |