Added logging to Notify command.

Signed-off-by: Ari Selseng <ari@selseng.net>
This commit is contained in:
Ari Selseng 2019-03-04 13:54:52 +01:00
parent 71a0cdceaa
commit 3218e0f70d
1 changed files with 9 additions and 2 deletions

View File

@ -37,6 +37,7 @@ use OCP\Files\Storage\INotifyStorage;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -49,11 +50,14 @@ class Notify extends Base {
private $connection; private $connection;
/** @var \OCP\DB\QueryBuilder\IQueryBuilder */ /** @var \OCP\DB\QueryBuilder\IQueryBuilder */
private $updateQuery; private $updateQuery;
/** @var ILogger */
private $log;
function __construct(GlobalStoragesService $globalService, IDBConnection $connection) { function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) {
parent::__construct(); parent::__construct();
$this->globalService = $globalService; $this->globalService = $globalService;
$this->connection = $connection; $this->connection = $connection;
$this->logger = $logger;
$this->updateQuery = $this->getUpdateQuery($this->connection); $this->updateQuery = $this->getUpdateQuery($this->connection);
} }
@ -159,7 +163,8 @@ class Notify extends Base {
try { try {
$this->updateQuery->execute([$parent, $mountId]); $this->updateQuery->execute([$parent, $mountId]);
} catch (DriverException $th) { } catch (DriverException $ex) {
$this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while trying to mark folder as outdated', 'level' => ILogger::WARN]);
$this->connection = $this->reconnectToDatabase($this->connection, $output); $this->connection = $this->reconnectToDatabase($this->connection, $output);
$output->writeln('<info>Needed to reconnect to the database</info>'); $output->writeln('<info>Needed to reconnect to the database</info>');
$this->updateQuery = $this->getUpdateQuery($this->connection); $this->updateQuery = $this->getUpdateQuery($this->connection);
@ -212,12 +217,14 @@ class Notify extends Base {
try { try {
$connection->close(); $connection->close();
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]);
$output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
} }
while (!$connection->isConnected()) { while (!$connection->isConnected()) {
try { try {
$connection->connect(); $connection->connect();
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]);
$output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>");
sleep(60); sleep(60);
} }