Files
services_core/app/Console/Commands/CheckMikrotikConnections.php
T
2026-08-07 09:16:13 +07:00

34 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\NasMikrotik;
use App\Jobs\CheckMikrotikConnection;
use Illuminate\Console\Command;
class CheckMikrotikConnections extends Command
{
protected $signature = 'nas:check-mikrotiks {--id=* : ID Mikrotik tertentu}';
protected $description = 'Mengantrekan pemeriksaan koneksi NAS yang sudah jatuh tempo';
public function handle(): int
{
$queued = 0;
NasMikrotik::query()
->where('status', 'active')
->where(fn ($query) => $query->whereNull('next_health_check_at')->orWhere('next_health_check_at', '<=', now()))
->when($this->option('id'), fn ($query) => $query->whereIn('id', $this->option('id')))
->select(['id'])
->chunkById(100, function ($devices) use (&$queued) {
foreach ($devices as $index => $device) {
CheckMikrotikConnection::dispatch($device->id)->delay(now()->addSeconds($index % 60));
$queued++;
}
});
$this->info("{$queued} pemeriksaan NAS masuk antrean nas-health.");
return self::SUCCESS;
}
}