You are here

function akamai_cron_process_queue in Akamai 7.3

Processes queued purge requests and submits them to the CCU API in batches.

1 call to akamai_cron_process_queue()
akamai_cron in ./akamai.module
Implements hook_cron().

File

./akamai.cron.inc, line 13
Contains functions for running cron tasks.

Code

function akamai_cron_process_queue() {
  $end = time() + variable_get('akamai_cron_queue_time_limit', AKAMAI_CRON_QUEUE_TIME_LIMIT_DEFAULT);
  $queue = DrupalQueue::get('akamai_ccu');
  $client = akamai_get_client();
  $batch_size = variable_get('akamai_batch_size', NULL);
  $batcher = new \Drupal\akamai\Batcher($client, $batch_size);
  while (time() < $end && ($item = $queue
    ->claimItem())) {
    try {
      $batcher
        ->insertItem($item);
    } catch (Exception $e) {
      watchdog_exception('akamai', $e);
    }
  }

  // Submit at least one batch.
  // Continue submitting batches until time limit is reached.
  while (!$batcher
    ->isEmpty()) {
    $batch = $batcher
      ->getBatch();
    $response = akamai_submit_batch($batch);
    if (!empty($response) || !variable_get('akamai_queue_on_failure', TRUE)) {
      foreach ($batch
        ->getItems() as $item) {
        $queue
          ->deleteItem($item);
      }
    }
    else {
      foreach ($batch
        ->getItems() as $item) {
        $queue
          ->releaseItem($item);
      }
    }
    if (time() > $end) {
      break;
    }
  }

  // Release any items that didn't make it into a batch.
  if (!$batcher
    ->isEmpty()) {
    $unsubmitted_items = $batcher
      ->getItems();
    foreach ($unsubmitted_items as $item) {
      $queue
        ->releaseItem($item);
    }
  }
}