Implement merge request review comments
This commit is contained in:
@ -8,43 +8,27 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var connUpgrade = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
}
|
||||
|
||||
// connectToRunner is a placeholder for now and will become the endpoint for websocket connections.
|
||||
// connectToRunner is the endpoint for websocket connections.
|
||||
func connectToRunner(writer http.ResponseWriter, request *http.Request) {
|
||||
r, _ := runner.FromContext(request.Context())
|
||||
executionId := request.URL.Query().Get(ExecutionIdKey)
|
||||
executionRequest, ok := r.Execution(runner.ExecutionId(executionId))
|
||||
executionId := runner.ExecutionId(request.URL.Query().Get(ExecutionIdKey))
|
||||
_, ok := r.Execution(executionId)
|
||||
if !ok {
|
||||
writeNotFound(writer, errors.New("executionId does not exist"))
|
||||
return
|
||||
}
|
||||
log.
|
||||
WithField("runnerId", r.Id()).
|
||||
WithField("executionId", executionId).
|
||||
WithField("command", executionRequest.Command).
|
||||
Info("Running execution")
|
||||
connClient, err := connUpgrade.Upgrade(writer, request, nil)
|
||||
connUpgrader := websocket.Upgrader{}
|
||||
connClient, err := connUpgrader.Upgrade(writer, request, nil)
|
||||
if err != nil {
|
||||
log.WithError(err).Warn("Connection upgrade failed")
|
||||
return
|
||||
}
|
||||
err = connClient.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
if err != nil {
|
||||
writeInternalServerError(writer, err, dto.ErrorUnknown)
|
||||
return
|
||||
}
|
||||
defer func(connClient *websocket.Conn) {
|
||||
err := connClient.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
if err != nil {
|
||||
writeInternalServerError(writer, err, dto.ErrorUnknown)
|
||||
}
|
||||
}(connClient)
|
||||
|
||||
// ToDo: Implement communication forwarding
|
||||
err, ok = r.Execute(runner.ExecutionId(executionId))
|
||||
if !ok {
|
||||
writeBadRequest(writer, errors.New("invalid Execution Id"))
|
||||
return
|
||||
} else if err != nil {
|
||||
writeInternalServerError(writer, err, dto.ErrorUnknown)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user