function background_process_ass_service_group_idle in Background Process 7.2
Same name and namespace in other branches
- 8 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()
- 6 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()
- 7 background_process_ass/background_process_ass.module \background_process_ass_service_group_idle()
Determine host with most idle workers and claim it.
Parameters
$service_group: Service group to check
Return value
Claimed service host on success, NULL if none found
File
- background_process_ass/
background_process_ass.module, line 125 - @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;
$msg = "";
$workers =& drupal_static('background_process_ass_idle_workers', array());
// Load idle worker status for all hosts
foreach ($service_group['hosts'] as $idx => $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 {
// Could not determine most idle host, fallback to random
return background_process_service_group_random($service_group);
}
}