You are here

function mailchimp_cron in Mailchimp 8

Same name and namespace in other branches
  1. 5.2 mailchimp.module \mailchimp_cron()
  2. 5 mailchimp.module \mailchimp_cron()
  3. 6.2 mailchimp.module \mailchimp_cron()
  4. 6 mailchimp.module \mailchimp_cron()
  5. 7.5 mailchimp.module \mailchimp_cron()
  6. 7 mailchimp.module \mailchimp_cron()
  7. 7.3 mailchimp.module \mailchimp_cron()
  8. 7.4 mailchimp.module \mailchimp_cron()
  9. 2.x mailchimp.module \mailchimp_cron()

Implements hook_cron().

Processes queued Mailchimp actions.

1 call to mailchimp_cron()
_mailchimp_cron_batch in includes/mailchimp.drush.inc
Callback function to run cron.

File

./mailchimp.module, line 1424
Mailchimp module.

Code

function mailchimp_cron() {
  $queue = \Drupal::queue(MAILCHIMP_QUEUE_CRON);
  $queue
    ->createQueue();
  $queue_count = $queue
    ->numberOfItems();
  if ($queue_count > 0) {
    $config = \Drupal::config('mailchimp.settings');
    $batch_limit = $config
      ->get('batch_limit');
    $batch_size = $queue_count < $batch_limit ? $queue_count : $batch_limit;
    $count = 0;
    while ($count < $batch_size) {
      if ($item = $queue
        ->claimItem()) {
        call_user_func_array($item->data['function'], $item->data['args']);
        $queue
          ->deleteItem($item);
      }
      $count++;
    }
  }
}