You are here

public static function BrightcoveUtil::runStatusQueues in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 src/BrightcoveUtil.php \Drupal\brightcove\BrightcoveUtil::runStatusQueues()
  2. 3.x src/BrightcoveUtil.php \Drupal\brightcove\BrightcoveUtil::runStatusQueues()

Runs specific status queues based on the given $type.

Parameters

string $type: The queue's type to run, it can be either sync, run or clear.

\Drupal\Core\Queue\QueueFactory $queue_factory: Queue factory.

Throws

\Drupal\brightcove\Exception\BrightcoveUtilException Throws an exception if the queue type is invalid.

3 calls to BrightcoveUtil::runStatusQueues()
BrightcoveCommands::syncAll in src/Commands/BrightcoveCommands.php
Initiates a Brightcove-to-Drupal sync by adding API clients to the queue.
drush_brightcove_sync_all in ./brightcove.drush.inc
Implements drush_hook_COMMAND().
StatusOverviewForm::submitForm in src/Form/StatusOverviewForm.php
Form submission handler.

File

src/BrightcoveUtil.php, line 276

Class

BrightcoveUtil
Utility class for Brightcove.

Namespace

Drupal\brightcove

Code

public static function runStatusQueues($type, QueueFactory $queue_factory) {
  $queues = self::getStatusQueues();
  $batch_operations = [];
  switch ($type) {
    case 'sync':
      $batch_operations[] = [
        '_brightcove_initiate_sync',
        [],
      ];

    // There is intentionally no break here.
    case 'run':
      $queue_type = 'runQueue';
      break;
    case 'clear':
      $queue_type = 'clearQueue';
      break;
    default:
      throw new BrightcoveUtilException('Invalid queue type.');
  }

  // Build queue operations array.
  foreach ($queues as $queue) {
    $batch_operations[] = [
      [
        static::class,
        $queue_type,
      ],
      [
        $queue,
      ],
    ];
  }
  if ($batch_operations) {

    // Clean-up expired items in the default queue implementation table. If
    // that's not used, this will simply be a no-op.
    // @see system_cron()
    foreach ($queues as $queue) {
      $queue = $queue_factory
        ->get($queue);
      if ($queue instanceof QueueGarbageCollectionInterface) {
        $queue
          ->garbageCollection();
      }
    }
    batch_set([
      'operations' => $batch_operations,
    ]);
  }
}