diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-06-27 19:36:54 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-06-27 19:36:54 (GMT) |
commit | 902279bc40475d9ca4dd2c8e9928861027fd306d (patch) | |
tree | f8d4fadb7e708eace39ef47e0359aea49aa46264 /src | |
parent | 2dac2d1b858ae686dbc6f64982024cdd39b1dddc (diff) |
progress callbacks now report current and total
Diffstat (limited to 'src')
-rw-r--r-- | src/rhimportd/ctrlTelnet.go | 4 | ||||
-rw-r--r-- | src/rhimportd/ctrlWebSocket.go | 26 |
2 files changed, 21 insertions, 9 deletions
diff --git a/src/rhimportd/ctrlTelnet.go b/src/rhimportd/ctrlTelnet.go index b86965e..65357e7 100644 --- a/src/rhimportd/ctrlTelnet.go +++ b/src/rhimportd/ctrlTelnet.go @@ -259,9 +259,9 @@ func telnetShow(c *telgo.Client, args []string, conf *rhimport.Config, db *rddb. return false } -func telnetProgressCallback(step int, stepName string, progress float64, userdata interface{}) bool { +func telnetProgressCallback(step int, stepName string, current, total float64, userdata interface{}) bool { c := userdata.(*telgo.Client) - c.Say("%s: %3.2f%%\r", stepName, progress*100) + c.Say("%s: %3.2f%%\r", stepName, (current/total)*100) return true } diff --git a/src/rhimportd/ctrlWebSocket.go b/src/rhimportd/ctrlWebSocket.go index edd4b9d..410c209 100644 --- a/src/rhimportd/ctrlWebSocket.go +++ b/src/rhimportd/ctrlWebSocket.go @@ -96,6 +96,8 @@ type webSocketResponseProgressData struct { webSocketResponseBaseData Step int `json:"PROGRESS_STEP"` StepName string `json:"PROGRESS_STEP_NAME"` + Current float64 `json:"CURRENT"` + Total float64 `json:"TOTAL"` Progress float64 `json:"PROGRESS"` } @@ -138,7 +140,12 @@ func sendWebSocketListResponse(ws *websocket.Conn, sessions map[string]string) { sendWebSocketResponse(ws, rd) } -func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step int, stepName string, progress float64) { +func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step int, stepName string, current, total float64) { + progress := current / total + if math.IsNaN(progress) || math.IsInf(progress, 0) { + progress = 0.0 + } + rd := &webSocketResponseProgressData{} rd.ResponseCode = http.StatusOK rd.Type = "progress" @@ -147,7 +154,9 @@ func sendWebSocketProgressResponse(ws *websocket.Conn, id, refid string, step in rd.RefId = refid rd.Step = step rd.StepName = stepName - rd.Progress = progress + rd.Current = current + rd.Total = total + rd.Progress = progress * 100 sendWebSocketResponse(ws, rd) } @@ -178,13 +187,16 @@ func newWebSocketSession() *webSocketSession { return session } -func webSocketProgress(step int, stepName string, progress float64, userdata interface{}) bool { - if math.IsNaN(progress) { - progress = 0.0 +func webSocketProgress(step int, stepName string, current, total float64, userdata interface{}) bool { + if math.IsNaN(current) || math.IsInf(current, 0) { + current = 0.0 + } + if math.IsNaN(total) || math.IsInf(total, 0) { + total = 0.0 } c := userdata.(chan<- rhimport.ProgressData) select { - case c <- rhimport.ProgressData{Step: step, StepName: stepName, Progress: progress}: + case c <- rhimport.ProgressData{Step: step, StepName: stepName, Current: current, Total: total}: default: } return true @@ -299,7 +311,7 @@ func webSocketSessionHandler(reqchan <-chan webSocketRequestData, binchan <-chan sendWebSocketErrorResponse(ws, http.StatusBadRequest, fmt.Sprintf("unknown command '%s'", reqdata.Command)) } case p := <-session.progresschan: - sendWebSocketProgressResponse(ws, session.id, session.refId, p.Step, p.StepName, p.Progress*100) + sendWebSocketProgressResponse(ws, session.id, session.refId, p.Step, p.StepName, p.Current, p.Total) case d := <-session.donechan: sendWebSocketDoneResponse(ws, d.ResponseCode, d.ErrorString, session.id, session.refId, d.Cart, d.Cut) // TODO: send close message at this point? |