Пример #1
0
 public static function count_Jobs($pdo_connection, $period_timestamps, $job_status = null, $job_level = null)
 {
     $statment = null;
     $where = null;
     $tablename = 'Job';
     $fields = array('COUNT(*) as job_count');
     $intervals = null;
     // Check PDO object
     if (!is_a($pdo_connection, 'PDO') and is_null($pdo_connection)) {
         throw new Exception('Unvalid PDO object provided in count_Jobs() function');
     }
     // PDO object singleton
     if (is_null(CModel::$pdo_connection)) {
         CModel::$pdo_connection = $pdo_connection;
     }
     // Getting timestamp interval
     $intervals = CDBQuery::get_Timestamp_Interval($period_timestamps);
     // Defining interval depending on job status
     if (!is_null($job_status)) {
         switch ($job_status) {
             case 'running':
                 $where = array('(starttime BETWEEN ' . $intervals['starttime'] . ' AND ' . $intervals['endtime'] . ') ');
                 break;
             case 'waiting':
                 // We don't use interval for waiting jobs
                 break;
             default:
                 $where = array('(endtime BETWEEN ' . $intervals['starttime'] . ' AND ' . $intervals['endtime'] . ') ');
                 break;
         }
     } else {
         $where[] = '(endtime BETWEEN ' . $intervals['starttime'] . ' AND ' . $intervals['endtime'] . ') ';
     }
     // Job status
     if (!is_null($job_status)) {
         switch ($job_status) {
             case 'running':
                 $where[] = "JobStatus = 'R'";
                 break;
             case 'completed':
                 $where[] = "JobStatus = 'T' ";
                 break;
             case 'failed':
                 $where[] = "JobStatus IN ('f','E') ";
                 break;
             case 'canceled':
                 $where[] = "JobStatus = 'A' ";
                 break;
             case 'waiting':
                 $where[] = "JobStatus IN ('F','S','M','m','s','j','c','d','t','p','C') ";
                 break;
         }
         // end switch
     }
     // Job level
     if (!is_null($job_level)) {
         $where[] = "Level = '{$job_level}' ";
     }
     // Building SQL statment
     $statment = array('table' => $tablename, 'fields' => $fields, 'where' => $where);
     $statment = CDBQuery::get_Select($statment);
     // Execute SQL statment
     $result = CDBUtils::runQuery($statment, $pdo_connection);
     $result = $result->fetch();
     return $result['job_count'];
 }