info('Starting uptime monitoring...'); // Fetch all sites with monitoring enabled $sites = Site::where('monitoring_enabled', true)->get(); if ($sites->isEmpty()) { $this->warn('No enabled sites found for monitoring.'); return Command::SUCCESS; } $this->info("Found {$sites->count()} enabled site(s) to monitor."); // Create a batch of jobs to dispatch in parallel $jobs = $sites->map(function (Site $site) { return new CheckUptime($site); }); // Dispatch jobs using Laravel's bus with concurrency limit Bus::chain([ function () use ($jobs) { // Using bus batch for parallel processing Bus::batch($jobs->toArray()) ->name('Uptime Monitoring') ->allowFailures() ->onQueue('monitoring') ->dispatch(); } ])->dispatch(); $this->info("Dispatched {$jobs->count()} uptime check job(s)."); $this->comment('Jobs are being processed in the queue...'); return Command::SUCCESS; } }