You are here

function acquia_lift_process_queue in Acquia Lift Connector 7

Page callback - runs the Acquia Lift queue.

3 calls to acquia_lift_process_queue()
AcquiaLiftWebTestAgentAdmin::testPauseAgents in tests/acquia_lift.test
Tests that agents are paused when they need to be paused.
AcquiaLiftWebTestFundamentals::testAcquiaLiftQueue in tests/acquia_lift.test
acquia_lift_campaign_type_create_form_submit in ./acquia_lift.admin.unibar.inc
Submit handler to create a campaign from the Acquia Lift UI flow.
2 string references to 'acquia_lift_process_queue'
acquia_lift_command_process_queue in ./acquia_lift.module
Returns an AJAX command to trigger the Acquia Lift queue processing.
acquia_lift_menu in ./acquia_lift.module
Implements hook_menu().

File

./acquia_lift.module, line 1049
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_process_queue($exit_on_finish = TRUE) {
  if (!isset($_SESSION['acquia_lift_queue_trigger'])) {
    if ($exit_on_finish) {
      drupal_exit();
    }
    else {
      return;
    }
  }

  // Clear the session variable so the JS is no longer added to the page.
  unset($_SESSION['acquia_lift_queue_trigger']);

  // Allow execution to continue even if the request gets canceled.
  @ignore_user_abort(TRUE);

  // Try to allocate enough time to process the entire queue. It should
  // get through everything within a minute.
  drupal_set_time_limit(60);
  $queues = module_invoke('acquia_lift', 'cron_queue_info');
  $queue_name = 'acquia_lift_sync';
  $info = $queues[$queue_name];
  $function = $info['worker callback'];
  $end = time() + (isset($info['time']) ? $info['time'] : 15);
  $queue = DrupalQueue::get($queue_name);
  while (time() < $end && ($item = $queue
    ->claimItem())) {
    try {
      $function($item->data);
      $queue
        ->deleteItem($item);
    } catch (AcquiaLiftClientErrorException $e) {

      // If our worker callback throws an exception indicating a client error in
      // a request made to Lift, we should abort the processing of the queue and
      // set a message to let the user know things went wrong.
      drupal_set_message(t('An error occurred while syncing your campaign information to Lift: @error', array(
        '@error' => $e
          ->getMessage(),
      )));
      AcquiaLiftQueue::handleFailedItem($item);
      $queue
        ->deleteQueue();
      break;
    } catch (AcquiaLiftException $e) {

      // For other types of errors, allow the item to be retried.
      $queue
        ->releaseItem($item);
    }
  }
  acquia_lift_agent_clear_verified_status();
  if ($exit_on_finish) {
    drupal_exit();
  }
  else {
    return;
  }
}