From 6adee3cf7905400669c44bd9e5196ece89068531 Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Thu, 9 Jun 2022 18:50:23 +0300 Subject: [PATCH] Updated state:push log messages to reflect the changes to the underlying structure. --- src/Commands/State/ExportCommand.php | 6 +-- src/Commands/State/PushCommand.php | 76 ++++++++++++---------------- 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/Commands/State/ExportCommand.php b/src/Commands/State/ExportCommand.php index b42c3210..4e969008 100644 --- a/src/Commands/State/ExportCommand.php +++ b/src/Commands/State/ExportCommand.php @@ -200,7 +200,6 @@ class ExportCommand extends Command } if (count($entities) >= 1) { - $this->logger->info( 'SYSTEM: Checking [%(total)] media items for push mode compatibility.', (function () use ($entities, $input): array { @@ -318,8 +317,10 @@ class ExportCommand extends Command $this->logger->notice('SYSTEM: Sent [%(total)] change play state requests.', [ 'total' => $total ]); + + $this->logger->notice(sprintf('Using WatchState Version - \'%s\'.', getAppVersion())); } else { - $this->logger->notice('No play state changes detected.'); + $this->logger->notice('SYSTEM: No play state changes detected.'); } if (false === $input->getOption('dry-run')) { @@ -345,7 +346,6 @@ class ExportCommand extends Command file_put_contents($config, Yaml::dump(Config::get('servers', []), 8, 2)); } - $this->logger->notice(sprintf('Using WatchState Version - \'%s\'.', getAppVersion())); return self::SUCCESS; } diff --git a/src/Commands/State/PushCommand.php b/src/Commands/State/PushCommand.php index 46b9e838..3a8ed3f6 100644 --- a/src/Commands/State/PushCommand.php +++ b/src/Commands/State/PushCommand.php @@ -19,7 +19,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Yaml\Yaml; -use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; class PushCommand extends Command { @@ -92,8 +91,6 @@ class PushCommand extends Command return self::SUCCESS; } - $this->logger->info(sprintf('Using WatchState Version - \'%s\'.', getAppVersion())); - $list = []; $supported = Config::get('supported', []); @@ -167,65 +164,54 @@ class PushCommand extends Command if ($total >= 1) { $start = makeDate(); - $this->logger->notice('SYSTEM: Sending change play state requests.', [ - 'context' => [ - 'total' => $total, - 'time' => [ - 'start' => $start, - ], + $this->logger->notice('SYSTEM: Sending [%(total)] change play state requests.', [ + 'total' => $total, + 'time' => [ + 'start' => $start, ], ]); foreach ($this->queue->getQueue() as $response) { - $requestData = $response->getInfo('user_data'); + $context = ag($response->getInfo('user_data'), 'context', []); try { if (200 !== $response->getStatusCode()) { - $this->logger->error('Unexpected change play state response code.', [ - 'context' => [ - 'backend' => ag($requestData, 'server', '??'), - 'title' => ag($requestData, 'itemName', '??'), - ], - 'condition' => [ - 'expected' => 200, - 'given' => $response->getStatusCode(), - ], - ]); + $this->logger->error( + 'Request to change [%(backend)] [%(item.title)] play state returned with unexpected [%(status_code)] status code.', + $context + ); continue; } - $this->logger->notice('Marked [%(title)] as [%(state)].', [ - 'state' => ag($requestData, 'state', '??'), - 'backend' => ag($requestData, 'server', '??'), - 'title' => ag($requestData, 'itemName', '??'), - ]); - } catch (ExceptionInterface $e) { - $this->logger->error($e->getMessage(), [ - 'context' => [ - 'backend' => ag($requestData ?? [], 'server', '??'), - 'title' => ag($requestData ?? [], 'itemName', '??'), - ], - 'trace' => [ - 'file' => $e->getFile(), - 'line' => $e->getLine(), - 'kind' => get_class($e), - ], - ]); + $this->logger->notice('Marked [%(backend)] [%(item.title)] as [%(play_state)].', $context); + } catch (\Throwable $e) { + $this->logger->error( + 'Unhandled exception thrown during request to change play state of [%(backend)] %(item.type) [%(item.title)].', + [ + ...$context, + 'exception' => [ + 'file' => $e->getFile(), + 'line' => $e->getLine(), + 'kind' => get_class($e), + 'message' => $e->getMessage(), + ], + ] + ); } } $end = makeDate(); - $this->logger->notice('SYSTEM: Finished Sending change play state requests.', [ - 'context' => [ - 'total' => $total, - 'time' => [ - 'start' => $start, - 'end' => $end, - 'duration' => $end->getTimestamp() - $start->getTimestamp(), - ], + $this->logger->notice('SYSTEM: Sent [%(total)] change play state requests.', [ + 'total' => $total, + 'time' => [ + 'start' => $start, + 'end' => $end, + 'duration' => $end->getTimestamp() - $start->getTimestamp(), ], ]); + + $this->logger->info(sprintf('Using WatchState Version - \'%s\'.', getAppVersion())); } else { $this->logger->notice('SYSTEM: No play state changes detected.'); }