-
-
Save stevenwaskey/901aac71ec05a111651b1543c49ca152 to your computer and use it in GitHub Desktop.
Find any running "queue:listen" processes for a Laravel project and kill those. Fire "php artisan queue:stop" in your "current" project root. Intended to use with a deploy script when you are using non-daemon listeners and deploy releases. If you are using daemons, run "queue:restart" instead. You can use a process monitoring tool like Superviso…
This file contains 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 App\Console\Commands\StopQueueListeners; | |
use Illuminate\Console\Scheduling\Schedule; | |
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; | |
class Kernel extends ConsoleKernel | |
{ | |
/** | |
* The Artisan commands provided by your application. | |
* | |
* @var array | |
*/ | |
protected $commands = [ | |
StopQueueListeners::class, | |
]; | |
/** | |
* Define the application's command schedule. | |
* | |
* @param \Illuminate\Console\Scheduling\Schedule $schedule | |
* | |
* @return void | |
*/ | |
protected function schedule(Schedule $schedule) | |
{ | |
// | |
} | |
} |
This file contains 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\Commands; | |
use Illuminate\Console\Command; | |
class StopQueueListeners extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'queue:stop'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Kill the queue:listen processes for this project.'; | |
/** | |
* Create a new command instance. | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$pids = $this->getQueueListenerPids(); | |
if (count($pids) === 0) { | |
$this->info('No queue listeners are currently running.'); | |
return; | |
} | |
$this->stopQueueListeners($pids); | |
$this->info('All done.'); | |
} | |
/** | |
* Get the PID's of queue listeners for the current project. | |
* | |
* @return array | |
*/ | |
private function getQueueListenerPids() | |
{ | |
$command = 'ps -u forge -eo pid,user,command | grep $(pwd) | grep "queue:listen" | grep -v grep | awk \'{print $1}\''; | |
exec($command, $pids); | |
return (array) $pids; | |
} | |
/** | |
* Kill queue listener processes. | |
* | |
* @param array $pids | |
* | |
* @return void | |
*/ | |
private function stopQueueListeners(array $pids) | |
{ | |
foreach ($pids as $pid) { | |
$this->info('Killing queue listener with PID #' . $pid); | |
exec('kill -TERM ' . $pid); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment