You are here

public function BackgroundProcess::determineServiceHost in Background Process 8

Same name and namespace in other branches
  1. 6 BackgroundProcess.class.php \BackgroundProcess::determineServiceHost()
  2. 7 BackgroundProcess.class.php \BackgroundProcess::determineServiceHost()

Implements Function to Determine Service Host.

1 call to BackgroundProcess::determineServiceHost()
BackgroundProcess::execute in ./background_process.class.php
Implements Execute Process.

File

./background_process.class.php, line 104

Class

BackgroundProcess
BackgroundProcess class.

Code

public function determineServiceHost() {
  $service_hosts = background_process_get_service_hosts();
  if ($this->serviceHost && empty($service_hosts[$this->serviceHost])) {
    $this->serviceHost = \Drupal::config('background_process.settings')
      ->get('background_process_default_service_host');
    if (empty($service_hosts[$this->serviceHost])) {
      $this->serviceHost = NULL;
    }
  }

  // Find service group if a service host is not explicitly specified.
  if (!$this->serviceHost) {
    if (!$this->serviceGroup) {
      $this->serviceGroup = \Drupal::config('background_process.settings')
        ->get('background_process_default_service_group');
    }
    if ($this->serviceGroup) {
      $service_groups = \Drupal::config('background_process.settings')
        ->get('background_process_service_groups');
      if (isset($service_groups[$this->serviceGroup])) {
        $service_group = $service_groups[$this->serviceGroup];

        // Default method if none is provided.
        $service_group += [
          'method' => 'background_process_service_group_round_robin',
        ];
        if (is_callable($service_group['method'])) {
          $this->serviceHost = call_user_func($service_group['method'], $service_group);
          if ($this->serviceHost && empty($service_hosts[$this->serviceHost])) {
            $this->serviceHost = NULL;
          }
        }
      }
    }
  }

  // Fallback service host.
  if (!$this->serviceHost || empty($service_hosts[$this->serviceHost])) {
    $this->serviceHost = \Drupal::config('background_process.settings')
      ->get('background_process_default_service_host');
    if (empty($service_hosts[$this->serviceHost]) || $service_hosts[$this->serviceHost] == 0) {
      $this->serviceHost = 'default';
    }
  }
  return $this->serviceHost;
}