where('is_paused', false) ->where('is_deleted', false) ->whereNotNull('next_run') ->where('next_run', '<=', now()) ->cursor() ->each(function ($scheduler) { nlog("Doing job ::{$scheduler->id}:: {$scheduler->name}"); try { //@var \App\Models\Schedule $scheduler $scheduler->service()->runTask(); } catch(\Exception $e) { nlog("Exception:: TaskScheduler:: Doing job :: {$scheduler->id} :: {$scheduler->name}" . $e->getMessage()); } }); return; } foreach (MultiDB::$dbs as $db) { MultiDB::setDB($db); Scheduler::with('company') ->where('is_paused', false) ->where('is_deleted', false) ->whereNotNull('next_run') ->where('next_run', '<=', now()) ->cursor() ->each(function ($scheduler) { nlog("Doing job ::{$scheduler->id}:: {$scheduler->name}"); try { /** @var \App\Models\Scheduler $scheduler */ $scheduler->service()->runTask(); } catch(\Exception $e) { nlog("Exception:: TaskScheduler:: #{$scheduler->id}::" . $e->getMessage()); nlog($e->getMessage()); } }); } } }