log fwding

This commit is contained in:
Matej Kramny 2016-05-01 12:24:09 +01:00
parent ca321053ae
commit 8b5d6b9803
3 changed files with 24 additions and 2 deletions

View File

@ -76,7 +76,13 @@ app.run(['$rootScope', '$window', '$couchPotato', '$injector', '$state', '$http'
}
$rootScope.ws.onmessage = function (e) {
console.log('msg', e.data);
try {
var d = JSON.parse(e.data);
console.log(d);
setTimeout(function () {
$rootScope.$broadcast('remote.' + d.type, d);
}, 3000);
} catch (_) {}
}
}

View File

@ -14,6 +14,10 @@ define(function () {
}]);
app.registerController('TaskCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.$on('remote.log', function (evt, data) {
$scope.output_formatted.splice(0, 0, data);
});
$http.get($scope.project.getURL() + '/tasks/' + $scope.task.id + '/output')
.success(function (output) {
var out = [];

View File

@ -2,6 +2,7 @@ package tasks
import (
"bufio"
"encoding/json"
"os/exec"
"github.com/ansible-semaphore/semaphore/database"
@ -10,7 +11,18 @@ import (
func (t *task) log(msg string) {
for _, user := range t.users {
sockets.Message(user, []byte(msg))
b, err := json.Marshal(&map[string]interface{}{
"type": "log",
"m": msg,
"task_id": t.task.ID,
"project_id": t.projectID,
})
if err != nil {
panic(err)
}
sockets.Message(user, b)
}
go func() {