[TIC-Web] Add the get count of the inprogressed job. 84/127184/3
authorHeekyoung, Oh <heekyoung.oh@samsung.com>
Wed, 26 Apr 2017 10:17:33 +0000 (19:17 +0900)
committerHeekyoung, Oh <heekyoung.oh@samsung.com>
Wed, 26 Apr 2017 11:40:21 +0000 (20:40 +0900)
- add the query
- for that the get count of the inprogressed jobs.

Change-Id: I02f73505f72fb8d0bb2ffc824fd1a8ccf2cc8f77
Signed-off-by: Heekyoung, Oh <heekyoung.oh@samsung.com>
config.json
controller/dbquery.js
controller/router.js
public/src/js/page/job.js

index 1c95f09..2e863f0 100644 (file)
@@ -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/",
index ad88c8d..8966db3 100644 (file)
@@ -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) {
index c779496..9802bdc 100644 (file)
@@ -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
index 80bf81a..9d978ff 100644 (file)
@@ -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();
     }
 
     /**