where('status', 'active')->where('trigger_type', 'schedule')->whereNotNull('next_run_at')->where('next_run_at', '<=', now())->chunkById(100, function ($items) use ($runner, &$count) { foreach ($items as $automation) { $runner->dispatch($automation, ['scheduled_at' => now()->toIso8601String()], 'schedule'); $interval = max(1, (int) ($automation->trigger_config['interval_minutes'] ?? 60)); $automation->update(['next_run_at' => now()->addMinutes($interval)]); $count++; } }); $this->info("Dispatched {$count} scheduled automation(s)."); return self::SUCCESS; } }