adding logging to WS layer until it is more stable
This commit is contained in:
parent
e49b81e7a4
commit
fba952696d
1 changed files with 12 additions and 3 deletions
|
@ -68,6 +68,11 @@ func WsUser(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
// user must have read access to the repository
|
// user must have read access to the repository
|
||||||
// in order to pass this message along
|
// in order to pass this message along
|
||||||
if role, err := datastore.GetPerm(ctx, user, work.Repo); err != nil || role.Read == false {
|
if role, err := datastore.GetPerm(ctx, user, work.Repo); err != nil || role.Read == false {
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("WS: Error getting permissions for repository %s. Error: %s\n", work.Repo.Name, err)
|
||||||
|
} else {
|
||||||
|
log.Printf("WS: No read access for repository %s\n", work.Repo.Name)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,16 +108,22 @@ func WsConsole(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
commit, err := datastore.GetCommit(ctx, int64(commitID))
|
commit, err := datastore.GetCommit(ctx, int64(commitID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("WS: Error retrieving commit by ID. %s\n", err)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
repo, err := datastore.GetRepo(ctx, commit.RepoID)
|
repo, err := datastore.GetRepo(ctx, commit.RepoID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("WS: Error retrieving repo by ID. %s\n", err)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
role, err := datastore.GetPerm(ctx, user, repo)
|
role, err := datastore.GetPerm(ctx, user, repo)
|
||||||
if err != nil || role.Read == false {
|
if err != nil || role.Read == false {
|
||||||
|
if user == nil {
|
||||||
|
log.Println("WS: Error getting User session")
|
||||||
|
}
|
||||||
|
log.Println("WS: Error retrieving Read permission.", err)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -121,6 +132,7 @@ func WsConsole(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
// and listen for stream updates.
|
// and listen for stream updates.
|
||||||
channel := pubsub.Lookup(ctx, commit.ID)
|
channel := pubsub.Lookup(ctx, commit.ID)
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
|
log.Println("WS: Error getting build stream from channel")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -151,19 +163,16 @@ func WsConsole(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
||||||
err := ws.WriteMessage(websocket.TextMessage, data)
|
err := ws.WriteMessage(websocket.TextMessage, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("websocket for commit %d closed. Err: %s\n", commitID, err)
|
|
||||||
ws.Close()
|
ws.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case <-sub.CloseNotify():
|
case <-sub.CloseNotify():
|
||||||
log.Printf("websocket for commit %d closed by client\n", commitID)
|
|
||||||
ws.Close()
|
ws.Close()
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
||||||
err := ws.WriteMessage(websocket.PingMessage, []byte{})
|
err := ws.WriteMessage(websocket.PingMessage, []byte{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("websocket for commit %d closed. Err: %s\n", commitID, err)
|
|
||||||
ws.Close()
|
ws.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue