Created
August 16, 2019 01:51
-
-
Save franciscotis/eed59801d5086ce781541de9495b8c17 to your computer and use it in GitHub Desktop.
Kernel2.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console; | |
use Illuminate\Console\Scheduling\Schedule; | |
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | |
class Kernel extends ConsoleKernel | |
{ | |
protected $queues = [ | |
'notifications', | |
'default', | |
]; | |
/** | |
* The Artisan commands provided by your application. | |
* | |
* @var array | |
*/ | |
protected $commands = [ | |
// | |
]; | |
/** | |
* Define the application's command schedule. | |
* | |
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |
* @return void | |
*/ | |
protected function schedule(Schedule $schedule) | |
{ | |
// run the queue worker "without overlapping" | |
// this will only start a new worker if the previous one has died | |
$schedule->command($this->getQueueCommand()) | |
->withoutOverlapping(60) | |
->everyMinute(); | |
// restart the queue worker periodically to prevent memory issues | |
$schedule->command('queue:restart') | |
->hourly(); | |
} | |
protected function getQueueCommand() | |
{ | |
// build the queue command | |
$params = implode(' ',[ | |
'--daemon', | |
'--tries=3', | |
'--sleep=3', | |
'--queue='.implode(',',$this->queues), | |
]); | |
return sprintf('queue:work %s', $params); | |
} | |
/** | |
* Register the commands for the application. | |
* | |
* @return void | |
*/ | |
protected function commands() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment