lots of progress

This commit is contained in:
2025-01-26 21:36:05 +02:00
parent bbd082fd8f
commit 6a014c403c
44 changed files with 976 additions and 104 deletions
@@ -45,18 +45,9 @@ class FetchItemDataCommand extends Command
private function getBatch(string $type, int $batch, string $job)
{
return ItemToFetch::has('jobs')
->with([
// 'jobs' => fn ($jobs) => dd($jobs->first()->remaining_jobs) /*array_search($job, $jobs->first()->remaining_jobs, true)*/,
'jobs' => function ($jobs) use ($job) {
$remainingJobs = $jobs->first()->remaining_jobs;
if (is_string($remainingJobs)) {
$remainingJobs = json_decode($jobs->first()->remaining_jobs, true);
}
return array_search($job, $remainingJobs, true);
},
])
return ItemToFetch::whereHas('jobs', function($query) use ($job){
return $query->where('jobs', '<>', null)->whereRaw('FIND_IN_SET(?, jobs)', [$job]);
})->with(['jobs'])
->where('type', $type)
->take($batch)
->get();
@@ -57,6 +57,7 @@ class FetchUpcomingMoviesCommand extends Command
$oldUpcomingIds = UpcomingMovie::all()->pluck('movie_id');
foreach ($upcomingMovies['results'] as $upcomingMovie) {
echo ".";
$movie = $this->process($upcomingMovie);
if ($movie) {
@@ -69,11 +70,13 @@ class FetchUpcomingMoviesCommand extends Command
if (!empty($newUpcomingIds)) {
UpcomingMovie::whereIn('id', $oldUpcomingIds)->delete();
UpcomingMovie::insert($newUpcomingIds);
echo "+";
}
DB::commit();
} catch (\Throwable $e) {
DB::rollBack();
dump($e);
}
}
@@ -86,14 +89,14 @@ class FetchUpcomingMoviesCommand extends Command
return $movie;
}
$itemToFetch = ItemToFetch::where('tmdb_id', $upcomingMovie['id'])->where('type', $type)->first();
$itemToFetch = ItemToFetch::where('tmdb_id', $upcomingMovie['id'])->where('type', ItemToFetch::TYPE_MOVIE)->first();
if ($itemToFetch) {
$this->movieProcessingService->process($itemToFetch, ItemToFetchJobs::JOB_DETAILS);
return Movie::where('tmdb_id', $upcomingMovie['id'])->first();
}
ItemToFetch::create([
$itemToFetch = ItemToFetch::create([
'tmdb_id' => $upcomingMovie['id'],
'type' => ItemToFetch::TYPE_MOVIE,
]);
@@ -107,6 +110,7 @@ class FetchUpcomingMoviesCommand extends Command
'remaining_jobs' => json_encode($jobs),
]);
return null;
$this->movieProcessingService->process($itemToFetch, ItemToFetchJobs::JOB_DETAILS);
return Movie::where('tmdb_id', $upcomingMovie['id'])->first();
}
}