/**
  * @param WorkerInterface $worker
  *
  * @throws \LogicException if a worker with the name exists
  */
 public function addWorker(WorkerInterface $worker)
 {
     $name = $worker->getName();
     if (isset($this->workers[$name])) {
         throw new \LogicException(sprintf('A worker named `%s` already exists', $name));
     }
     $this->workers[$name] = $worker;
 }
Beispiel #2
0
 /**
  * @param WorkerInterface $worker
  * @param int $delay Seconds to wait before pulling the queue again
  */
 public function process($worker, $delay = 0)
 {
     while (true) {
         if (!$this->isEmpty()) {
             $worker->add($this->pull());
         }
         sleep($delay);
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function add(WorkerInterface $worker)
 {
     try {
         $this->setWorkerInstance($worker);
     } catch (\Exception $e) {
         $this->getOutput()->write('[x] Unable to set worker instance: ' . $e->getMessage());
     }
     $cmd1 = $worker->getProcess()->getCommand()->getCmd();
     $cmd2 = $this->workerInstance->getProcess()->getCommand()->getCmd();
     if ($cmd1 === $cmd2) {
         $this->workers[] = $worker;
     } else {
         $msg = '$worker must be an instance of WorkerInterface and the same as';
         throw new \Exception($msg . get_class($worker));
     }
     return $this;
 }