/** * @param \Neoxygen\NeoClient\Event\HttpExceptionEvent $event */ public function onHttpException(HttpExceptionEvent $event) { $request = $event->getRequest(); $exception = $event->getException(); $message = $exception->getMessage(); Client::log('emergency', sprintf('Error on connection "%s" - %s', $request->getConnection(), $message)); throw new HttpException(sprintf('Error on Connection "%s" with message "%s"', $request->getConnection(), $message)); }
public function onRequestException(HttpExceptionEvent $event) { $request = $event->getRequest(); $this->fails[$request->getConnection()] = !isset($this->fails[$request->getConnection()]) ? 1 : $this->fails[$request->getConnection()] + 1; if ($request->hasQueryMode()) { if ($request->getQueryMode() == 'READ') { $this->slavesUsed[] = $request->getConnection(); if ($this->connectionManager->hasNextSlave($this->slavesUsed)) { $next = $this->connectionManager->getNextSlave($this->slavesUsed); Client::log('warning', sprintf('Connection "%s" unreacheable, using "%s"', $request->getConnection(), $next)); $request->setInfoFromConnection($this->connectionManager->getConnection($next)); $request->setQueryMode('READ'); $event->stopPropagation(); } elseif (null === $this->masterUsed) { $master = $this->connectionManager->getMasterConnection(); if (isset($master)) { Client::log('warning', sprintf('Connection "%s" unreacheable, using "%s"', $request->getConnection(), $master->getAlias())); $this->masterUsed = true; $request->setInfoFromConnection($master); $request->setQueryMode('READ'); $event->stopPropagation(); } else { Client::log('warning', sprintf('Connection "%s" unreacheable, even after trying the master', $request->getConnection())); } } } elseif ($request->getQueryMode() == 'WRITE') { Client::log('emergency', sprintf('The master connection "%s" is unreachable', $request->getConnection())); $newMaster = $this->detectReelectedMaster(); if (null !== $newMaster) { $conn = $this->connectionManager->getConnection($newMaster); $this->masterWriteFails = $this->masterWriteFails + 1; $this->newMasterDetected = $newMaster; $request->setInfoFromConnection($conn); $request->setQueryMode('WRITE'); $event->stopPropagation(); } } } }
public function onRequestException(HttpExceptionEvent $event) { $request = $event->getRequest(); $this->fails[$request->getConnection()] = !isset($this->fails[$request->getConnection()]) ? 1 : $this->fails[$request->getConnection()] + 1; if ($request->hasQueryMode()) { if ($request->getQueryMode() == 'READ') { $this->slavesUsed[] = $request->getConnection(); if ($this->connectionManager->hasNextSlave($this->slavesUsed)) { $next = $this->connectionManager->getNextSlave($this->slavesUsed); Client::log('warning', sprintf('Connection "%s" unreacheable, using "%s"', $request->getConnection(), $next)); $request->setInfoFromConnection($this->connectionManager->getConnection($next)); $event->stopPropagation(); } elseif (null === $this->masterUsed) { $master = $this->connectionManager->getMasterConnection(); Client::log('warning', sprintf('Connection "%s" unreacheable, using "%s"', $request->getConnection(), $master->getAlias())); $this->masterUsed = true; $request->setInfoFromConnection($master); $event->stopPropagation(); } } } }