fix price force refresh 2
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\LivePriceTickService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* حلقه بینهایت — برای supervisor: php artisan prices:tick-daemon
|
||||
*/
|
||||
class PriceTickDaemonCommand extends Command
|
||||
{
|
||||
protected $signature = 'prices:tick-daemon {--interval=10}';
|
||||
|
||||
protected $description = 'Continuously refresh montzar/zaarbox/products every N seconds (supervisor)';
|
||||
|
||||
public function handle(LivePriceTickService $tickService): int
|
||||
{
|
||||
$interval = max(1, (int) $this->option('interval'));
|
||||
|
||||
$this->info("Price tick daemon started (every {$interval}s). Ctrl+C to stop.");
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$tickService->tick();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('prices:tick-daemon failed', [
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
sleep($interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\LivePriceTickService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* هر دقیقه ۶ بار prices:tick — برای schedule:run (فاصله ۱۰ ثانیه).
|
||||
*/
|
||||
class PriceTickLoopCommand extends Command
|
||||
{
|
||||
protected $signature = 'prices:tick-loop {--iterations=6} {--interval=10}';
|
||||
|
||||
protected $description = 'Run prices:tick several times per minute (default: 6× every 10s)';
|
||||
|
||||
public function handle(LivePriceTickService $tickService): int
|
||||
{
|
||||
$iterations = max(1, (int) $this->option('iterations'));
|
||||
$interval = max(1, (int) $this->option('interval'));
|
||||
|
||||
for ($i = 0; $i < $iterations; $i++) {
|
||||
$tickService->tick();
|
||||
|
||||
if ($i < $iterations - 1) {
|
||||
sleep($interval);
|
||||
}
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,12 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// تیک قیمت — هر ۱۰ ثانیه (۶ بار در دقیقه)
|
||||
$schedule->call(function () {
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
\Illuminate\Support\Facades\Artisan::call('prices:tick');
|
||||
if ($i < 5) {
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
})->everyMinute()->name('prices_tick_10s')->withoutOverlapping();
|
||||
// تیک قیمت — ۶ بار در دقیقه با فاصله ۱۰ ثانیه (montzar + zaarbox + محصولات)
|
||||
// نیاز: * * * * * php artisan schedule:run
|
||||
$schedule->command('prices:tick-loop --iterations=6 --interval=10')
|
||||
->everyMinute()
|
||||
->name('prices_tick_10s')
|
||||
->withoutOverlapping(58);
|
||||
|
||||
$schedule->command('prices:refresh-zaarbox')
|
||||
->everyThirtyMinutes()
|
||||
|
||||
Reference in New Issue
Block a user