You are here

function hosting_task_log_ajax in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 task/hosting_task.module \hosting_task_log_ajax()

Read additional task log data, served via AJAX.

1 string reference to 'hosting_task_log_ajax'
hosting_task_menu in task/hosting_task.module
Implements hook_menu().

File

task/hosting_task.module, line 100
Web server node type is defined here.

Code

function hosting_task_log_ajax($node, $last_position, $id) {
  $commands = array();

  // Long polling for ten seconds.
  $expire = time() + 10;
  $table = FALSE;
  while ((empty($table) || !count($table['#rows'])) && time() < $expire) {
    usleep(200000);
    $table = _hosting_task_log_table($node, $last_position);
  }
  if (isset($table['#refresh_url'])) {
    $url = $table['#refresh_url'];
  }
  else {
    $url = url('hosting/task/log/ajax/' . $node->nid . '/' . $last_position);
  }
  if (!empty($table)) {
    unset($table['#header']);
    $commands[] = hosting_task_ajax_command_hosting_table_append('#' . $id, drupal_render($table));
  }
  if (!hosting_task_task_has_finished($node)) {
    $commands[] = hosting_task_ajax_command_hosting_table_check('#' . $id, $url);
  }
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}