You are here

public function WarmerCommands::enqueue in Warmer 2.x

Same name and namespace in other branches
  1. 8 src/Commands/WarmerCommands.php \Drupal\warmer\Commands\WarmerCommands::enqueue()

Enqueue specific warmer plugins.

@option run-queue If supplied, the warmer queue will be flushed at the end. That will leave all the items in the cache. If not, they'll be processed later by the queue workers on cron. @usage warmer-enqueue foo,bar --run-queue Pre-fetches all the items managed by the warmer with IDs foo or bar into the cache. @usage warmer-enqueue foo Schedules all the items managed by the warmer with ID foo for pre-fetching.

@command warmer:enqueue @aliases warmer-enqueue

@validate-warmer warmer_ids

Parameters

array $warmer_ids: List of plugin IDs separated by comas of the warmer to enqueue. See the warmer:list command to find all the available warmers.

array $options: An associative array of options whose values come from cli, aliases, config, etc.

Throws

\Exception

File

src/Commands/WarmerCommands.php, line 89

Class

WarmerCommands
Drush commands for the Warmer module.

Namespace

Drupal\warmer\Commands

Code

public function enqueue(array $warmer_ids, $options = [
  'run-queue' => FALSE,
]) {
  $warmer_ids = array_unique(StringUtils::csvToArray($warmer_ids));
  $warmers = $this->warmerManager
    ->getWarmers($warmer_ids);
  $batch_count = 0;
  $count_list = array_map(function (WarmerPluginBase $warmer) use (&$batch_count) {
    $count = 0;
    $ids = [
      NULL,
    ];
    while ($ids = $warmer
      ->buildIdsBatch(end($ids))) {
      $this->queueManager
        ->enqueueBatch(HookImplementations::class . '::warmBatch', $ids, $warmer);
      $batch_count++;
      $count += count($ids);
    }
    return $count;
  }, $warmers);
  $total = array_sum($count_list);
  $this
    ->logger()
    ->success(dt('@total items enqueued for cache warming.', [
    '@total' => $total,
  ]));
  if (!$options['run-queue']) {
    $this
      ->logger()
      ->notice(dt('If you need your items into cache right away you can run "drush queue-run warmer".'));
    return;
  }
  $this
    ->logger()
    ->success(dt('Warming caches in @count batches from the "warmer" queue.', [
    '@count' => $batch_count,
  ]));
  $this->queueCommands
    ->run('warmer', [
    'time-limit' => static::VERY_HIGH_NUMBER,
  ]);
  return;
}