}
- public function CountJobs( $delay = LAST_DAY, $status = 'any' )
+ public function countJobs( $start_timestamp, $end_timestamp, $status = 'ALL', $level = 'ALL', $jobname = 'ALL', $client = 'ALL' )
{
$query = "SELECT COUNT(JobId) AS job_nb FROM Job ";
$where_delay = "";
- $where_status = "";
- // Interval condition for SQL query
- if( $delay != ALL ) {
- $end_date = mktime();
- $start_date = $end_date - $delay;
-
- $start_date = date( "Y-m-d H:i:s", $start_date );
- $end_date = date( "Y-m-d H:i:s", $end_date );
-
- $where_delay = "WHERE EndTime BETWEEN '$start_date' AND '$end_date' ";
+ // Calculate sql query interval
+ $start_date = date( "Y-m-d H:i:s", $start_timestamp);
+ $end_date = date( "Y-m-d H:i:s", $end_timestamp);
+
+ switch( $this->driver )
+ {
+ case 'sqlite':
+ case 'mysql':
+ $query .= "WHERE (EndTime BETWEEN '$start_date' AND '$end_date') ";
+ break;
+ case 'pgsql':
+ $query .= "WHERE (EndTime BETWEEN timestamp '$start_date' AND timestamp '$end_date') ";
+ break;
}
- if( $status != 'any' ) {
+ if( $status != 'ALL' ) {
switch( $status )
{
case 'completed':
- $where_status = "JobStatus = 'T' ";
+ $query .= " AND JobStatus = 'T' ";
break;
case 'failed':
- $where_status = "JobStatus IN ('f','E') ";
+ $query .= " AND JobStatus IN ('f','E') ";
break;
case 'canceled':
- $where_status = "JobStatus = 'A' ";
+ $query .= " AND JobStatus = 'A' ";
break;
case 'waiting':
- $where_status = "JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
+ $query .= " AND JobStatus IN ('F','S','M','m','s','j','c','d','t') ";
break;
} // end switch
}
- if( !empty($where_delay) )
- $query = $query . $where_delay . 'AND ' . $where_status;
- else {
- if( !empty($where_status) )
- $query = $query . 'WHERE ' . $where_status;
+ if( $level != 'ALL' ) {
+ $query .= " AND Level = '$level'";
}
-
+
+ // Execute the query
$jobs = $this->db_link->query( $query );
if (PEAR::isError( $jobs ) ) {
$this->TriggerDBError("Unable to get last $status jobs number from catalog", $jobs);
}else {
- $jobs = $jobs->fetchRow( DB_FETCHMODE_ASSOC );
+ $jobs = $jobs->fetchRow();
return $jobs['job_nb'];
}
}
// Backup Job list for report.tpl and last_run_report.tpl
$dbSql->tpl->assign( 'jobs_list', $dbSql->Get_BackupJob_Names() );
-// Last 24 hours completed jobs number
-$dbSql->tpl->assign( 'completed_jobs', $dbSql->CountJobs( LAST_DAY, 'completed' ) );
-
-// Last 24 hours failed jobs number
-$dbSql->tpl->assign( 'failed_jobs', $dbSql->CountJobs( LAST_DAY, 'failed' ) );
-
-// Last 24 hours waiting jobs number
-$dbSql->tpl->assign( 'waiting_jobs', $dbSql->CountJobs( LAST_DAY, 'waiting' ) );
-
-// Last 24 hours Job Levels
-$dbSql->tpl->assign( 'incr_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'I') );
-$dbSql->tpl->assign( 'diff_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'D') );
-$dbSql->tpl->assign( 'full_jobs', $dbSql->CountJobsbyLevel( LAST_DAY, 'F') );
+// Last 24 hours status (completed, failed and waiting jobs)
+$dbSql->tpl->assign( 'completed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'completed' ) );
+$dbSql->tpl->assign( 'failed_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'failed' ) );
+$dbSql->tpl->assign( 'waiting_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'waiting' ) );
+
+// Last 24 hours jobs Level
+$dbSql->tpl->assign( 'incr_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_INCR) );
+$dbSql->tpl->assign( 'diff_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_DIFF) );
+$dbSql->tpl->assign( 'full_jobs', $dbSql->countJobs( NOW-DAY, NOW, 'ALL', J_FULL) );
// Last 24 hours Job status graph
$data = array();