From ac59cd71aaf8684170f6fb07d115b0eadb68b04e Mon Sep 17 00:00:00 2001 From: Lang Date: Wed, 23 Nov 2016 22:32:25 +0100 Subject: [PATCH] handle prod mysql timeout && graphics improve --- .../Resources/public/css/style.mineseeker.css | 2 ++ src/Mine/SeekerBundle/Rpc/MineseekerRpc.php | 17 +++++++++++++++ .../SeekerBundle/Topic/MineseekerTopic.php | 21 ++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css index ae59b1d..f22bc4b 100644 --- a/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css +++ b/src/Mine/SeekerBundle/Resources/public/css/style.mineseeker.css @@ -189,6 +189,8 @@ main { background: -webkit-linear-gradient(top, rgba(35, 111, 135, 1) 0%, rgba(149, 207, 245, 1) 100%); background: linear-gradient(to bottom, rgba(35, 111, 135, 1) 0%, rgba(149, 207, 245, 1) 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#236f87', endColorstr='#95cff5', GradientType=0); + + margin-top: 0; } #mine-wrapper .game-wrapper .users .user-container.user-red { diff --git a/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php b/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php index 88fcc26..319bb45 100644 --- a/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php +++ b/src/Mine/SeekerBundle/Rpc/MineseekerRpc.php @@ -65,6 +65,7 @@ class MineseekerRpc implements RpcInterface */ private function getGrid($gameAssoc) { + $this->reConnect(); $getsee = array(); $this->em->clear(); @@ -87,6 +88,7 @@ class MineseekerRpc implements RpcInterface */ private function saveGrid($data) { + $this->reConnect(); $playedGame = new PlayedGame(); $grid = new Grid(); @@ -113,4 +115,19 @@ class MineseekerRpc implements RpcInterface return true; } + + /** Handle prod MySQL timeout */ + private function reConnect() + { + try { + $connection = $this->em->getConnection(); + + if (false === $connection->ping()) { + $connection->close(); + $connection->connect(); + } + } catch(PDOException $ex) { + throw PDOException::class; + } + } } diff --git a/src/Mine/SeekerBundle/Topic/MineseekerTopic.php b/src/Mine/SeekerBundle/Topic/MineseekerTopic.php index f3a9459..577eab7 100644 --- a/src/Mine/SeekerBundle/Topic/MineseekerTopic.php +++ b/src/Mine/SeekerBundle/Topic/MineseekerTopic.php @@ -2,6 +2,7 @@ namespace Mine\SeekerBundle\Topic; +use Doctrine\DBAL\Driver\PDOException; use Doctrine\ORM\EntityManager; use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface; use Gos\Bundle\WebSocketBundle\Topic\TopicInterface; @@ -43,7 +44,7 @@ class MineseekerTopic implements TopicInterface * @param ConnectionInterface $connection * @param Topic $topic * @param WampRequest $request - * @return void + * @return void4 */ public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request) { @@ -131,6 +132,7 @@ class MineseekerTopic implements TopicInterface */ private function saveResignToDb($topic, $color) { + $this->reConnect(); $gameAssoc = explode('/', $topic->getId())[2]; $playedGame = $this->em @@ -150,6 +152,7 @@ class MineseekerTopic implements TopicInterface */ private function saveStepToDb($topic, $event) { + $this->reConnect(); $gameAssoc = explode('/', $topic->getId())[2]; $playedGame = $this->em @@ -184,6 +187,7 @@ class MineseekerTopic implements TopicInterface */ private function saveUserToDb($topic, $userName, $user, $count) { + $this->reConnect(); $gameAssoc = explode('/', $topic->getId())[2]; $playedGame = $this->em @@ -234,4 +238,19 @@ class MineseekerTopic implements TopicInterface 'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '' ); } + + /** Handle prod MySQL timeout */ + private function reConnect() + { + try { + $connection = $this->em->getConnection(); + + if (false === $connection->ping()) { + $connection->close(); + $connection->connect(); + } + } catch(PDOException $ex) { + throw PDOException::class; + } + } }