]> git.sur5r.net Git - bacula/bacula/commitdiff
bacula-web: New function Get_ElapsedTime in bweb.inc.php
authorDavide Franco <bacula-dev@dflc.ch>
Mon, 10 Jan 2011 17:01:59 +0000 (18:01 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 20 Apr 2013 12:43:35 +0000 (14:43 +0200)
 - Internal php code improvments in jobs.php (elapsed time calculation for jobs)

gui/bacula-web/bweb.inc.php
gui/bacula-web/jobs.php
gui/bacula-web/templates/jobs.tpl

index 528d1e1420ea6b2a12306c9e39a473069e60c33e..51f46aed0f66e60344a47b80637634a48d46f4b3 100644 (file)
@@ -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                  = "";
index fe5ec30f518f557dde8e452baf13a7ab805fff32..931020229d721bd83e2a57a0819bdfa0f88db9e9 100644 (file)
@@ -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 ";
          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 )
                        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';
   $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 ";
   
   $jobsresult = $dbSql->db_link->query( $query );
   
-  //var_dump( $_POST );
-  
   if( PEAR::isError( $jobsresult ) ) {
          echo "SQL query = $query <br />";
          die("Unable to get last failed jobs from catalog" . $jobsresult->getMessage() );
                // 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);
          }
   }
index b7464b73be1f1a71f8cb1e6670cb42432314310e..23eb84310561b8b39a9e240da0afa860f5bb80ea 100644 (file)
                <td width="70" class="{$job.Job_classe}">{$job.Job_name}</td>
                <td width="80" class="{$job.Job_classe}">{$job.StartTime}</td>
                <td width="80" class="{$job.Job_classe}">{$job.EndTime}</td>
-               <td width="70" class="{$job.Job_classe}">{$job.elapsed}</td>
+               <td width="70" class="{$job.Job_classe}">{$job.elapsed_time}</td>
                <td width="50" class="{$job.Job_classe}">{$job.Level}</td>
                <td width="80" class="{$job.Job_classe}">{$job.Pool_name}</td>
          </tr>