From ea1f4e8c836f036f38affbdb3e26a35c7706c117 Mon Sep 17 00:00:00 2001 From: Lee Peuker Date: Tue, 16 Aug 2022 19:36:35 +0200 Subject: [PATCH] Add imdb job type --- src/Command/ImdbSync.php | 7 ++++++- src/HttpController/SettingsController.php | 1 + src/ValueObject/JobType.php | 8 ++++++++ src/Worker/Repository.php | 2 +- src/Worker/Service.php | 10 ++++++++++ templates/page/job-queue.html.twig | 4 ++-- templates/page/settings-app.html.twig | 3 ++- 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Command/ImdbSync.php b/src/Command/ImdbSync.php index 135f7fa9..21a2c8e0 100644 --- a/src/Command/ImdbSync.php +++ b/src/Command/ImdbSync.php @@ -3,6 +3,8 @@ namespace Movary\Command; use Movary\Application\Service\Imdb\SyncMovies; +use Movary\ValueObject\JobStatus; +use Movary\Worker\Service; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -18,7 +20,8 @@ class ImdbSync extends Command public function __construct( private readonly SyncMovies $syncMovieDetails, - private readonly LoggerInterface $logger + private readonly Service $workerService, + private readonly LoggerInterface $logger, ) { parent::__construct(); } @@ -44,6 +47,8 @@ protected function execute(InputInterface $input, OutputInterface $output) : int $this->syncMovieDetails->syncMovies($maxAgeInHours, $movieCountSyncThreshold); + $this->workerService->addImdbSyncJob(JobStatus::createDone()); + $this->generateOutput($output, 'Syncing imdb movie ratings done.'); } catch (\Throwable $t) { $this->generateOutput($output, 'ERROR: Could not complete imdb sync.'); diff --git a/src/HttpController/SettingsController.php b/src/HttpController/SettingsController.php index 7d50ec2d..65bdc792 100644 --- a/src/HttpController/SettingsController.php +++ b/src/HttpController/SettingsController.php @@ -159,6 +159,7 @@ public function renderAppPage() : Response $this->twig->render('page/settings-app.html.twig', [ 'applicationVersion' => $this->applicationVersion ?? '-', 'lastSyncTmdb' => $this->workerService->findLastTmdbSync() ?? '-', + 'lastSyncImdb' => $this->workerService->findLastImdbSync() ?? '-', ]), ); } diff --git a/src/ValueObject/JobType.php b/src/ValueObject/JobType.php index 0e2e71e2..2b0a251f 100644 --- a/src/ValueObject/JobType.php +++ b/src/ValueObject/JobType.php @@ -4,6 +4,8 @@ class JobType { + private const TYPE_IMDB_SYNC = 'imdb_sync'; + private const TYPE_LETTERBOXD_IMPORT_HISTORY = 'letterboxd_import_history'; private const TYPE_LETTERBOXD_IMPORT_RATINGS = 'letterboxd_import_ratings'; @@ -22,6 +24,7 @@ private function __construct(private readonly string $type) self::TYPE_TMDB_SYNC, self::TYPE_TRAKT_IMPORT_HISTORY, self::TYPE_TRAKT_IMPORT_RATINGS, + self::TYPE_IMDB_SYNC, ]) === false) { throw new \RuntimeException('Not supported job type: ' . $this->type); } @@ -32,6 +35,11 @@ public static function createFromString(string $status) : self return new self($status); } + public static function createImdbSync() : self + { + return new self(self::TYPE_IMDB_SYNC); + } + public static function createLetterboxdImportHistory() : self { return new self(self::TYPE_LETTERBOXD_IMPORT_HISTORY); diff --git a/src/Worker/Repository.php b/src/Worker/Repository.php index f4f8ce9b..e31fa116 100644 --- a/src/Worker/Repository.php +++ b/src/Worker/Repository.php @@ -31,7 +31,7 @@ public function addJob(JobType $type, JobStatus $status, ?int $userId = null, ?a public function fetchJobs(int $userId) : JobList { - $data = $this->dbConnection->fetchAllAssociative('SELECT * FROM `job_queue` WHERE user_id = ? OR user_id IS NULL ORDER BY created_at DESC, id DESC LIMIT 20', [$userId]); + $data = $this->dbConnection->fetchAllAssociative('SELECT * FROM `job_queue` WHERE user_id = ? OR user_id IS NULL ORDER BY created_at DESC, id DESC LIMIT 30', [$userId]); return JobList::createFromArray($data); } diff --git a/src/Worker/Service.php b/src/Worker/Service.php index 12087be6..5d152655 100644 --- a/src/Worker/Service.php +++ b/src/Worker/Service.php @@ -39,6 +39,11 @@ public function addTmdbSyncJob(JobStatus $jobStatus) : void $this->repository->addJob(JobType::createTmdbSync(), $jobStatus); } + public function addImdbSyncJob(JobStatus $jobStatus) : void + { + $this->repository->addJob(JobType::createImdbSync(), $jobStatus); + } + public function addTraktImportHistoryJob(int $userId, ?JobStatus $jobStatus = null) : void { $this->repository->addJob(JobType::createTraktImportHistory(), $jobStatus ?? JobStatus::createWaiting(), $userId); @@ -72,6 +77,11 @@ public function fetchJobsForStatusPage(int $userId) : array return $jobsData; } + public function findLastImdbSync() : ?DateTime + { + return $this->repository->findLastDateForJobByType(JobType::createImdbSync()); + } + public function findLastTmdbSync() : ?DateTime { return $this->repository->findLastDateForJobByType(JobType::createTmdbSync()); diff --git a/templates/page/job-queue.html.twig b/templates/page/job-queue.html.twig index 45c68212..de88a5b1 100644 --- a/templates/page/job-queue.html.twig +++ b/templates/page/job-queue.html.twig @@ -9,8 +9,8 @@ {{ include('component/navbar.html.twig') }}
-

Last 20 Jobs:

-
+

Last 30 Jobs:

+
diff --git a/templates/page/settings-app.html.twig b/templates/page/settings-app.html.twig index 77f313f5..b0a201b3 100644 --- a/templates/page/settings-app.html.twig +++ b/templates/page/settings-app.html.twig @@ -12,7 +12,8 @@ {{ include('component/settings-nav.html.twig') }}
-

Last tmdb sync: {{ lastSyncTmdb }}

+

Last TMDB sync: {{ lastSyncTmdb }}

+

Last IMDb sync: {{ lastSyncImdb }}

Application version: {{ applicationVersion }}