diff options
author | Markus Grüneis <gimpf@gimpf.org> | 2014-10-24 20:15:05 +0200 |
---|---|---|
committer | Markus Grüneis <gimpf@gimpf.org> | 2014-10-24 20:15:05 +0200 |
commit | 29a58aa13af219763202e4287bfa004b9a41f3ae (patch) | |
tree | 5b85433c0a2fdcf5f7bde589088d5ede68c994d0 /src/hub/src | |
parent | hub: Retry on GET /lastupdate error instead of panic. (diff) |
hub: appendMany now supports response
Diffstat (limited to 'src/hub/src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srv.go | 16 | ||||
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvWeb.go | 10 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srv.go b/src/hub/src/spreadspace.org/sfive/s5srv.go index 1839419..59a6409 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srv.go +++ b/src/hub/src/spreadspace.org/sfive/s5srv.go @@ -1,11 +1,16 @@ package sfive +type appendManyToken struct { + data []StatisticsData + response chan bool +} + type StatsSinkServer struct { store sqliteStore quit chan bool done chan bool appendData chan StatisticsData - appendManyData chan []StatisticsData + appendManyData chan appendManyToken // chan []StatisticsData } func (self StatsSinkServer) appendActor() { @@ -19,10 +24,13 @@ func (self StatsSinkServer) appendActor() { if err != nil { s5l.Printf("failed to store data: %v\n", err) } - case values := <-self.appendManyData: - err := self.store.AppendMany(values) + case token := <-self.appendManyData: + err := self.store.AppendMany(token.data) if err != nil { s5l.Printf("failed to store many data: %v\n", err) + token.response <- false + } else { + token.response <- true } } } @@ -49,7 +57,7 @@ func NewServer(dbPath string) (server *StatsSinkServer, err error) { server.quit = make(chan bool) server.done = make(chan bool) server.appendData = make(chan StatisticsData, 100) - server.appendManyData = make(chan []StatisticsData, 5) + server.appendManyData = make(chan appendManyToken, 5) go server.appendActor() return } diff --git a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go index 2d39740..0013ea4 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvWeb.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvWeb.go @@ -157,7 +157,15 @@ func (self StatsSinkServer) postUpdate(c web.C, w http.ResponseWriter, r *http.R container := StatisticsDataContainer{} err = json.Unmarshal(buffer, &container) if err == nil { - self.appendManyData <- container.Data + token := appendManyToken{ + data: container.Data, + response: make(chan bool, 2)} + defer close(token.response) + self.appendManyData <- token + success := <-token.response + if !success { + http.Error(w, "failed to store data", http.StatusInternalServerError) + } return } |