command('queue:flush') ->daily(); // Restart processing queued jobs (just in case) $schedule->command('queue:restart') ->hourly(); $schedule->command('freescout:fetch-monitor') ->everyMinute() ->withoutOverlapping(); // Fetch emails from mailboxes $schedule->command('freescout:fetch-emails') ->everyMinute() ->withoutOverlapping() ->sendOutputTo(storage_path().'/logs/fetch-emails.log'); // Command runs as subprocess and sets cache mutex. If schedule:run command is killed // subprocess does not clear the mutex and it stays in the cache until cache:clear is executed. // By default, the lock will expire after 24 hours. // // cache:clear clears the mutex, but sometimes process continues running, so we need to kill it. if (function_exists('shell_exec')) { $running_commands = 0; try { $processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep 'queue:work'")); foreach ($processes as $process) { preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m); if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) { $running_commands++; } } } catch (\Exception $e) { // Do nothing } if ($running_commands > 1) { // queue:work command is stopped by settings a cache key \Cache::forever('illuminate:queue:restart', Carbon::now()->getTimestamp()); } } $schedule->command('queue:work', Config('app.queue_work_params')) ->everyMinute() ->withoutOverlapping() ->sendOutputTo(storage_path().'/logs/queue-jobs.log'); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }