A Laravel package to manage multiple queue workers similar to Horizon, with memory monitoring and graceful shutdown
randika-srimal/queue-manager is a Laravel package for a laravel package to manage multiple queue workers similar to horizon, with memory monitoring and graceful shutdown.
It currently has 1 GitHub stars and 78 downloads on Packagist (latest version 1.0.1).
Install it with composer require randika-srimal/queue-manager.
Discover more Laravel packages by randika-srimal
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package to manage multiple queue workers similar to Horizon, with memory monitoring and graceful shutdown capabilities. This package allows you to run multiple queue workers with different configurations from a single command.
Install the package via Composer:
composer require randika-srimal/queue-manager
If you're developing this package locally, add it to your Laravel project's composer.json:
{
"repositories": [
{
"type": "path",
"url": "./packages/queue-manager"
}
],
"require": {
"randika-srimal/queue-manager": "@dev"
}
}
Then run:
composer update randika-srimal/queue-manager
Publish the configuration file:
php artisan vendor:publish --tag=queue-manager-config
This will create config/queue-manager.php in your Laravel project. Edit this file to configure your workers:
<?php
return [
'workers' => [
[
'connection' => 'database',
'queue' => 'default',
'processes' => 3,
'memory' => 128, // Maximum memory in MB before restart
'timeout' => 60, // Maximum execution time per job in seconds
'sleep' => 3, // Seconds to sleep when no jobs available
'tries' => 3, // Number of times to attempt a job
],
[
'connection' => 'redis',
'queue' => 'high-priority,default',
'processes' => 5,
'memory' => 256,
'timeout' => 60,
'sleep' => 1,
'tries' => 3,
],
],
'memory_check_interval' => 30, // How often to check memory (seconds)
'restart_delay' => 2, // Delay before restarting a worker (seconds)
];
Start the queue manager:
php artisan queue:manage
--no-restart - Disable automatic restart of failed workersphp artisan queue:manage --no-restart
Press Ctrl+C to gracefully shutdown all workers. The manager will:
'workers' => [
[
'connection' => 'database',
'queue' => 'default',
'processes' => 3,
'memory' => 128,
'timeout' => 60,
'sleep' => 3,
'tries' => 3,
],
[
'connection' => 'database',
'queue' => 'emails',
'processes' => 2,
'memory' => 128,
'timeout' => 120,
'sleep' => 5,
'tries' => 2,
],
],
'workers' => [
[
'connection' => 'redis',
'queue' => 'high-priority,default,low-priority',
'processes' => 5,
'memory' => 256,
'timeout' => 60,
'sleep' => 1,
'tries' => 3,
],
],
For production environments, it's recommended to run the queue manager under a process supervisor like systemd or Supervisor.
Create /etc/systemd/system/queue-manager.service:
[Unit]
Description=Laravel Queue Manager
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/html
ExecStart=/usr/bin/php /var/www/html/artisan queue:manage
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl enable queue-manager
sudo systemctl start queue-manager
Create /etc/supervisor/conf.d/queue-manager.conf:
[program:queue-manager]
process_name=%(program_name)s
command=php /var/www/html/artisan queue:manage
autostart=true
autorestart=true
user=www-data
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/queue-manager.log
Update and start:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start queue-manager
The MIT License (MIT). Please see License File for more information.
Inspired by Laravel Horizon's process management capabilities.