function it_can_be_executed(Redis $redis, Worker $worker)
 {
     $workerId = '1234@localhost';
     $worker->identify()->willReturn($workerId);
     $nowIso = '2015-04-18T13:16:16.263400+0000';
     $redis->multi()->shouldBeCalled();
     $redis->sadd("workers", "{$workerId}")->shouldBeCalled();
     $redis->del("worker:{$workerId}:queues")->shouldBeCalled();
     $redis->zadd("worker:{$workerId}:queues", 0, 'my-queue')->shouldBeCalled();
     $redis->zadd("worker:{$workerId}:queues", 1, 'your-queue')->shouldBeCalled();
     $redis->hsetnx("worker:{$workerId}:status", "first-seen", $nowIso)->shouldBeCalled();
     $redis->hset("worker:{$workerId}:status", "last-seen", $nowIso)->shouldBeCalled();
     $redis->expire("worker:{$workerId}:queues", 7 * 24 * 3600)->shouldBeCalled();
     $redis->expire("worker:{$workerId}:status", 7 * 24 * 3600)->shouldBeCalled();
     $redis->exec()->shouldBeCalled();
     $this->execute();
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $queues = $input->getArgument('queues');
     $logger = $this->logger ?: $this->createDefaultLogger($output);
     $jobExecutor = $this->jobExecutor ?: $this->createDefaultJobExecutor();
     $worker = new Worker($this->metro, $jobExecutor, $logger, ...$queues);
     $worker->setInterval((int) $input->getOption('interval'));
     $input->getOption('once') && $worker->setInterval(0);
     $input->getOption('drain') && $worker->quitAsap();
     $this->updateProcTitleIfPossible($worker->identify(), $queues);
     $worker->work();
 }