示例#1
0
 function it_does_not_clean_up_workers_on_another_host(SystemInterface $system, $workerRegistry, WorkerInterface $localWorker, WorkerInterface $remoteWorker, Process $localProcess, Process $remoteProcess)
 {
     $system->getCurrentPid()->willReturn(6545);
     $system->getHostname()->shouldBeCalled()->willReturn('bar.resque.com');
     $workerRegistry->all()->shouldBeCalled()->willReturn([$localWorker, $remoteWorker]);
     $localWorker->getProcess()->shouldBeCalled()->willReturn($localProcess);
     $remoteWorker->getProcess()->shouldBeCalled()->willReturn($remoteProcess);
     $localWorker->getHostname()->shouldBeCalled()->willReturn('bar.resque.com');
     $remoteWorker->getHostname()->shouldBeCalled()->willReturn('my.other.host');
     $localProcess->getPid()->willReturn(1);
     $remoteProcess->getPid()->willReturn(1);
     $workerRegistry->deregister($localWorker)->shouldBeCalled();
     $workerRegistry->deregister($remoteWorker)->shouldNotBeCalled();
     $this->pruneDeadWorkers();
 }
示例#2
0
 /**
  * Prune dead workers.
  *
  * Look for any workers which should be running on this server and if
  * they're not, remove them from Redis.
  *
  * This is a form of garbage collection to handle cases where the
  * server may have been killed and the workers did not exit gracefully
  * and therefore leave state information in Redis.
  *
  * @return void
  */
 public function pruneDeadWorkers()
 {
     $workerPids = $this->getLocalWorkerPids();
     $workers = $this->registry->all();
     // @todo Maybe findWorkersForHost($hostname) ?
     $hostname = $this->system->getHostname();
     foreach ($workers as $worker) {
         if ($worker instanceof WorkerInterface) {
             $isNotOnCurrentHost = $worker->getHostname() != $hostname;
             $isCurrentlyRunning = in_array($worker->getProcess()->getPid(), $workerPids);
             $isCurrentProcess = $worker->getProcess()->getPid() == $this->system->getCurrentPid();
             if ($isNotOnCurrentHost || $isCurrentlyRunning || $isCurrentProcess) {
                 continue;
             }
             $this->logger->warning('Pruning dead worker {worker}', array('worker' => $worker));
             $this->registry->deregister($worker);
         }
     }
 }
示例#3
0
 function it_sets_the_workers_hostname_on_create(SystemInterface $system)
 {
     $system->getHostname()->shouldBeCalled(1)->willReturn('wild.ones');
     $this->createWorker()->getHostname()->shouldEqual('wild.ones');
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function createWorker()
 {
     $worker = new Worker($this->jobInstanceFactory, $this->eventDispatcher);
     $worker->setHostname($this->system->getHostname());
     return $worker;
 }