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; } }