Skip to content

Commit

Permalink
Merge pull request #100 from leepeuker/add-imdb-job-type
Browse files Browse the repository at this point in the history
Add imdb job type
  • Loading branch information
leepeuker authored Aug 16, 2022
2 parents bc87c24 + ea1f4e8 commit dbe196f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Command/ImdbSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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.');
Expand Down
1 change: 1 addition & 0 deletions src/HttpController/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? '-',
]),
);
}
Expand Down
8 changes: 8 additions & 0 deletions src/ValueObject/JobType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Worker/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Worker/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions templates/page/job-queue.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{{ include('component/navbar.html.twig') }}

<div style="padding-top: 1rem">
<p>Last 20 Jobs:</p>
<div style="text-align: center;">
<p>Last 30 Jobs:</p>
<div class="table-responsive" style="text-align: center;">
<table class="table">
<thead>
<tr>
Expand Down
3 changes: 2 additions & 1 deletion templates/page/settings-app.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{ include('component/settings-nav.html.twig') }}

<div style="padding-bottom: 1rem;padding-top: 1rem">
<p style="margin-bottom: 0.5rem">Last <a href="https://themoviedb.org/" target="_blank">tmdb</a> sync: <span class="fw-light">{{ lastSyncTmdb }}</span></p>
<p style="margin-bottom: 0.5rem">Last <a href="https://themoviedb.org/" target="_blank">TMDB</a> sync: <span class="fw-light">{{ lastSyncTmdb }}</span></p>
<p style="margin-bottom: 0.5rem">Last <a href="https://www.imdb.com/" target="_blank">IMDb</a> sync: <span class="fw-light">{{ lastSyncImdb }}</span></p>
<p><a href="https://github.com/leepeuker/movary/releases" target="_blank">Application</a> version: <span class="fw-light">{{ applicationVersion }}</span>
</p>
</div>
Expand Down

0 comments on commit dbe196f

Please sign in to comment.