Files
ismysiteup.online/app/Console/Commands/MonitorSslCommand.php
T
2026-01-17 13:46:20 +02:00

65 lines
1.7 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\CheckSslCertificate;
use App\Models\Site;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Bus;
class MonitorSslCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'monitor:ssl';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check SSL certificates for all enabled sites';
/**
* Execute the console command.
*/
public function handle()
{
$this->info('Starting SSL certificate monitoring...');
// Fetch all sites with monitoring enabled
$sites = Site::where('monitoring_enabled', true)->get();
if ($sites->isEmpty()) {
$this->warn('No enabled sites found for SSL monitoring.');
return Command::SUCCESS;
}
$this->info("Found {$sites->count()} enabled site(s) for SSL monitoring.");
// Create a batch of jobs to dispatch in parallel
$jobs = $sites->map(function (Site $site) {
return new CheckSslCertificate($site);
});
// Dispatch jobs using Laravel's bus with batch processing
Bus::chain([
function () use ($jobs) {
Bus::batch($jobs->toArray())
->name('SSL Certificate Monitoring')
->allowFailures()
->onQueue('monitoring')
->dispatch();
}
])->dispatch();
$this->info("Dispatched {$jobs->count()} SSL certificate check job(s).");
$this->comment('Jobs are being processed in the queue...');
return Command::SUCCESS;
}
}