You are here

function hosting_task_view in Hostmaster (Aegir) 6

Implementation of hook_view().

File

modules/hosting/task/hosting_task.module, line 666
Web server node type is defined here.

Code

function hosting_task_view($node, $teaser = FALSE, $page = FALSE) {
  drupal_add_js(drupal_get_path('module', 'hosting') . '/hosting.js');
  $node = node_prepare($node, $teaser);
  $ref = node_load($node->rid);
  hosting_set_breadcrumb($node);
  $node->content['info']['#prefix'] = '<div id="hosting-task-info" class="clear-block">';
  $node->content['info']['reference'] = array(
    '#type' => 'item',
    '#title' => drupal_ucfirst($ref->type),
    '#value' => _hosting_node_link($node->rid),
  );
  if ($node->task_status != HOSTING_TASK_QUEUED) {
    if ($node->task_status == HOSTING_TASK_PROCESSING) {
      $node->content['info']['started'] = array(
        '#type' => 'item',
        '#title' => t('Started'),
        '#value' => format_date($node->executed),
        '#weight' => 1,
      );
      $node->content['info']['delta'] = array(
        '#type' => 'item',
        '#title' => t('Processing time'),
        '#value' => format_interval(time() - $node->executed),
        '#weight' => 2,
      );
    }
    else {
      $node->content['info']['executed'] = array(
        '#type' => 'item',
        '#title' => t('Executed'),
        '#value' => format_date($node->executed),
        '#weight' => 1,
      );
      $node->content['info']['delta'] = array(
        '#type' => 'item',
        '#title' => t('Execution time'),
        '#value' => format_interval($node->delta),
        '#weight' => 2,
      );
    }
  }
  else {
    $queues = hosting_get_queues();
    $queue = $queues['tasks'];
    $freq = $queue['frequency'];
    $last = $queue['last_run'];
    $now = time();

    # the first part is the regular case: the task was never run, compute the next time

    # the second part is the case where the task wasn't run in the last queue run even though it was scheduled, so we compute the next iteration
    $next = max($last + $freq, $now - ($now - $last) % $freq + $freq);
    if ($freq < 60 * 60 * 12) {

      # 12h

      # display only the time if we have short iterations
      $date = format_date($next, 'custom', 'H:i:sO');
    }
    else {
      $date = format_date($next, 'medium');
    }
    $items = $queue['items'];
    $node->content['info']['notexecuted'] = array(
      '#type' => 'item',
      '#title' => t('This task has not been processed yet'),
      '#value' => t('It will be processed around %date, if the queue is not too crowded. The queue is currently run every %freq, was last run %last and processes %items items at a time. Server time is %time.', array(
        '%freq' => format_interval($freq),
        '%date' => $date,
        '%last' => hosting_format_interval($last),
        '%items' => $items,
        '%time' => format_date($now, 'custom', 'H:i:sO'),
      )),
    );
  }
  if ($node->task_status) {
    $node->content['info']['status'] = array(
      '#type' => 'item',
      '#title' => t('Status'),
      '#value' => _hosting_parse_error_code($node->task_status),
    );
  }
  $node->content['info']['#suffix'] = '</div>';
  if (user_access('retry failed tasks') && $node->task_status == HOSTING_TASK_ERROR) {
    $node->content['retry'] = array(
      '#type' => 'markup',
      '#value' => drupal_get_form('hosting_task_retry_form', $node->nid),
      '#weight' => 5,
    );
  }
  if (user_access('access task logs')) {
    if ($table = _hosting_task_log_table($node->vid)) {
      $node->content['hosting_log'] = array(
        '#weight' => 10,
        '#type' => 'item',
        '#value' => $table,
      );
    }
  }
  return $node;
}