function tripal_jobs_report
2.x tripal_core.jobs.inc | tripal_jobs_report() |
3.x tripal.jobs.inc | tripal_jobs_report() |
1.x jobs.inc | tripal_jobs_report() |
Returns the Tripal Job Report
Return value
The HTML to be rendered which describes the job report
File
- tripal/
includes/ tripal.jobs.inc, line 106 - Contains functions related to the display of Tripal jobs in a Tripal website.
Code
function tripal_jobs_report() {
// run the following function which will
// change the status of jobs that have errored out
tripal_get_running_jobs();
$job_status = '';
$job_name = '';
if (array_key_exists('tripal_job_filter', $_SESSION)) {
$job_status = array_key_exists('job_status', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_status'] : '';
$job_name = array_key_exists('job_name', $_SESSION['tripal_job_filter']) ? $_SESSION['tripal_job_filter']['job_name'] : '';
}
// build the SQL for getting the jobs
$sql = "
SELECT
TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
TJ.status as job_status, TJ,submit_date,TJ.start_time,
TJ.end_time,TJ.priority,U.name as username
FROM {tripal_jobs} TJ
INNER JOIN {users} U on TJ.uid = U.uid
WHERE 1=1
";
$args = array();
if ($job_status) {
$sql .= "AND TJ.status = :status ";
$args[':status'] = $job_status;
}
if ($job_name) {
$sql .= "AND TJ.job_name like :job_name";
$args[':job_name'] = "%$job_name%";
}
$sql .= " ORDER BY job_id DESC ";
// create the SQL that returns the total number of records
$count_sql = "SELECT count(*) as total FROM ($sql) as t1";
$result = db_query($count_sql, $args);
$total_jobs = $result->fetchObject();
// initialize the pager
$num_per_page = 25;
$page = pager_find_page();
pager_default_initialize($total_jobs->total, $num_per_page);
// get results
$pager_sql = "$sql LIMIT :number OFFSET :offset";
$args[':number'] = $num_per_page;
$args[':offset'] = $num_per_page * $page;
$jobs = db_query($pager_sql, $args);
// iterate through the jobs and build the table rows
$rows = array();
foreach ($jobs as $job) {
$submit = tripal_get_job_submit_date($job);
$start = tripal_get_job_start($job);
$end = tripal_get_job_end($job);
$cancel_link = '';
$execute_link = '';
if ($job->start_time == 0 and $job->end_time == 0) {
$cancel_link = "<a href=\"" . url("admin/tripal/tripal_jobs/cancel/" . $job->job_id) . "\">Cancel</a><br />";
$execute_link = "<a href=\"" . url("admin/tripal/tripal_jobs/execute/" . $job->job_id) . "\">Execute</a><br />";
}
$rerun_link = "<a href=\"" . url("admin/tripal/tripal_jobs/rerun/" . $job->job_id) . "\">Re-run</a><br />";
$view_link = "<a href=\"" . url("admin/tripal/tripal_jobs/view/" . $job->job_id) . "\">View</a>";
$rows[] = array(
$job->job_id,
$job->username,
$job->job_name,
"Submit Date: $submit<br>Start Time: $start<br>End Time: $end",
$job->priority,
$job->progress . '%',
$job->job_status,
"$execute_link $cancel_link $rerun_link $view_link",
);
}
// the header for the jobs table
$header = array(
'Job ID',
'User',
'Job Name',
array('data' => 'Dates', 'style' => "white-space: nowrap"),
'Priority',
'Progress',
'Status',
'Action'
);
$table = array(
'header' => $header,
'rows' => $rows,
'attributes' => array('class' => 'tripal-data-table'),
'sticky' => FALSE,
'caption' => '',
'colgroups' => array(),
'empty' => 'No jobs have been submitted',
);
// create the report page
$output = "Waiting jobs are executed first by priority level (the lower the " .
"number the higher the priority) and second by the order they " .
"were entered";
$report_form = drupal_get_form('tripal_jobs_report_form');
$output .= drupal_render($report_form);
$output .= theme_table($table);
$output .= theme('pager');
return $output;
}