Exemplo n.º 1
0
 public function update(Worker $worker)
 {
     /** @var EntityManager $em */
     $em = $this->doctrine->getManager();
     $exception = null;
     $i = 0;
     while ($i < 5) {
         try {
             $worker = $this->getWorker(['queue' => $worker->getQueue(), 'instance' => $worker->getInstance(), 'host' => $worker->getHost()]);
             $em->persist($worker);
             $em->flush();
             return;
         } catch (\Exception $e) {
             // the connection might have "gone away"
             $this->logger->warning("Error while updating worker entity", ['message' => $e->getMessage()]);
             $exception = $e;
             $this->doctrine->resetManager();
             $em = $this->doctrine->getManager();
             $em->getConnection()->close();
             $em->getConnection()->connect();
         }
         $i++;
     }
     throw new ApplicationException("Unable to update worker entity", $exception);
 }
 private function reset()
 {
     if ($this->doctrine) {
         /** @var Connection $c */
         $c = $this->doctrine->getConnection();
         $c->close();
         $this->doctrine->resetManager();
     }
 }
Exemplo n.º 3
0
 public function testResetUnknownEntityManager()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $registry = new Registry($container, array(), array(), 'default', 'default');
     $this->setExpectedException('InvalidArgumentException', 'Doctrine ORM Manager named "default" does not exist.');
     $registry->resetManager('default');
 }