Procházet zdrojové kódy

Add last test launch time in the new /api/runs route

Gaël Métais před 4 roky
rodič
revize
dc5bd2e71e

+ 4 - 1
lib/server/controllers/apiController.js

@@ -227,7 +227,10 @@ var ApiController = function(app) {
     // Counts all pending runs
     // Counts all pending runs
     app.get('/api/runs', function(req, res) {
     app.get('/api/runs', function(req, res) {
         res.setHeader('Content-Type', 'application/json');
         res.setHeader('Content-Type', 'application/json');
-        res.send(JSON.stringify({pendingRuns: queue.length()}, null, 2));
+        res.send(JSON.stringify({
+            pendingRuns: queue.length(),
+            timeSinceLastTestStarted: queue.timeSinceLastTestStarted()
+        }, null, 2));
     });
     });
 
 
     // Delete one run by id
     // Delete one run by id

+ 8 - 1
lib/server/datastores/runsQueue.js

@@ -6,7 +6,7 @@ function RunsQueue() {
     'use strict';
     'use strict';
 
 
     var queue = [];
     var queue = [];
-
+    var lastTestTimestamp = 0;
 
 
     this.push = function(runId) {
     this.push = function(runId) {
         var deferred = Q.defer();
         var deferred = Q.defer();
@@ -21,6 +21,7 @@ function RunsQueue() {
                 runId: runId
                 runId: runId
             });
             });
             
             
+            lastTestTimestamp = Date.now();
             deferred.resolve();
             deferred.resolve();
 
 
         } else {
         } else {
@@ -31,6 +32,7 @@ function RunsQueue() {
                     deferred.notify(position);
                     deferred.notify(position);
                 },
                 },
                 itIsTimeCallback: function() {
                 itIsTimeCallback: function() {
+                    lastTestTimestamp = Date.now();
                     deferred.resolve();
                     deferred.resolve();
                 }
                 }
             });
             });
@@ -78,6 +80,11 @@ function RunsQueue() {
     this.length = function() {
     this.length = function() {
         return queue.length;
         return queue.length;
     };
     };
+
+    // Returns the number of seconds since the last test was launched
+    this.timeSinceLastTestStarted = function() {
+        return Math.round((Date.now() - lastTestTimestamp) / 1000);
+    };
 }
 }
 
 
 module.exports = RunsQueue;
 module.exports = RunsQueue;