From 424cae24c6e8d9ad909ee24cf5a9a9fc48dab6ce Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 5 May 2015 00:28:59 +0300 Subject: [PATCH] change status waiting to queued + other small fixes --- lib/distributor.js | 2 +- resources/projects.js | 4 ++-- static/js/app/app.js | 26 +++++++++++++++----------- test/distributor.js | 4 ++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/distributor.js b/lib/distributor.js index 42478e0..97deca1 100644 --- a/lib/distributor.js +++ b/lib/distributor.js @@ -86,7 +86,7 @@ Distributor.prototype.run = function(project, params, callback) { self._updateBuild({ project: project, params: params, - status: 'waiting' + status: 'queued' }, this.slot()); }, function(err, build) { diff --git a/resources/projects.js b/resources/projects.js index 8fd3869..43653c4 100644 --- a/resources/projects.js +++ b/resources/projects.js @@ -25,7 +25,7 @@ module.exports = function(app) { nodes: [{type: 'local', maxExecutorsCount: 1}], onBuildUpdate: function(build, callback) { var buildsResource = app.dataio.resource('builds'); - if (build.status === 'waiting') { + if (build.status === 'queued') { build.id = ++buildsSequnce; // create resource for build data var buildDataResource = app.dataio.resource('build' + build.id); @@ -34,7 +34,7 @@ module.exports = function(app) { }); } buildsResource.clientEmitSync( - build.status === 'waiting' ? 'create' : 'update', + build.status === 'queued' ? 'create' : 'update', build ); callback(null, build); diff --git a/static/js/app/app.js b/static/js/app/app.js index 488ee41..5ec641f 100644 --- a/static/js/app/app.js +++ b/static/js/app/app.js @@ -7,17 +7,17 @@ define([ ) { var connect = dataio(socketio.connect()); - var projects = connect.resource('projects'), + var projectsResource = connect.resource('projects'), projectsTemplate = _($('#projects-template').html()).template(); $('#projects').on('click', '.js-projects .js-run', function() { var projectName = $(this).parent('.js-project').data('name'); - projects.sync('run', {projectName: projectName}, function(err, result) { + projectsResource.sync('run', {projectName: projectName}, function(err, result) { $('#content').append(err && err.message); }); }); - projects.sync('read', function(err, projects) { + projectsResource.sync('read', function(err, projects) { $('#projects').html( (err && err.message) || projectsTemplate({projects: projects}) @@ -25,13 +25,13 @@ define([ }); - var builds = connect.resource('builds'), + var buildsResource = connect.resource('builds'), buildsTemplate = _($('#builds-template').html()).template(), - buildsHash = {}; + builds = []; $('#builds').on('click', '.js-builds .js-show-console', function() { var buildId = $(this).parent('.js-build').data('id'), - resourceName = 'build' + buildId;; + resourceName = 'build' + buildId; $('#build-console').prev('h2').html('Build #' + buildId + ' console'); $('#build-console').html(''); @@ -41,10 +41,14 @@ define([ }); }); - builds.subscribe(function(build, action) { - buildsHash[build.id] = build; - $('#builds').html(buildsTemplate({ - builds: _(buildsHash).values().reverse() - })); + buildsResource.subscribe(function(build, action) { + var oldBuild = _(builds).findWhere({id: build.id}); + if (oldBuild) { + _(oldBuild).extend(build); + } else { + builds.unshift(build); + } + + $('#builds').html(buildsTemplate({builds: builds})); }); }); diff --git a/test/distributor.js b/test/distributor.js index 406101d..1def2c9 100644 --- a/test/distributor.js +++ b/test/distributor.js @@ -43,7 +43,7 @@ describe('Distributor', function() { it('instance should be created without errors', function() { var number = 1; var conditionsHash = { - 1: {queue: {length: 0}, build: {status: 'waiting'}}, + 1: {queue: {length: 0}, build: {status: 'queued'}}, 2: {queue: {length: 1}, build: {status: 'in-progress'}}, 3: {queue: {length: 0}, build: {status: 'done'}}, 4: 'Should never happend' @@ -92,7 +92,7 @@ describe('Distributor', function() { it('instance should be created without errors', function() { var number = 1; var conditionsHash = { - 1: {queue: {length: 0}, build: {status: 'waiting'}}, + 1: {queue: {length: 0}, build: {status: 'queued'}}, 2: {queue: {length: 1}, build: {status: 'in-progress'}}, 3: { queue: {length: 0},