info('Waiting '. $this->nextMinute(). ' for next run of scheduler'); sleep($this->nextMinute()); $this->runScheduler(); } /** * Main recurring loop function. * Runs the scheduler every minute. * If the --queue flag is provided it will run the scheduler as a queue job. * Prevents overruns of cron jobs but does mean you need to have capacity to run the scheduler * in your queue within 60 seconds. * */ protected function runScheduler() { $fn = $this->option('queue') ? 'queue' : 'call'; $this->info('Running scheduler'); Artisan::$fn('schedule:run'); $this->info('completed, sleeping..'); sleep($this->nextMinute()); $this->runScheduler(); } /** * Works out seconds until the next minute starts; * * @return int */ protected function nextMinute() { $current = Carbon::now(); return 60 -$current->second; } }