From 300c8d0479d75bf20a32b1dbd55d2fa5d23a0198 Mon Sep 17 00:00:00 2001 From: Davide Franco Date: Mon, 10 Jan 2011 18:01:59 +0100 Subject: [PATCH] bacula-web: New function Get_ElapsedTime in bweb.inc.php - Internal php code improvments in jobs.php (elapsed time calculation for jobs) --- gui/bacula-web/bweb.inc.php | 21 +++++++++++++++++++++ gui/bacula-web/jobs.php | 31 ++++++++++++++----------------- gui/bacula-web/templates/jobs.tpl | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/gui/bacula-web/bweb.inc.php b/gui/bacula-web/bweb.inc.php index 528d1e1420..51f46aed0f 100644 --- a/gui/bacula-web/bweb.inc.php +++ b/gui/bacula-web/bweb.inc.php @@ -428,6 +428,27 @@ class Bweb extends DB { } } + // Return elasped time string for a job + function Get_ElapsedTime( $start_time, $end_time ) + { + $diff = $end_time - $start_time; + + $daysDiff = sprintf("%02d", floor($diff/60/60/24) ); + $diff -= $daysDiff*60*60*24; + + $hrsDiff = sprintf("%02d", floor($diff/60/60) ); + $diff -= $hrsDiff*60*60; + + $minsDiff = sprintf("%02d", floor($diff/60) ); + $diff -= $minsDiff*60; + $secsDiff = sprintf("%02d", $diff ); + + if( $daysDiff > 0 ) + return $daysDiff . 'day(s) ' . $hrsDiff.':' . $minsDiff . ':' . $secsDiff; + else + return $hrsDiff . ':' . $minsDiff . ':' . $secsDiff; + } + public function Get_ElapsedTime_Job( $delay = LAST_DAY ) { $query = ""; diff --git a/gui/bacula-web/jobs.php b/gui/bacula-web/jobs.php index fe5ec30f51..931020229d 100644 --- a/gui/bacula-web/jobs.php +++ b/gui/bacula-web/jobs.php @@ -22,7 +22,7 @@ // Running jobs $running_jobs = array(); - $query = "SELECT Job.JobId, Job.JobStatus, Status.JobStatusLong, Job.Name, Job.StartTime, Job.Level, Pool.Name AS Pool_name "; + $query = "SELECT Job.JobId, Job.JobStatus, Status.JobStatusLong, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS Pool_name "; $query .= "FROM Job "; $query .= "JOIN Status ON Job.JobStatus = Status.JobStatus "; $query .= "LEFT JOIN Pool ON Job.PoolId = Pool.PoolId "; @@ -36,8 +36,10 @@ die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() ); }else { while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) { + $elapsed = 'N/A'; + /* if( $job['JobStatus'] == 'R') { $elapsed = mktime() - strtotime($job['StartTime']); if( $elapsed > 3600 ) @@ -47,8 +49,13 @@ else $elapsed = date( "i:s", $elapsed ); } - $job['elapsed_time'] = $elapsed; - + */ + // Elapsed time for this job + if( $job['JobStatus'] == 'R' ) + $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), time() ); + else + $job['elapsed_time'] = 'N/A'; + // Odd or even row if( count($running_jobs) % 2) $job['Job_classe'] = 'odd'; @@ -63,17 +70,7 @@ $query = ""; $last_jobs = array(); - switch( $dbSql->driver ) - { - case 'mysql': - $query = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, "; - break; - case 'pgsql': - $query = "SELECT (Job.EndTime - Job.StartTime ) AS elapsed, "; - break; - } - - $query .= "Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong "; + $query .= "SELECT Job.JobId, Job.Name AS Job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus, Pool.Name AS Pool_name, Status.JobStatusLong "; $query .= "FROM Job "; $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId "; $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus "; @@ -104,8 +101,6 @@ $jobsresult = $dbSql->db_link->query( $query ); - //var_dump( $_POST ); - if( PEAR::isError( $jobsresult ) ) { echo "SQL query = $query
"; die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() ); @@ -120,7 +115,9 @@ // Odd or even row if( count($last_jobs) % 2) $job['Job_classe'] = 'odd'; - + + // Elapsed time for this job + $job['elapsed_time'] = $dbSql->Get_ElapsedTime( strtotime($job['StartTime']), strtotime($job['EndTime']) ); array_push( $last_jobs, $job); } } diff --git a/gui/bacula-web/templates/jobs.tpl b/gui/bacula-web/templates/jobs.tpl index b7464b73be..23eb843105 100644 --- a/gui/bacula-web/templates/jobs.tpl +++ b/gui/bacula-web/templates/jobs.tpl @@ -110,7 +110,7 @@ {$job.Job_name} {$job.StartTime} {$job.EndTime} - {$job.elapsed} + {$job.elapsed_time} {$job.Level} {$job.Pool_name} -- 2.39.5