You are here

function purge_processor_cron_cron in Purge 8.3

Implements hook_cron().

File

modules/purge_processor_cron/purge_processor_cron.module, line 15
Purge Cron Processor.

Code

function purge_processor_cron_cron() {
  $purgePurgers = \Drupal::service('purge.purgers');
  $purgeProcessors = \Drupal::service('purge.processors');
  $purgeQueue = \Drupal::service('purge.queue');

  // Do not continue when the cron processor isn't enabled.
  if (!($processor = $purgeProcessors
    ->get('cron'))) {
    return;
  }

  // Claim zero or more items from the queue and feed it to the purgers service.
  $claims = $purgeQueue
    ->claim();
  try {
    $purgePurgers
      ->invalidate($processor, $claims);
  } catch (DiagnosticsException $e) {

    // Diagnostic exceptions happen when the system cannot purge.
  } catch (CapacityException $e) {

    // Capacity exceptions happen when too much was purged during this request.
  } catch (LockException $e) {

    // Lock exceptions happen when another code path is currently processing.
  } finally {
    $purgeQueue
      ->handleResults($claims);
  }
}