function tripal_jobs_view

2.x tripal_core.jobs.inc tripal_jobs_view($job_id)
3.x tripal.jobs.inc tripal_jobs_view($job_id)
1.x jobs.inc tripal_jobs_view($job_id)

Returns the HTML code to display a given job

Parameters

$job_id: The job_id of the job to display

Return value

The HTML describing the indicated job

Related topics

1 string reference to 'tripal_jobs_view'
tripal_core_menu in tripal_core/tripal_core.module
Implements hook_menu(). Defines all menu items needed by Tripal Core

File

tripal_core/includes/tripal_core.jobs.inc, line 245
Contains functions related to the display of Tripal jobs in a Tripal website.

Code

function tripal_jobs_view($job_id) {
  // get the job record
  $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,TJ.arguments,
            TJ.callback,TJ.error_msg,TJ.pid
     FROM {tripal_jobs} TJ
       INNER JOIN users U on TJ.uid = U.uid
     WHERE TJ.job_id = :job_id";
  $results = db_query($sql, array(':job_id' => $job_id));
  $job = $results->fetchObject();

  // We do not know what the arguments are for and we want to provide a
  // meaningful description to the end-user. So we use a callback function
  // defined in the module that created the job to describe in an array
  // the arguments provided.  If the callback fails then just use the
  // arguments as they are.  Historically, job arguments were separated with
  // two colon. We now store them as a serialized array. So, we need to handle
  // both cases.
  if (preg_match("/::/", $job->arguments)) {
    $args = preg_split("/::/", $job->arguments);
  }
  else {
    $args = unserialize($job->arguments);
  }
  $arg_hook = $job->modulename . "_job_describe_args";
  if (is_callable($arg_hook)) {
    $new_args = call_user_func_array($arg_hook, array($job->callback, $args));
    if (is_array($new_args) and count($new_args)) {
      $job->arguments = $new_args;
    }
    else {
      $job->arguments = $args;
    }
  }
  else {
    $job->arguments = $args;
  }
  // generate the list of arguments for display
  $arguments = '';
  foreach ($job->arguments as $key => $value) {
    $arguments .= "$key: $value<br>";
  }

  // build the links
  $links = l('Return to jobs list', "admin/tripal/tripal_jobs/") . ' | ';
  $links .= l('Re-run this job', "admin/tripal/tripal_jobs/rerun/" . $job->job_id) . ' | ';
  if ($job->start_time == 0 and $job->end_time == 0) {
    $links .= l('Cancel this job', "admin/tripal/tripal_jobs/cancel/" . $job->job_id) . ' | ';
    $links .= l('Execute this job', "admin/tripal/tripal_jobs/execute/" . $job->job_id);
  }

  // make our start and end times more legible
  $job->submit_date = tripal_get_job_submit_date($job);
  $job->start_time = tripal_get_job_start($job);
  $job->end_time = tripal_get_job_end($job);

  // construct the table headers
  $header = array('Detail', 'Value');

  // construct the table rows
  $rows[] = array('Job Description', $job->job_name);
  $rows[] = array('Submitting Module', $job->modulename);
  $rows[] = array('Callback function', $job->callback);
  $rows[] = array('Arguments', $arguments);
  $rows[] = array('Progress', $job->progress . "%");
  $rows[] = array('Status', $job->job_status);
  $rows[] = array('Process ID', $job->pid);
  $rows[] = array('Submit Date', $job->submit_date);
  $rows[] = array('Start time', $job->start_time);
  $rows[] = array('End time', $job->end_time);
  $rows[] = array('Error Message', $job->error_msg);
  $rows[] = array('Priority', $job->priority);
  $rows[] = array('Submitting User', $job->username);

  $table = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array('class' => 'tripal-data-table'),
    'sticky' => FALSE,
    'caption' => '',
    'colgroups' => array(),
    'empty' => '',
  );

  $output = '<p>' . substr($links, 0, -2) . '</p>'; // remove trailing |
  $output .= theme_table($table);
  return $output;
}