From c5f4a8ed2dcb22a527c60ae1c3ca7cd579993648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20P=C5=82aczek?= Date: Fri, 16 Sep 2022 10:52:50 +0200 Subject: [PATCH] Video size is handled by the queue job. --- .env.example | 2 +- .../SymfonyCastDl/SymfonyCastDlService.php | 8 ++--- app/Jobs/GetVideoFileSize.php | 36 +++++++++++++++++++ .../2022_09_16_054545_create_jobs_table.php | 36 +++++++++++++++++++ ..._09_16_062657_create_failed_jobs_table.php | 36 +++++++++++++++++++ 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 app/Jobs/GetVideoFileSize.php create mode 100644 database/migrations/2022_09_16_054545_create_jobs_table.php create mode 100644 database/migrations/2022_09_16_062657_create_failed_jobs_table.php diff --git a/.env.example b/.env.example index 2f5011e..a99da48 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,7 @@ DB_PASSWORD= BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local -QUEUE_CONNECTION=sync +QUEUE_CONNECTION=database SESSION_DRIVER=file SESSION_LIFETIME=120 diff --git a/app/Http/SymfonyCastDl/SymfonyCastDlService.php b/app/Http/SymfonyCastDl/SymfonyCastDlService.php index 8cb25f0..c13a34a 100644 --- a/app/Http/SymfonyCastDl/SymfonyCastDlService.php +++ b/app/Http/SymfonyCastDl/SymfonyCastDlService.php @@ -2,6 +2,7 @@ namespace App\Http\SymfonyCastDl; +use App\Jobs\GetVideoFileSize; use App\Models\Chapter; use App\Models\Course; use GuzzleHttp\TransferStats; @@ -40,14 +41,13 @@ class SymfonyCastDlService $coursePage = $this->client->get('courses/filtering'); $courses = $this->htmlParser->getCourses($coursePage); - $courses->each(fn($course) => $course->save()); -// $singleCoursePage = $this->client->get($courses[3]->link); + $courses->each->save(); /** @var Course $course */ foreach ($courses as $course) { $singleCoursePage = $this->client->get($course->link); $chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id); -// $chapters->each(fn($chapter) => $this->videoSize($chapter)->save()); - $chapters->each(fn($chapter) => $chapter->save()); + $chapters->each->save(); + $chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id)); } } diff --git a/app/Jobs/GetVideoFileSize.php b/app/Jobs/GetVideoFileSize.php new file mode 100644 index 0000000..b02559a --- /dev/null +++ b/app/Jobs/GetVideoFileSize.php @@ -0,0 +1,36 @@ + +// $this->videoSize($this->chapter); +// $this->chapter->save(); + $service = new SymfonyCastDlService($htmlParser); + $service->videoSize(Chapter::find($this->chapterId)); + +// dd($this->chapterId); + } +} diff --git a/database/migrations/2022_09_16_054545_create_jobs_table.php b/database/migrations/2022_09_16_054545_create_jobs_table.php new file mode 100644 index 0000000..a786a89 --- /dev/null +++ b/database/migrations/2022_09_16_054545_create_jobs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('jobs'); + } +}; diff --git a/database/migrations/2022_09_16_062657_create_failed_jobs_table.php b/database/migrations/2022_09_16_062657_create_failed_jobs_table.php new file mode 100644 index 0000000..1719198 --- /dev/null +++ b/database/migrations/2022_09_16_062657_create_failed_jobs_table.php @@ -0,0 +1,36 @@ +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. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('failed_jobs'); + } +};