"JOB_ADD_ONE": "/api/job/add/",
"JOB_EDIT_ONE": "/api/job/edit/",
"JOB_READ_LOG": "/api/job/log/",
- "JOB_GET_NEXTJOB": "/api/job/queue/next"
+ "JOB_GET_NEXTJOB": "/api/job/queue/next",
+ "JOB_HAS_INPROGRESSJOB": "/api/job/queue/inprogress"
},
"PACKAGE": {
"IMPORT": "/api/imports/",
],
'getJobsQueueCount': [
'select count(job_id) as total_count ',
+ 'from tic_job ',
+ 'where job_deleted = false ',
+ 'and job_status = "INPROGRESS" OR job_status = "READY";'
+ ],
+ 'getJobsQueueInprogressCount': [
+ 'select ',
+ 'count(job_id) as total_count, ',
+ 'job_id ',
'from tic_job ',
'where job_deleted = false ',
- 'and job_status = "INPROGRESS" OR job_status = "READY";'
+ 'and job_status = "INPROGRESS";'
],
'getJobsQueueNext': [
'select tic_job.job_id job_id, ',
};
/**
+ * Get Counts of Job for inprogress
+ */
+mariadb.getJobsQueueInprogressCount = function getJobsQueueInprogressCount(req, res) {
+ var queryString = _.join(this.queries['getJobsQueueInprogressCount'], '');
+
+ function onSuccess(rows) {
+ res.json(rows.result);
+ }
+
+ logger.info('getJobsQueueInprogressCount: query = ' + queryString);
+
+ // call
+ this.doQuery(queryString).then(onSuccess);
+};
+
+/**
* Get All Jobs
*/
mariadb.getJobsAllList = function getJobsAllList(req, res) {
});
/**
+ * Get the count of job for the status was "INPROGRESS"
+ */
+ router.post('/job/queue/inprogress', function (req, res) {
+ logger.info('an api called that /job/queue/inprogress');
+ client.getJobsQueueInprogressCount(req, res);
+ });
+
+ /**
* Read the log file
* @URI /api/job/log/:id
* @TYPE POST
_.forEach(arrJobs, function (value, index) {
targetTableBody.append(new JobTableItem(value, index).getRow());
if (value.getJobStatus() === JOB_STATUS_INPROGRESS) {
- targetId = 'extended_job_table_row_' + value.getJobId();
Util.POST(AppConfig.EVENT.JOB.JOB_READ_LOG + value.getJobId())
.then(function (line) {
- targetId = '#' + targetId + ' > td > div';
+ targetId = '#extended_job_table_row_' + value.getJobId() + ' > td > div';
$(targetId).append(line);
});
}
function onError(err) {
if (err) {
- logger.error(err);
+ logger.error(err.responseText);
throw err;
}
}
jobId: jobId
});
+ function onError(err) {
+ if (err) {
+ logger.error(err.responseText);
+ throw err;
+ }
+ }
+
// notification popup
Util.showAlertDialog('Failed to create an image. The #ID is ' + jobId + '.');
};
Util.POST(AppConfig.EVENT.JOB.JOB_EDIT_ONE + jobId, msgObj)
.then(checksNextJob)
- .then(function () {
- // upate the list of jobs
- updateList(ModelJobPaging.getCurrentPoint());
- });
+ .then(onError);
});
/**
function getNextJob () {
logger.info('doCreateAnImage.getNextJob');
- return Util.POST(AppConfig.EVENT.JOB.JOB_GET_NEXTJOB);
+ return Util.POST(AppConfig.EVENT.JOB.JOB_GET_NEXTJOB)
+ .then(createNextJobModel)
+ .then(doCreate)
+ .then(doUpdateJobView)
+ .catch(onError);
+ }
+
+ function getJobsQueueInprogressCount () {
+ logger.info('doCreateAnImage.getJobsQueueInprogressCount');
+ Util.POST(AppConfig.EVENT.JOB.JOB_HAS_INPROGRESSJOB)
+ .then(function (dataObj) {
+ var resObj, jobId, jobCnt;
+ resObj = dataObj[0];
+ jobCnt = Number(resObj.total_count);
+
+ if (jobCnt === 0) {
+ getNextJob();
+ } else {
+ jobId = resObj.job_id;
+ logger.info('There is an inprogressed job : (' + jobId + ')');
+ }
+ });
}
- getNextJob()
- .then(createNextJobModel)
- .then(doCreate)
- .then(doUpdateJobView)
- .catch(onError);
+ getJobsQueueInprogressCount();
}
/**