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

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

File

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

Code

function tripal_jobs_view($job_id) {

  // set the breadcrumb
  $breadcrumb = array();
  $breadcrumb[] = l('Home', '<front>');
  $breadcrumb[] = l('Administration', 'admin');
  $breadcrumb[] = l('Tripal', 'admin/tripal');
  $breadcrumb[] = l('Jobs', 'admin/tripal/tripal_jobs');
  drupal_set_breadcrumb($breadcrumb);

  // 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) {
    if (is_array($value)) {
      $value = print_r($value, TRUE);
    }
    $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('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' => '',
  );

  $content['links'] = array(
    '#type' => 'markup',
    '#markup' => '<p>' . substr($links, 0, -2) . '</p>',
  );
  $content['job_title'] = array(
    '#type' => 'item',
    '#title' => t('Job Title'),
    '#markup' => $job->job_name,
  );
  $content['job_status'] = array(
    '#type' => 'item',
    '#title' => t('Status'),
    '#markup' => $job->job_status,
  );
  $content['details_fset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Job Details'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#attributes' => array(
      'class' => array('collapsible', 'collapsed'),
    ),
    '#attached' => array(
      'js' => array('misc/collapse.js', 'misc/form.js')
    ),
  );
  $content['details_fset']['job_details'] = array(
    '#type' => 'markup',
    '#markup' => theme_table($table),
  );
  $content['log_fset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Job Logs'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
    '#attributes' => array(
      'class' => array('collapsible', 'collapsed'),
    ),
    '#attached' => array(
      'js' => array('misc/collapse.js', 'misc/form.js')
    ),
  );
  $content['log_fset']['job_logs'] = array(
    '#type' => 'markup',
    '#markup' => '<pre>' . $job->error_msg . '</pre>',
  );
  return $content;
}