You are here

public function CronJob::sendMessage in Ultimate Cron 8.2

Send a nodejs message.

Parameters

string $action: The action performed.

array $data: Data blob for the given action.

3 calls to CronJob::sendMessage()
CronJob::lock in src/Entity/CronJob.php
Lock job.
CronJob::setProgress in src/Entity/CronJob.php
Set job progress.
CronJob::unlock in src/Entity/CronJob.php
Unlock job.

File

src/Entity/CronJob.php, line 706

Class

CronJob
Class for handling cron jobs.

Namespace

Drupal\ultimate_cron\Entity

Code

public function sendMessage($action, $data = array()) {

  // @TODO: Nodejs integration has not been ported to 8.x yet.
  if (FALSE && \Drupal::moduleHandler()
    ->moduleExists('nodejs')) {
    $settings = ultimate_cron_plugin_load('settings', 'general')
      ->getDefaultSettings();
    if (empty($settings['nodejs'])) {
      return;
    }
    $elements = array();
    $build = clone $this;
    $cell_idxs = array();
    switch ($action) {
      case 'lock':
        $logger = $build
          ->getPlugin('logger');
        if (empty($data['log_entry'])) {
          $build->lock_id = $data['lock_id'];
          $build->log_entry = $logger
            ->factoryLogEntry($build->name);
          $build->log_entry
            ->setData(array(
            'lid' => $data['lock_id'],
            'start_time' => microtime(TRUE),
          ));
        }
        else {
          $build->log_entry = $data['log_entry'];
        }
        $cell_idxs = array(
          'tr#' . $build->name . ' .ctools-export-ui-start-time' => 3,
          'tr#' . $build->name . ' .ctools-export-ui-duration' => 4,
          'tr#' . $build->name . ' .ctools-export-ui-status' => 5,
          'tr#' . $build->name . ' .ctools-export-ui-operations' => 7,
        );
        break;
      case 'unlock':
        $build->log_entry = $build
          ->loadLogEntry($data['lock_id']);
        $build->lock_id = FALSE;
        $cell_idxs = array(
          'tr#' . $build->name . ' .ctools-export-ui-start-time' => 3,
          'tr#' . $build->name . ' .ctools-export-ui-duration' => 4,
          'tr#' . $build->name . ' .ctools-export-ui-status' => 5,
          'tr#' . $build->name . ' .ctools-export-ui-operations' => 7,
        );
        break;
      case 'setProgress':
        $build->lock_id = $build
          ->isLocked();
        $build->log_entry = $build
          ->loadLogEntry($build->lock_id);
        $cell_idxs = array(
          'tr#' . $build->name . ' .ctools-export-ui-start-time' => 3,
          'tr#' . $build->name . ' .ctools-export-ui-duration' => 4,
          'tr#' . $build->name . ' .ctools-export-ui-status' => 5,
        );
        break;
    }
    $cells = $build
      ->rebuild_ctools_export_ui_table_row();
    foreach ($cell_idxs as $selector => $cell_idx) {
      $elements[$selector] = $cells[$cell_idx];
    }
    $message = (object) array(
      'channel' => 'ultimate_cron',
      'data' => (object) array(
        'action' => $action,
        'job' => $build,
        'timestamp' => microtime(TRUE),
        'elements' => $elements,
      ),
      'callback' => 'nodejsUltimateCron',
    );
    nodejs_send_content_channel_message($message);
  }
}