info('Starting DNS monitoring...'); $query = DnsRecord::with('site')->where('is_active', true); // Filter by specific DNS record if ($dnsRecordId = $this->option('dns-record')) { $query->where('id', $dnsRecordId); } // Filter by site if ($siteId = $this->option('site')) { $query->where('site_id', $siteId); } $dnsRecords = $query->get(); if ($dnsRecords->isEmpty()) { $this->warn('No active DNS records found.'); return self::SUCCESS; } $this->info("Found {$dnsRecords->count()} active DNS record(s)."); $bar = $this->output->createProgressBar($dnsRecords->count()); $bar->start(); $dispatched = 0; $errors = 0; foreach ($dnsRecords as $dnsRecord) { try { if ($this->option('sync')) { // Run synchronously CheckDnsRecord::dispatchSync($dnsRecord); $this->newLine(); $this->line(" ✓ Checked: {$dnsRecord->site->name} - {$dnsRecord->record_type} {$dnsRecord->domain}"); } else { // Queue the job CheckDnsRecord::dispatch($dnsRecord); } $dispatched++; } catch (\Exception $e) { $errors++; $this->newLine(); $this->error(" ✗ Error checking {$dnsRecord->domain}: {$e->getMessage()}"); } $bar->advance(); } $bar->finish(); $this->newLine(2); // Summary $this->info("DNS monitoring completed!"); $this->table( ['Metric', 'Count'], [ ['Total DNS Records', $dnsRecords->count()], ['Successfully Dispatched', $dispatched], ['Errors', $errors], ] ); if (!$this->option('sync')) { $this->comment('Jobs have been queued. Run the queue worker to process them.'); } return self::SUCCESS; } }