33 lines
861 B
PHP
33 lines
861 B
PHP
<?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;
|
|||
|
|
}
|
|||
|
|
}
|