summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimportd
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at/rhimportd')
-rw-r--r--src/helsinki.at/rhimportd/ctrlWebSocket.go34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/helsinki.at/rhimportd/ctrlWebSocket.go b/src/helsinki.at/rhimportd/ctrlWebSocket.go
index 346dd6a..92e261a 100644
--- a/src/helsinki.at/rhimportd/ctrlWebSocket.go
+++ b/src/helsinki.at/rhimportd/ctrlWebSocket.go
@@ -97,15 +97,15 @@ func sendWebSocketErrorResponse(ws *websocket.Conn, id string, code int, err_str
}
type webSocketSession struct {
- id string
- session *rhimport.SessionChan
- respchan chan webSocketResponseData
- donechan chan rhimport.ImportResult
+ id string
+ session *rhimport.SessionChan
+ progresschan chan rhimport.ProgressData
+ donechan chan rhimport.ImportResult
}
func newWebSocketSession() *webSocketSession {
session := &webSocketSession{}
- session.respchan = make(chan webSocketResponseData, 10)
+ session.progresschan = make(chan rhimport.ProgressData, 10)
session.donechan = make(chan rhimport.ImportResult, 1)
return session
}
@@ -114,17 +114,17 @@ func webSocketProgress(step int, step_name string, progress float64, userdata in
if math.IsNaN(progress) {
progress = 0.0
}
- session := userdata.(*webSocketSession)
+ c := userdata.(chan<- rhimport.ProgressData)
select {
- case session.respchan <- webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, step, step_name, progress * 100, 0, 0}:
+ case c <- rhimport.ProgressData{step, step_name, progress}:
default:
}
return true
}
func webSocketDone(res rhimport.ImportResult, userdata interface{}) bool {
- session := userdata.(*webSocketSession)
- session.donechan <- res
+ c := userdata.(chan<- rhimport.ImportResult)
+ c <- res
return true
}
@@ -150,10 +150,10 @@ func (self *webSocketSession) startNewSession(reqdata *webSocketRequestData, con
}
self.id = id
self.session = s
- if err := s.AddDoneHandler(self, webSocketDone); err != nil {
+ if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil {
return http.StatusInternalServerError, err.Error()
}
- if err := s.AddProgressHandler(self, webSocketProgress); err != nil {
+ if err := s.AddProgressHandler((chan<- rhimport.ProgressData)(self.progresschan), webSocketProgress); err != nil {
return http.StatusInternalServerError, err.Error()
}
s.Run(time.Duration(reqdata.Timeout) * time.Second)
@@ -167,10 +167,10 @@ func (self *webSocketSession) reconnectSession(reqdata *webSocketRequestData, se
}
self.id = reqdata.Id
self.session = s
- if err := s.AddDoneHandler(self, webSocketDone); err != nil {
+ if err := s.AddDoneHandler((chan<- rhimport.ImportResult)(self.donechan), webSocketDone); err != nil {
return http.StatusInternalServerError, err.Error()
}
- if err := s.AddProgressHandler(self, webSocketProgress); err != nil {
+ if err := s.AddProgressHandler((chan<- rhimport.ProgressData)(self.progresschan), webSocketProgress); err != nil {
return http.StatusInternalServerError, err.Error()
}
s.Run(time.Duration(reqdata.Timeout) * time.Second)
@@ -222,10 +222,10 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, ws *websocket.
sendWebSocketErrorResponse(ws, "", http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command))
return
}
- case respdata := <-session.respchan:
- sendWebSocketResponse(ws, &respdata)
- case donedata := <-session.donechan:
- sendWebSocketResponse(ws, &webSocketResponseData{donedata.ResponseCode, "DONE", donedata.ErrorString, session.id, 0, "", 100.0, donedata.Cart, donedata.Cut})
+ case p := <-session.progresschan:
+ sendWebSocketResponse(ws, &webSocketResponseData{http.StatusOK, "PROGRESS", "", session.id, p.Step, p.StepName, p.Progress * 100, 0, 0})
+ case d := <-session.donechan:
+ sendWebSocketResponse(ws, &webSocketResponseData{d.ResponseCode, "DONE", d.ErrorString, session.id, 0, "", 100.0, d.Cart, d.Cut})
// TODO: send close message at this point?
}
}