}
}
+ // 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 = "";
// 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);
}
}