You are here

function background_process_ass_service_group_idle in Background Process 8

Same name and namespace in other branches
  1. 6 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()
  2. 7.2 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()
  3. 7 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()

Implements to Determine host with most idle workers and claim it.

File

background_process_ass/background_process_ass.module, line 66
Implements Background Process Ass Module. @todo Implement admin interface. @todo Fix runtime check of running process.

Code

function background_process_ass_service_group_idle($service_group, $reload = FALSE) {
  $result = NULL;
  $max = 0;
  $workers =& drupal_static('background_process_ass_idle_workers', []);

  // Load idle worker status for all hosts.
  foreach ($service_group['hosts'] as $host) {
    $name = $host . '_ass';
    if ($reload || !isset($workers[$name])) {
      $workers[$name] = background_process_ass_get_server_status($name, TRUE, $reload);
    }

    // Reload apache server status for all hosts, if any is fully loaded.
    if ($workers[$name] <= 0 && !$reload) {
      return background_process_ass_service_group_idle($service_group, TRUE);
    }
    if ($max < $workers[$name]) {
      $result = $host;
      $max = $workers[$name];
    }
  }
  if (isset($result)) {

    // Claim host and tell caller.
    $workers[$result . '_ass']--;
    return $result;
  }
  else {
    return background_process_service_group_round_robin($service_group);
  }
}