From 66147227d976d386e21ed29380659bda7dd9cb5c Mon Sep 17 00:00:00 2001 From: Tim Slager Date: Mon, 22 Jan 2024 13:17:11 +0100 Subject: [PATCH] fix: Fixes job BEWARE: Please first review and push #37 before pushing this one. #37 has fixes that this pr depends on it. --- src/app/Jobs/ImportFromApiJob.php | 2 +- src/app/Traits/Imports/OpenLibraryTrait.php | 8 ++++- .../2024_01_22_120757_failed_jobs.php | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/database/migrations/2024_01_22_120757_failed_jobs.php diff --git a/src/app/Jobs/ImportFromApiJob.php b/src/app/Jobs/ImportFromApiJob.php index a4efddf..4a60bc4 100644 --- a/src/app/Jobs/ImportFromApiJob.php +++ b/src/app/Jobs/ImportFromApiJob.php @@ -41,7 +41,7 @@ public function handle(): void // replace with switch statement once more sources are added if ($this->source == ImportSources::OPEN_LIBRARY) { - $this->importOpenLibrary($this->query); + $this->importOpenLibrary(); } } } diff --git a/src/app/Traits/Imports/OpenLibraryTrait.php b/src/app/Traits/Imports/OpenLibraryTrait.php index f26d10c..a0cdd86 100644 --- a/src/app/Traits/Imports/OpenLibraryTrait.php +++ b/src/app/Traits/Imports/OpenLibraryTrait.php @@ -10,7 +10,13 @@ trait OpenLibraryTrait { use CommonLibraryTrait; - public function importOpenLibrary($tries = 3) { + + /** + * @param $tries int The amount of times the import should be tried. + * @return void Imports books from OpenLibrary. + */ + public function importOpenLibrary(int $tries = 3): void + { if ($tries < 1) $tries = 3; $maxOffset = (int) ceil(100 * $tries / 100) * 100; diff --git a/src/database/migrations/2024_01_22_120757_failed_jobs.php b/src/database/migrations/2024_01_22_120757_failed_jobs.php new file mode 100644 index 0000000..0285366 --- /dev/null +++ b/src/database/migrations/2024_01_22_120757_failed_jobs.php @@ -0,0 +1,32 @@ +id(); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('failed_jobs'); + } +};