You are here

public function BackgroundProcess::determineServiceHost in Background Process 7

Same name and namespace in other branches
  1. 8 background_process.class.php \BackgroundProcess::determineServiceHost()
  2. 6 BackgroundProcess.class.php \BackgroundProcess::determineServiceHost()
1 call to BackgroundProcess::determineServiceHost()
BackgroundProcess::execute in ./BackgroundProcess.class.php

File

./BackgroundProcess.class.php, line 116
Class for handling background processes.

Class

BackgroundProcess
BackgroundProcess class.

Code

public function determineServiceHost() {

  // Validate explicitly selected service host
  $service_hosts = background_process_get_service_hosts();
  if ($this->service_host && empty($service_hosts[$this->service_host])) {
    $this->service_host = variable_get('background_process_default_service_host', 'default');
    if (empty($service_hosts[$this->service_host])) {
      $this->service_host = NULL;
    }
  }

  // Find service group if a service host is not explicitly specified.
  if (!$this->service_host) {
    if (!$this->service_group) {
      $this->service_group = variable_get('background_process_default_service_group', 'default');
    }
    if ($this->service_group) {
      $service_groups = variable_get('background_process_service_groups', array());
      if (isset($service_groups[$this->service_group])) {
        $service_group = $service_groups[$this->service_group];

        // Default method if none is provided
        $service_group += array(
          'method' => 'background_process_service_group_round_robin',
        );
        if (is_callable($service_group['method'])) {
          $this->service_host = call_user_func($service_group['method'], $service_group);

          // Revalidate service host
          if ($this->service_host && empty($service_hosts[$this->service_host])) {
            $this->service_host = NULL;
          }
        }
      }
    }
  }

  // Fallback service host
  if (!$this->service_host || empty($service_hosts[$this->service_host])) {
    $this->service_host = variable_get('background_process_default_service_host', 'default');
    if (empty($service_hosts[$this->service_host])) {
      $this->service_host = 'default';
    }
  }
  return $this->service_host;
}