Video size is handled by the queue job.
This commit is contained in:
@@ -18,7 +18,7 @@ DB_PASSWORD=
|
|||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=file
|
CACHE_DRIVER=file
|
||||||
FILESYSTEM_DISK=local
|
FILESYSTEM_DISK=local
|
||||||
QUEUE_CONNECTION=sync
|
QUEUE_CONNECTION=database
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\SymfonyCastDl;
|
namespace App\Http\SymfonyCastDl;
|
||||||
|
|
||||||
|
use App\Jobs\GetVideoFileSize;
|
||||||
use App\Models\Chapter;
|
use App\Models\Chapter;
|
||||||
use App\Models\Course;
|
use App\Models\Course;
|
||||||
use GuzzleHttp\TransferStats;
|
use GuzzleHttp\TransferStats;
|
||||||
@@ -40,14 +41,13 @@ class SymfonyCastDlService
|
|||||||
$coursePage = $this->client->get('courses/filtering');
|
$coursePage = $this->client->get('courses/filtering');
|
||||||
|
|
||||||
$courses = $this->htmlParser->getCourses($coursePage);
|
$courses = $this->htmlParser->getCourses($coursePage);
|
||||||
$courses->each(fn($course) => $course->save());
|
$courses->each->save();
|
||||||
// $singleCoursePage = $this->client->get($courses[3]->link);
|
|
||||||
/** @var Course $course */
|
/** @var Course $course */
|
||||||
foreach ($courses as $course) {
|
foreach ($courses as $course) {
|
||||||
$singleCoursePage = $this->client->get($course->link);
|
$singleCoursePage = $this->client->get($course->link);
|
||||||
$chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id);
|
$chapters = $this->htmlParser->getCourseDetails($singleCoursePage, $course->id);
|
||||||
// $chapters->each(fn($chapter) => $this->videoSize($chapter)->save());
|
$chapters->each->save();
|
||||||
$chapters->each(fn($chapter) => $chapter->save());
|
$chapters->each(fn($chapter) => GetVideoFileSize::dispatch($chapter->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
app/Jobs/GetVideoFileSize.php
Normal file
36
app/Jobs/GetVideoFileSize.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Http\SymfonyCastDl\HtmlParser;
|
||||||
|
use App\Http\SymfonyCastDl\SymfonyCastDlService;
|
||||||
|
use App\Models\Chapter;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class GetVideoFileSize implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(private int $chapterId)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function handle(HtmlParser $htmlParser)
|
||||||
|
{
|
||||||
|
|
||||||
|
// $this->
|
||||||
|
// $this->videoSize($this->chapter);
|
||||||
|
// $this->chapter->save();
|
||||||
|
$service = new SymfonyCastDlService($htmlParser);
|
||||||
|
$service->videoSize(Chapter::find($this->chapterId));
|
||||||
|
|
||||||
|
// dd($this->chapterId);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
database/migrations/2022_09_16_054545_create_jobs_table.php
Normal file
36
database/migrations/2022_09_16_054545_create_jobs_table.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('jobs', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||||
|
$table->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');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user