/**
  * {@inheritDoc}
  */
 public function delete(WorkerInterface $worker)
 {
     $id = $worker->getId();
     $this->redis->srem('workers', $id);
     $this->redis->del('worker:' . $id);
     $this->redis->del('worker:' . $id . ':started');
     return $this;
 }
 function it_deletes_workers_from_redis(RedisClientInterface $redis, WorkerInterface $worker)
 {
     $worker->getId()->shouldBeCalled()->willReturn('local:789');
     $redis->srem('workers', 'local:789')->shouldBeCalled()->willReturn(1);
     $redis->del('worker:local:789')->shouldBeCalled()->willReturn(1);
     $redis->del('worker:local:789:started')->shouldBeCalled()->willReturn(1);
     $this->delete($worker)->shouldReturn($this);
 }
Example #3
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();
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 public function save(JobInterface $job, \Exception $exception, WorkerInterface $worker)
 {
     $queue = $job instanceof OriginQueueAwareInterface ? $job->getOriginQueue() : null;
     $this->redis->rpush('failed', json_encode(array('failed_at' => date('c'), 'payload' => $job, 'exception' => get_class($exception), 'error' => $exception->getMessage(), 'backtrace' => explode("\n", $exception->getTraceAsString()), 'worker' => $worker->getId(), 'queue' => $queue instanceof QueueInterface ? $queue->getName() : null)));
 }
 /**
  * {@inheritDoc}
  */
 public function has(WorkerInterface $worker)
 {
     return isset($this->workers[$worker->getId()]);
 }
Example #6
0
 /**
  * Deregister on worker exit.
  *
  * @param WorkerInterface $worker The worker to wait for exit and then deregister.
  * @throws ResqueRuntimeException when $worker fails to exit cleanly.
  * @return void
  */
 public function deregisterOnWorkerExit(WorkerInterface $worker)
 {
     $process = $worker->getProcess();
     $process->wait();
     if ($process->isCleanExit()) {
         $this->registry->deregister($worker);
     } else {
         throw new ResqueRuntimeException(sprintf('Foreman error with worker %s wait on pid %d', $worker->getId(), $process->getPid()));
     }
 }