From: Heekyoung, Oh Date: Wed, 26 Apr 2017 10:17:33 +0000 (+0900) Subject: [TIC-Web] Add the get count of the inprogressed job. X-Git-Tag: v20170428~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F84%2F127184%2F3;p=archive%2F20170607%2Ftools%2Ftic.git [TIC-Web] Add the get count of the inprogressed job. - add the query - for that the get count of the inprogressed jobs. Change-Id: I02f73505f72fb8d0bb2ffc824fd1a8ccf2cc8f77 Signed-off-by: Heekyoung, Oh --- diff --git a/config.json b/config.json index 1c95f09..2e863f0 100644 --- a/config.json +++ b/config.json @@ -51,7 +51,8 @@ "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/", diff --git a/controller/dbquery.js b/controller/dbquery.js index ad88c8d..8966db3 100644 --- a/controller/dbquery.js +++ b/controller/dbquery.js @@ -82,9 +82,17 @@ mariadb.queries = { ], '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, ', @@ -309,6 +317,22 @@ mariadb.getJobsQueueCount = function getJobsQueueCount(callback) { }; /** + * 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) { diff --git a/controller/router.js b/controller/router.js index c779496..9802bdc 100644 --- a/controller/router.js +++ b/controller/router.js @@ -136,6 +136,14 @@ var init = function (serv) { }); /** + * 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 diff --git a/public/src/js/page/job.js b/public/src/js/page/job.js index 80bf81a..9d978ff 100644 --- a/public/src/js/page/job.js +++ b/public/src/js/page/job.js @@ -89,10 +89,9 @@ define([ _.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); }); } @@ -316,7 +315,7 @@ define([ function onError(err) { if (err) { - logger.error(err); + logger.error(err.responseText); throw err; } } @@ -415,6 +414,13 @@ define([ 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 + '.'); @@ -425,10 +431,7 @@ define([ }; Util.POST(AppConfig.EVENT.JOB.JOB_EDIT_ONE + jobId, msgObj) .then(checksNextJob) - .then(function () { - // upate the list of jobs - updateList(ModelJobPaging.getCurrentPoint()); - }); + .then(onError); }); /** @@ -535,14 +538,31 @@ define([ 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(); } /**