You are here

public function BackgroundProcess::dispatch in Background Process 8

Same name and namespace in other branches
  1. 6 BackgroundProcess.class.php \BackgroundProcess::dispatch()
  2. 7.2 background_process.inc \BackgroundProcess::dispatch()
  3. 7 BackgroundProcess.class.php \BackgroundProcess::dispatch()

Implements to Dispatch Process.

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

File

./background_process.class.php, line 178

Class

BackgroundProcess
BackgroundProcess class.

Code

public function dispatch() {
  $this
    ->sendMessage('dispatch');
  $handle = rawurlencode($this->handle);
  $token = rawurlencode($this->token);
  if ($this->serviceHost == 0) {
    $this->serviceHost = 'default';
  }
  list($url, $headers) = background_process_build_request('bgp-start/' . $handle . '/' . $token, $this->serviceHost);
  background_process_set_service_host($this->handle, $this->serviceHost);
  $options = [
    'method' => 'POST',
    'headers' => $headers,
  ];
  $result = background_process_http_request($url, $options);
  if (empty($result->error)) {
    $this->connection = $result->fp;
    _background_process_ensure_cleanup($this->handle, TRUE);
    return TRUE;
  }
  else {
    background_process_remove_process($this->handle);
    \Drupal::logger('bg_process')
      ->error('Could not call service %handle for callback %callback: @error', [
      '%handle' => $this->handle,
      '%callback' => _background_process_callback_name($this->callback),
      '@error' => print_r($result, TRUE),
    ]);
    return NULL;
  }
  return FALSE;
}