You are here

public function BackgroundProcess::sendMessage in Background Process 8

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

Implements to Send Message.

2 calls to BackgroundProcess::sendMessage()
BackgroundProcess::dispatch in ./background_process.class.php
Implements to Dispatch Process.
BackgroundProcess::lock in ./background_process.class.php
Implements to Lock the Background Process.

File

./background_process.class.php, line 211

Class

BackgroundProcess
BackgroundProcess class.

Code

public function sendMessage($action) {
  if (\Drupal::moduleHandler()
    ->moduleExists('nodejs')) {
    if (!isset($this->progress_object)) {
      if ($progress = progress_get_progress($this->handle)) {
        $this->progress_object = $progress;
        $this->progress = $progress->progress;
        $this->progress_message = $progress->message;
      }
      else {
        $this->progress = 0;
        $this->progress_message = '';
      }
    }
    $object = clone $this;
    $message = (object) [
      'channel' => 'background_process',
      'data' => (object) [
        'action' => $action,
        'background_process' => $object,
        'timestamp' => microtime(TRUE),
      ],
      'callback' => 'nodejsBackgroundProcess',
    ];
    drupal_alter('background_process_message', $message);
    nodejs_send_content_channel_message($message);
  }
}