<?php
-/*
-+-------------------------------------------------------------------------+
-| Copyright (C) 2004 Juan Luis Francés Jiménez |
-| |
-| This program is free software; you can redistribute it and/or |
-| modify it under the terms of the GNU General Public License |
-| as published by the Free Software Foundation; either version 2 |
-| of the License, or (at your option) any later version. |
-| |
-| This program is distributed in the hope that it will be useful, |
-| but WITHOUT ANY WARRANTY; without even the implied warranty of |
-| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
-| GNU General Public License for more details. |
-+-------------------------------------------------------------------------+
-*/
session_start();
- require ("paths.php");
- require($smarty_path."Smarty.class.php");
- include "classes.inc.php";
+ require_once ("paths.php");
+ require_once ($smarty_path."Smarty.class.php");
+ require_once ("bweb.inc.php");
+ require_once ("config.inc.php");
$smarty = new Smarty();
$dbSql = new Bweb();
$smarty->compile_dir = "./templates_c";
$smarty->config_dir = "./configs";
- // Get the last 10 failed jobs
+ // 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 .= "FROM Job ";
+ $query .= "JOIN Status ON Job.JobStatus = Status.JobStatus ";
+ $query .= "LEFT JOIN Pool ON Job.PoolId = Pool.PoolId ";
+ $query .= "WHERE Job.JobStatus IN ('F','S','M','m','s','j','c','d','t','C','R')";
+
+ $jobsresult = $dbSql->db_link->query( $query );
+
+ if( PEAR::isError( $jobsresult ) ) {
+ echo "SQL query = $query <br />";
+ 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 )
+ $elapsed = date( "H:i:s", $elapsed );
+ elseif( $elapsed > 86400 )
+ $elapsed = date( "d day(s) i:s", $elapsed );
+ else
+ $elapsed = date( "i:s", $elapsed );
+ }
+ $job['elapsed_time'] = $elapsed;
+
+ array_push( $running_jobs, $job);
+ }
+ }
+
+ $smarty->assign( 'running_jobs', $running_jobs );
+
+ // Get the last jobs list
$query = "";
- $failed_jobs = array();
+ $last_jobs = array();
switch( $dbSql->driver )
{
case 'mysql':
- $query = "SELECT SEC_TO_TIME( UNIX_TIMESTAMP(Job.EndTime)-UNIX_TIMESTAMP(Job.StartTime) ) AS elapsed, Job.JobId, Job.Name AS job_name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name AS pool_name, Job.JobStatus ";
- $query .= "FROM Job ";
- $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
- $query .= "WHERE Job.JobStatus = 'f' ";
- //$query .= "WHERE Job.EndTime BETWEEN <= NOW() and UNIX_TIMESTAMP(EndTime) >UNIX_TIMESTAMP(NOW())-86400 ";
- $query .= "ORDER BY Job.EndTime DESC ";
- $query .= "LIMIT 10";
-
+ $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, Job.Name, Job.StartTime, Job.EndTime, Job.Level, Pool.Name, Job.JobStatus ";
- $query .= "FROM Job ";
- $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
- $query .= "WHERE EndTime <= NOW() and EndTime > NOW() - 86400 * interval '1 second' ";
- $query .= "ORDER BY Job.EndTime DESC";
- $query .= "LIMIT 10";
+ $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 .= "FROM Job ";
+ $query .= "LEFT JOIN Pool ON Job.PoolId=Pool.PoolId ";
+ $query .= "LEFT JOIN Status ON Job.JobStatus = Status.JobStatus ";
+
+ // Filter by status
+ if( isset( $_POST['status'] ) ) {
+ switch( $_POST['status'] )
+ {
+ case 'completed':
+ $query .= "WHERE Job.JobStatus = 'T' ";
+ break;
+ case 'failed':
+ $query .= "WHERE Job.JobStatus = 'f' ";
+ break;
+ case 'canceled':
+ $query .= "WHERE Job.JobStatus = 'A' ";
+ break;
+ }
+ }
+
+ $query .= "ORDER BY Job.EndTime DESC ";
+
+ // Determine how many jobs to display
+ if( isset($_POST['limit']) )
+ $query .= "LIMIT " . $_POST['limit'];
+ else
+ $query .= "LIMIT 20 ";
+
$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() );
}else {
while( $job = $jobsresult->fetchRow( DB_FETCHMODE_ASSOC ) ) {
- array_push( $failed_jobs, $job);
+ // Determine icon for job
+ if( $job['JobStatus'] == 'T' )
+ $job['Job_icon'] = "s_ok.gif";
+ else
+ $job['Job_icon'] = "s_error.gif";
+
+ // Odd or even row
+ if( count($last_jobs) % 2)
+ $job['Job_classe'] = 'odd';
+
+ array_push( $last_jobs, $job);
}
}
- $smarty->assign( 'failed_jobs', $failed_jobs );
+ $smarty->assign( 'last_jobs', $last_jobs );
+
+ if( isset( $_POST['status'] ) )
+ $total_jobs = $dbSql->CountJobs( ALL, $_POST['status'] );
+ else
+ $total_jobs = $dbSql->CountJobs( ALL );
+
+ $smarty->assign( 'total_jobs', $total_jobs );
+ // Process and display the template
$smarty->display('jobs.tpl');
?>