예제 #1
0
 /**
  * Defer task.
  *
  * @param int      $pid
  * @param callable $deferrer
  *
  * @return $this
  */
 public function defer($pid, $deferrer)
 {
     $connection = $this->entityManager->getConnection();
     $this->entity->setPid($pid);
     $this->entityManager->flush();
     $connection->close();
     $exitCode = $deferrer();
     $connection->connect();
     $this->entity->setExitCode($exitCode);
     $this->entityManager->flush();
     return $this;
 }
예제 #2
0
 /**
  * Test that all values can be set and are returned afterwards.
  */
 public function testTaskEntityAccessors()
 {
     $createdAt = new \DateTime('yesterday');
     $updatedAt = new \DateTime();
     $entity = new TaskEntity();
     $entity->setPriority(100)->setCommandline('commandline')->setPid(1001)->setExitCode(0)->setCreatedAt($createdAt)->setUpdatedAt($updatedAt);
     $this->assertNull($entity->getId());
     $this->assertSame(100, $entity->getPriority());
     $this->assertSame('commandline', $entity->getCommandline());
     $this->assertSame(1001, $entity->getPid());
     $this->assertSame(0, $entity->getExitCode());
     $this->assertSame($createdAt, $entity->getCreatedAt());
     $this->assertSame($updatedAt, $entity->getUpdatedAt());
 }
예제 #3
0
 /**
  * Test that the task runner runs all tasks in quiet mode.
  */
 public function testTaskRunnerRunsAllTasksInQuietMode()
 {
     $connection = $this->createMock(Connection::class);
     $entityManager = $this->createMock(EntityManagerInterface::class);
     $entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $entityOne = new TaskEntity();
     if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
         $entityOne->setCommandline('dir');
     } else {
         $entityOne->setCommandline('ls -l');
     }
     $entityTwo = new TaskEntity();
     $entityTwo->setCommandline('foobarbaz');
     $taskManager = $this->createMock(TaskManager::class);
     $taskManager->expects($this->exactly(3))->method('findNextTask')->will($this->onConsecutiveCalls(new Task($entityManager, $entityOne), new Task($entityManager, $entityTwo), null));
     $output = $this->createMock(OutputInterface::class);
     $output->expects($this->atLeastOnce())->method('isQuiet')->will($this->returnValue(true));
     $logger = $this->createMock(LoggerInterface::class);
     $logger->expects($this->atLeastOnce())->method('log');
     $taskRunner = new TaskRunner($taskManager, $output, $logger);
     $taskRunner->runAll(60);
     $this->assertInternalType('integer', $entityOne->getPid());
     $this->assertEquals(0, $entityOne->getExitCode());
 }
예제 #4
0
 /**
  * Create and persist new task.
  *
  * @param string   $commandline
  * @param int|null $priority
  *
  * @return Task
  */
 public function newTask($commandline, $priority = null)
 {
     if (null === $priority) {
         $priority = TaskEntity::DEFAULT_PRIORITY;
     }
     $entity = new TaskEntity();
     $entity->setCommandline($commandline);
     $entity->setPriority($priority);
     $this->entityManager->persist($entity);
     $this->entityManager->flush();
     return new Task($this->entityManager, $entity);
 }
 /**
  * Test that the next entity can be found by commandline.
  */
 public function testFindingNextByCommandline()
 {
     $entityManager = $this->getEntityManager();
     $entityOne = new TaskEntity();
     $entityOne->setPriority(1000);
     $entityOne->setCommandline('foo');
     $entityTwo = new TaskEntity();
     $entityTwo->setPriority(1);
     $entityTwo->setCommandline('bar');
     $entityManager->persist($entityOne);
     $entityManager->persist($entityTwo);
     $entityManager->flush();
     $class = $entityManager->getClassMetadata(TaskEntity::class);
     $repository = new TaskEntityRepository($entityManager, $class);
     $entity = $repository->findNextByCommandline('foo');
     $this->assertInstanceOf(TaskEntity::class, $entity);
     $this->assertSame('foo', $entity->getCommandline());
 }