fix race condition with status socket

This commit is contained in:
John Mitchell 2017-02-21 14:55:11 -05:00
parent f59b3ad886
commit 69220e94de
2 changed files with 28 additions and 3 deletions

View File

@ -1,5 +1,5 @@
export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService',
function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService) {
export default ['jobData', 'jobDataOptions', 'jobLabels', 'jobFinished', 'count', '$scope', 'ParseTypeChange', 'ParseVariableString', 'jobResultsService', 'eventQueue', '$compile', '$log', 'Dataset', '$q', 'Rest', '$state', 'QuerySet', '$rootScope', 'moment', '$stateParams', 'i18n', 'fieldChoices', 'fieldLabels', 'workflowResultsService', 'statusSocket',
function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTypeChange, ParseVariableString, jobResultsService, eventQueue, $compile, $log, Dataset, $q, Rest, $state, QuerySet, $rootScope, moment, $stateParams, i18n, fieldChoices, fieldLabels, workflowResultsService, statusSocket) {
var toDestroy = [];
var cancelRequests = false;
var runTimeElapsedTimer = null;
@ -664,6 +664,14 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
});
}));
// get previously set up socket messages from resolve
if (statusSocket[0].job_status) {
$scope.job_status = statusSocket[0].job_status;
}
if ($scope.job_status === "running") {
runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer);
}
// Processing of job-status messages from the websocket
toDestroy.push($scope.$on(`ws-jobs`, function(e, data) {
if (parseInt(data.unified_job_id, 10) ===
@ -671,7 +679,9 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
// controller is defined, so set the job_status
$scope.job_status = data.status;
if (data.status === "running") {
runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer);
if (!runTimeElapsedTimer) {
runTimeElapsedTimer = workflowResultsService.createOneSecondTimer(moment(), updateJobElapsedTimer);
}
} else if (data.status === "successful" ||
data.status === "failed" ||
data.status === "error" ||
@ -699,7 +709,12 @@ function(jobData, jobDataOptions, jobLabels, jobFinished, count, $scope, ParseTy
}
}));
statusSocket[1]();
$scope.$on('$destroy', function(){
if (statusSocket[1]) {
statusSocket[1]();
}
$( ".JobResultsStdOut-aLineOfStdOut" ).remove();
cancelRequests = true;
eventQueue.initialize();

View File

@ -36,6 +36,16 @@ export default {
}
},
resolve: {
statusSocket: ['$rootScope', '$stateParams', function($rootScope, $stateParams) {
var preScope = {};
var eventOn = $rootScope.$on(`ws-jobs`, function(e, data) {
if (parseInt(data.unified_job_id, 10) ===
parseInt($stateParams.id,10)) {
preScope.job_status = data.status;
}
});
return [preScope, eventOn];
}],
// the GET for the particular job
jobData: ['Rest', 'GetBasePath', '$stateParams', '$q', '$state', 'Alert', 'jobResultsService', function(Rest, GetBasePath, $stateParams, $q, $state, Alert, jobResultsService) {
return jobResultsService.getJobData($stateParams.id);