Skip to content

Commit

Permalink
🧭 Optimze download video job
Browse files Browse the repository at this point in the history
  • Loading branch information
ellermister committed Sep 5, 2024
1 parent b3cae57 commit 9c123b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/Jobs/DownloadVideoJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function updateVideoStatus()
$savePath = sprintf('%s/%s.mp4', $videoPath, $this->vInfo['id']);
if (is_file($savePath)) {
redis()->hSet('video_downloaded', $this->vInfo['id'], 1);
}else{
redis()->hDel('video_downloaded', $this->vInfo['id']);
}
}
}
9 changes: 9 additions & 0 deletions app/Jobs/UpdateFavListJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Jobs;

use App\Console\Commands\DownloadVideo;
use Arr;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Log;

class UpdateFavListJob implements ShouldQueue
{
Expand Down Expand Up @@ -141,6 +143,13 @@ public function pullFavList($id)

foreach ($favList as $video) {
redis()->set(sprintf('video:%d', $video['id']), json_encode($video, JSON_UNESCAPED_UNICODE));

$exist = redis()->hGet('video_downloaded', $video['id']);
if(!$exist && !video_has_invalid($video)){
Log::info(sprintf('create download video job: %s', $video['title']));
$job = new DownloadVideoJob($video);
dispatch($job);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

Schedule::call(function () {
Artisan::call('app:update-fav');
})->hourly()->onSuccess(function () {
Artisan::call('app:download-video');
});
})->everyFiveMinutes();

0 comments on commit 9c123b9

Please sign in to comment.