diff --git a/server/app/index.html b/server/app/index.html index b6a92689..b53cb0dc 100644 --- a/server/app/index.html +++ b/server/app/index.html @@ -31,6 +31,8 @@ + + diff --git a/server/app/scripts/app.js b/server/app/scripts/app.js index 7da26666..a113c590 100644 --- a/server/app/scripts/app.js +++ b/server/app/scripts/app.js @@ -213,11 +213,11 @@ app.controller("CommitController", function($scope, $http, $routeParams, stdout, var name = $routeParams.name; var branch = $routeParams.branch; var commit = $routeParams.commit; + $scope.console=''; feed.subscribe(function(item) { - // if the - if (item.commit.sha == commit - && item.commit.branch == branch) { + if (item.commit.sha == commit && + item.commit.branch == branch) { $scope.commit = item.commit; $scope.$apply(); } else { @@ -247,15 +247,20 @@ app.controller("CommitController", function($scope, $http, $routeParams, stdout, if (data.status!='Started' && data.status!='Pending') { $http({method: 'GET', url: '/v1/repos/'+remote+'/'+owner+"/"+name+"/branches/"+branch+"/commits/"+commit+"/console"}). success(function(data, status, headers, config) { - $scope.console = data; + var lineFormatter = new Drone.LineFormatter(); + var el = document.querySelector('#output'); + angular.element(el).append(lineFormatter.format(data)); }). error(function(data, status, headers, config) { console.log(data); }); + return; } + var lineFormatter = new Drone.LineFormatter(); + var el = document.querySelector('#output'); stdout.subscribe(data.id, function(out){ - console.log(out); + angular.element(el).append(lineFormatter.format(out)); }); }). error(function(data, status, headers, config) { diff --git a/server/app/scripts/commit_updates.js b/server/app/scripts/commit_updates.js index 6493f355..dd449200 100644 --- a/server/app/scripts/commit_updates.js +++ b/server/app/scripts/commit_updates.js @@ -3,49 +3,29 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } (function () { - Drone.CommitUpdates = function(socket) { - if(typeof(socket) === "string") { - var url = [(window.location.protocol == 'https:' ? 'wss' : 'ws'), - '://', - window.location.host, - socket].join('') - this.socket = new WebSocket(url); - } else { - this.socket = socket; - } - + Drone.Console = function() { this.lineFormatter = new Drone.LineFormatter(); - this.attach(); } - Drone.CommitUpdates.prototype = { + Drone.Console.prototype = { lineBuffer: "", autoFollow: false, - startOutput: function(el) { + start: function(el) { if(typeof(el) === 'string') { this.el = document.getElementById(el); } else { this.el = el; } - if(!this.reqId) { - this.updateScreen(); - } + this.update(); }, - stopOutput: function() { + stop: function() { this.stoppingRefresh = true; }, - attach: function() { - this.socket.onopen = this.onOpen; - this.socket.onerror = this.onError; - this.socket.onmessage = this.onMessage.bind(this); - this.socket.onclose = this.onClose; - }, - - updateScreen: function() { + update: function() { if(this.lineBuffer.length > 0) { this.el.innerHTML += this.lineBuffer; this.lineBuffer = ''; @@ -62,21 +42,8 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } } }, - onOpen: function() { - console.log('output websocket open'); - }, - - onError: function(e) { - console.log('websocket error: ' + e); - }, - - onMessage: function(e) { + write: function(e) { this.lineBuffer += this.lineFormatter.format(e.data); - }, - - onClose: function(e) { - console.log('output websocket closed: ' + JSON.stringify(e)); - window.location.reload(); } }; diff --git a/server/app/scripts/services/stdout.js b/server/app/scripts/services/stdout.js index 5e353e48..72543ae5 100644 --- a/server/app/scripts/services/stdout.js +++ b/server/app/scripts/services/stdout.js @@ -24,6 +24,7 @@ angular.module('app').service('stdout', ['$window', function($window) { this.unsubscribe = function() { callback = undefined; if (websocket != undefined) { + console.log('unsubscribing websocket at '+websocket.url); websocket.close(); } }; diff --git a/server/app/views/commit.html b/server/app/views/commit.html index 0c9bc03f..e6cd5ba6 100644 --- a/server/app/views/commit.html +++ b/server/app/views/commit.html @@ -29,6 +29,6 @@ {{ commit.sha | shortHash}} -
{{ console }}+ \ No newline at end of file diff --git a/server/handler/hook.go b/server/handler/hook.go index 20ef5898..c88575db 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -46,8 +46,6 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error { return nil } - //fmt.Printf("%#v", hook) - // fetch the repository from the database repo, err := h.repos.FindName(remote.GetHost(), hook.Owner, hook.Repo) if err != nil { diff --git a/server/handler/ws.go b/server/handler/ws.go index ec32e338..ff69da07 100644 --- a/server/handler/ws.go +++ b/server/handler/ws.go @@ -1,6 +1,7 @@ package handler import ( + "log" "net/http" "strconv" "time" @@ -157,16 +158,19 @@ func (h *WsHandler) WsConsole(w http.ResponseWriter, r *http.Request) error { ws.SetWriteDeadline(time.Now().Add(writeWait)) err := ws.WriteMessage(websocket.TextMessage, data) if err != nil { + log.Println("websocket for commit %d closed. Err: %s", commitID, err) ws.Close() return } case <-sub.CloseNotify(): + log.Println("websocket for commit %d closed by client", commitID) ws.Close() return case <-ticker.C: ws.SetWriteDeadline(time.Now().Add(writeWait)) err := ws.WriteMessage(websocket.PingMessage, []byte{}) if err != nil { + log.Println("websocket for commit %d closed. Err: %s", commitID, err) ws.Close() return } diff --git a/server/pubsub/channel.go b/server/pubsub/channel.go index 1efa64f7..c7469e76 100644 --- a/server/pubsub/channel.go +++ b/server/pubsub/channel.go @@ -1,6 +1,7 @@ package pubsub import ( + "log" "time" ) @@ -47,7 +48,9 @@ func (c *Channel) start() { // if somehow we encounter a nil pointer or some // other unexpected behavior. defer func() { - recover() + if r := recover(); r != nil { + log.Println("recoved from panic", r) + } }() // timeout the channel after N duration @@ -63,6 +66,7 @@ func (c *Channel) start() { case sub := <-c.unsubscribe: delete(c.subscriptions, sub) close(sub.send) + log.Println("usubscribed to subscription") case sub := <-c.subscribe: c.subscriptions[sub] = true @@ -89,15 +93,18 @@ func (c *Channel) start() { select { case sub.send <- msg: // do nothing - default: - sub.Close() + //default: + // log.Println("subscription closed in inner select") + // sub.Close() } } case <-timeout: + log.Println("subscription's timedout channel received message") c.Close() case <-c.closed: + log.Println("subscription's close channel received message") c.stop() return } @@ -111,6 +118,7 @@ func replay(s *Subscription, history []interface{}) { } func (c *Channel) stop() { + log.Println("subscription stopped") for sub := range c.subscriptions { sub.Close() } diff --git a/server/pubsub/opts.go b/server/pubsub/opts.go index 02e2b481..3a8a6cd6 100644 --- a/server/pubsub/opts.go +++ b/server/pubsub/opts.go @@ -21,6 +21,6 @@ var DefaultOpts = &Opts{ } var ConsoleOpts = &Opts{ - Timeout: time.Minute * 60, + Timeout: time.Minute * 120, Record: true, }