Actually, when the queue fails, the failing event occurs, therefore, for example, you can register the failing event in your AppServiceProvider class in the boot method using something like this:
public function boot() { Queue::failing(function (JobFailed $event) {
Alternatively, you can declare a failed method in the handler class, for example:
class SendEmail extends Job implements ShouldQueue { use InteractsWithQueue, SerializesModels; public function handle(Mailer $mailer) {
Read the documentation .
As for background monitoring, you can use Supervisord :
Supervisor is a client-server system that allows its users to control and manage multiple processes on UNIX-like operating systems.
In this case, you must install it on your computer and configure it using at least one program section, for example:
[program:queue] command=/usr/local/bin/php artisan queue:listen --tries=3
This is an example of a program section that I used to monitor my queue with Supervisord . In this case, you need to read the documentation for supervisord to understand how to use it, I just gave you an idea, Supervisord will start in the background as soon as you start it, and it will also restart monitoring even after the server restarts (if it is on for some reason does not work), so you do not need to worry about it.
A simple (minimal) configuration file might look something like this:
[unix_http_server] file=/tmp/supervisor.sock ; (the path to the socket file) [supervisord] logfile=/home/someDirName/www/example.com/supervisord.log logfile_maxbytes=50MB logfile_backups=10 loglevel=info pidfile=/tmp/supervisord.pid nodaemon=false loglevel=warn [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock [program:queue] command=/usr/local/bin/php artisan queue:listen --tries=3 directory=/home/someDirName/www/example.com autostart=true autorestart=true redirect_stderr=true
Well, you can read the documentation to really get a clear idea about this. It can help you get started.