You are here

public function BackgroundProcess::queue in Background Process 6

Same name and namespace in other branches
  1. 8 background_process.class.php \BackgroundProcess::queue()
  2. 7 BackgroundProcess.class.php \BackgroundProcess::queue()

File

./BackgroundProcess.class.php, line 87
Class for handling background processes.

Class

BackgroundProcess
BackgroundProcess class.

Code

public function queue($callback, $args = array()) {
  if (!module_exists('drupal_queue')) {
    throw new Exception(t('Drupal Queue is not installed'));
  }
  if (!$this
    ->lock(BACKGROUND_PROCESS_STATUS_QUEUED)) {
    return FALSE;
  }
  if (!background_process_set_process($this->handle, $callback, $this->uid, $args, $this->token)) {

    // Could not update process
    return NULL;
  }
  drupal_queue_include();
  module_invoke_all('background_process_pre_execute', $this->handle, $callback, $args, $this->token);

  // Initialize progress stats
  progress_remove_progress($this->handle);
  $queues = variable_get('background_process_queues', array());
  $queue_name = isset($queues[$callback]) ? 'bgp:' . $queues[$callback] : 'background_process';
  $queue = DrupalQueue::get($queue_name);
  $queue
    ->createItem(array(
    rawurlencode($this->handle),
    rawurlencode($this->token),
  ));
  _background_process_ensure_cleanup($this->handle, TRUE);
}