You are here

public function BackgroundProcess::setServiceGroup in Background Process 7.2

Set the service group. This method sets the service host based on the service group.

Parameters

optional $service_group: Service group. If invalid or none specified, the default service group will be used.

1 call to BackgroundProcess::setServiceGroup()
BackgroundProcess::ensureServiceHost in ./background_process.inc
Make sure that the process has been designated a service host.

File

./background_process.inc, line 431
External API short overview

Class

BackgroundProcess
@file

Code

public function setServiceGroup($service_group_name = NULL) {
  if (!$service_group_name && isset($this->service_group)) {
    $service_group_name = $this->service_group;
  }
  $service_groups = background_process_get_service_groups();
  $service_host = NULL;
  if (!$service_group_name || empty($service_groups[$service_group_name])) {
    $service_group_name = variable_get('background_process_default_service_group', 'default');
  }
  if (empty($service_groups[$service_group_name])) {

    // Default service group not found, use default service host.
    throw new BackgroundProcessException(t('Default service group not found'), BACKGROUND_PROCESS_ERROR_NO_SERVICE_GROUP);
  }
  else {
    $this->service_group = $service_groups[$service_group_name];

    // Ask the balancer for an appropriate service host
    if (!is_callable($this->service_group['method'])) {
      throw new BackgroundProcessException(t('Cannot call balancer method'), BACKGROUND_PROCESS_ERROR_INVALID_BALANCER);
    }
    $service_host = call_user_func($this->service_group['method'], $this->service_group);
  }
  $this
    ->setServiceHost($service_host);
  return $this;
}