예제 #1
0
 /**
  * Checks if the Queue Manager is already running in a different process.
  *
  * @TODO: This is not using the ->add() atomic operation, so it will fail the concurrency checks. Fix this.
  * @return bool If the manager is running in another process.
  */
 public function checkServer()
 {
     if (!$this->memcache->add('queue.lock', getmypid())) {
         $pid = $this->memcache->get('queue.lock');
         if ($this->isQueueRunning($pid)) {
             return true;
         } else {
             $this->memcache->delete('queue.lock');
             return $this->checkServer();
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Adds a Process to the queue.
  *
  * @param Process $process Process to be added.
  * @param string $name The process name
  */
 public function addProcess(Process $process, $name = null, $flush = true)
 {
     /** @var \SplQueue $queue */
     $queue = $this->getQueue(true);
     if (!$name) {
         $name = substr(str_shuffle(md5(microtime())), 0, 10);
     }
     $this->memcache->add('queue.process.processlist.' . $name, $process);
     $service = new \Symfony\Component\Process\Process($this->phpPath . ' app/console naroga:queue:dispatch ' . $name);
     $processData = new ProcessData($service, $name);
     $queue->enqueue($processData);
     if ($flush) {
         $this->flush($queue);
     }
     $this->eventDispatcher->dispatch('queue.process_queued', new ProcessQueuedEvent($processData->getName(), $process));
 }