Skip to content

Commit

Permalink
[devices-module] Refresh DB connection (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 13, 2023
1 parent 2311c75 commit dbf56c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/Commands/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,15 @@ private function executeConnector(Style\SymfonyStyle $io, Input\InputInterface $
self::DATABASE_REFRESH_INTERVAL,
function (): void {
$this->eventLoop->futureTick(function (): void {
try {
$this->database->clear();
} catch (Throwable $ex) {
throw new Exceptions\Terminate('Failed to refresh database connection', $ex->getCode(), $ex);
// Check if ping to DB is possible...
if (!$this->database->ping()) {
// ...if not, try to reconnect
$this->database->reconnect();

// ...and ping again
if (!$this->database->ping()) {
throw new Exceptions\Terminate('Connection to database could not be re-established');
}
}
});
},
Expand Down
6 changes: 2 additions & 4 deletions src/Utilities/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,12 @@ private function pingAndReconnect(): void

// ...and ping again
if (!$this->database->ping()) {
throw new Exceptions\Runtime('Connection to database could not be established');
throw new Exceptions\Runtime('Connection to database could not be re-established');
}

$this->database->clear();
}
} catch (Throwable $ex) {
throw new Exceptions\Runtime(
'Connection to database could not be reestablished',
'Connection to database could not be re-established',
$ex->getCode(),
$ex,
);
Expand Down

0 comments on commit dbf56c9

Please sign in to comment.