Updated state:push log messages to reflect the changes to the underlying structure.

This commit is contained in:
Abdulmhsen B. A. A
2022-06-09 18:50:23 +03:00
parent f3226db8e5
commit 6adee3cf79
2 changed files with 34 additions and 48 deletions

View File

@@ -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;
}

View File

@@ -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.');
}