Files
Discount-Bandit/routes/console.php
T
YNWA Fawzy 49b03c2e79 Features:
- single time url with notification, where user can see the prices of other products and can check the trend of prices without logging in, each url is valid for 15 minutes only and has a unique value.
- filter to get products that are lowest within x days.
- add canadian tire store, Target

Fixes:
- change limit from 300 products to 60 every 5 minutes.
- fix best buy crawling single product
- fix best buy url is not viewable
- error when getting variation for best buy
- remove fnac from deployment, as they block after 2-3 tries everytime.

Took 11 hours 35 minutes
2024-10-03 23:55:59 +04:00

45 lines
1.3 KiB
PHP

<?php
use App\Console\Commands\ClearNotificationCount;
use App\Enums\StatusEnum;
use App\Jobs\CrawlProductJob;
use App\Models\ProductStore;
use App\Models\Store;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schedule;
use Spatie\Health\Commands\ScheduleCheckHeartbeatCommand;
Schedule::call(function () {
try {
DB::table('jobs')->truncate();
Log::info("Products Schedule Started");
$stores= Store::with([
"product_stores"=>function($query){
$query->orderBy("updated_at")->limit(60);
}])
->whereHas('product_stores')
->where('status', StatusEnum::Published)
->get();
foreach ($stores as $store)
foreach ($store->product_stores as $index=>$product_store){
CrawlProductJob::dispatch($product_store->id)
->onQueue($product_store->store->slug)
->delay( now()->addSeconds($index * 5));
}
Log::info("Products Schedule Finished Successfully");
}
catch (Exception $e) {
Log::error("Couldn't Run the Product Schedule, Error: \n" . $e);
}
})->everyFiveMinutes();
Schedule::command(ClearNotificationCount::class)->dailyAt("23:59");
Schedule::command(ScheduleCheckHeartbeatCommand::class)->everyMinute();