From 186c065484e92010162f6dedfacfff299dfb3f48 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Fri, 16 Dec 2016 16:12:49 -0800 Subject: [PATCH] adding elapsed time for a running job --- .../src/job-results/job-results.controller.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/awx/ui/client/src/job-results/job-results.controller.js b/awx/ui/client/src/job-results/job-results.controller.js index a11e7cf7be..c3cd22e851 100644 --- a/awx/ui/client/src/job-results/job-results.controller.js +++ b/awx/ui/client/src/job-results/job-results.controller.js @@ -1,4 +1,5 @@ -export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope) { +export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', 'moment', +function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope, moment) { // used for tag search $scope.job_event_dataset = Dataset.data; @@ -169,6 +170,17 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count' $scope.events = {}; + // For elapsed time while a job is running, compute the differnce in seconds, + // from the time the job started until now. Moment() returns the current + // time as a moment object. + var start = ($scope.job.started === null) ? moment() : moment($scope.job.started); + if(jobFinished === false){ + var elapsedInterval = setInterval(function(){ + let now = moment(); + $scope.job.elapsed = now.diff(start, 'seconds'); + }, 1000); + } + // EVENT STUFF BELOW // This is where the async updates to the UI actually happen. @@ -442,6 +454,13 @@ export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count' parseInt($scope.job.id,10)) { // controller is defined, so set the job_status $scope.job_status = data.status; + if (data.status === "successful" || + data.status === "failed" || + data.status === "error" || + data.status === "canceled") { + clearInterval(elapsedInterval); + $state.go('.', null, { reload: true }); + } } else if (parseInt(data.project_id, 10) === parseInt($scope.job.project,10)) { // this is a project status update message, so set the