public function execute($callback, $args = array())
 {
     $this->callback = $callback;
     $this->args = $args;
     if (!background_process_set_process($this->handle, $this->callback, $this->uid, $this->args, $this->token)) {
         // Could not update process
         return NULL;
     }
     module_invoke_all('background_process_pre_execute', $this->handle, $this->callback, $this->args, $this->token);
     // Initialize progress stats
     $old_db = db_set_active('background_process');
     progress_remove_progress($this->handle);
     db_set_active($old_db);
     $this->connection = FALSE;
     $this->determineServiceHost();
     return $this->dispatch();
 }
 /**
  * Lock job.
  *
  * Background Process doesn't internally provide a unique id
  * for the running process, so we'll have to add that ourselves.
  * We store the unique lock id in the second callback argument.
  */
 public function lock($job)
 {
     $handle = 'uc-' . $job->name;
     $process = new BackgroundProcess($handle);
     if (!$process->lock()) {
         return FALSE;
     }
     $lock_id = $job->name . ':' . uniqid('bgpl', TRUE);
     global $user;
     background_process_set_process($process->handle, '__LOCKED__', $user->uid, array($job->name, $lock_id), $process->token);
     return $lock_id;
 }