示例#1
0
文件: Worker.php 项目: zwilias/qman
 public function run()
 {
     $this->startTime = time();
     $workers = $this->beanie->workers();
     $this->registerWatchers($workers);
     register_shutdown_function([$this->shutdownHandler, 'handleShutdown'], $this, $this->logger);
     $this->eventLoop->run();
     $this->shutdown($workers);
     $this->logger->info('Termination sequence complete. I\'ll be back.');
 }
示例#2
0
 public function testWorkers_retrievesServers_getsWorkers()
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|Server $serverMock */
     $serverMock = $this->getMockBuilder(Server::class)->disableOriginalConstructor()->getMock();
     /** @var \PHPUnit_Framework_MockObject_MockObject|Pool $poolMock */
     $poolMock = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->setMethods(['getServers'])->getMock();
     $poolMock->expects($this->once())->method('getServers')->willReturn([$serverMock]);
     $beanie = new Beanie($poolMock);
     $workers = $beanie->workers();
     $this->assertEquals([new Worker($serverMock)], $workers);
 }
示例#3
0
 public function testJob_buryBuries_kickKicks()
 {
     $this->beanie->producer()->put('test');
     $job = $this->beanie->worker()->reserve();
     $job->bury();
     $jobStats = $job->stats();
     $this->assertEquals($jobStats['state'], 'buried');
     $this->beanie->manager($this->serverName)->tubes()[0]->kick();
     $jobStats = $job->stats();
     $this->assertEquals($jobStats['state'], 'ready');
     $job->delete();
 }
示例#4
0
 public function testWorker_reserve_receivesJob()
 {
     $jobData = 'test';
     $response = sprintf('%s %s %s', \Beanie\Command\Response::RESPONSE_RESERVED, 1, strlen($jobData));
     $worker = \Beanie\Beanie::pool([$this->serverName])->worker();
     $worker->getServer()->connect();
     $acceptedConnection = socket_accept($this->socket);
     socket_set_nonblock($acceptedConnection);
     socket_write($acceptedConnection, $response . "\r\n");
     socket_write($acceptedConnection, $jobData . "\r\n");
     $job = $worker->reserve();
     $command = socket_read($acceptedConnection, 1024);
     $this->assertEquals(sprintf('%s' . "\r\n", \Beanie\Command\CommandInterface::COMMAND_RESERVE), $command);
     $this->assertInstanceOf(\Beanie\Job\Job::class, $job);
     $this->assertEquals(1, $job->getId());
     $this->assertEquals($jobData, $job->getData());
     $this->assertEquals(\Beanie\Job\Job::STATE_RESERVED, $job->getState());
     socket_close($acceptedConnection);
 }
示例#5
0
文件: QMan.php 项目: zwilias/qman
 /**
  * @param string[] $servers
  * @param CommandSerializerInterface $serializer
  * @param LoggerInterface $logger
  * @return static
  */
 public static function create(array $servers, CommandSerializerInterface $serializer = null, LoggerInterface $logger = null)
 {
     return new static(Beanie::pool($servers)->producer(), $serializer, $logger);
 }