Laravel Beanstalkd Queuing Service Exception Handling

Beanstalkd was first developed to solve the needs of a popular web application (Causes on Facebook). Currently, it is an absolutely reliable, easy to install messaging service which is perfect to get started with and use. Reference this posts Production-Ready Beanstalkd with Laravel Queues to deploy queue service with beanstalkd.

Here we use to make the process of monitoring Supervisor. Task in the queue will be some exception in some cases, to avoid infinite loop on exception we need to travel Laravel how many times to try a specific job, before deciding it has failed

$ php artisan queue:listen --tries=3

This way, it will stop processing that specific job after 3 tries. If you're using Supervisor, edit config file in /etc/supervisor/conf.d/ floder. Laravel use failed_jobs to record failed jobs in queue, to populate failed_jobs table, we need do migrate create table.

$ php artisan queue:failed-table

This creates the necessary migration. Then do

$ php artisan migrate

to get table created in your database.

mysql> show columns from my_failed_jobs;
+------------+------------------+------+-----+---------------------+----------------+
| Field      | Type             | Null | Key | Default             | Extra          |
+------------+------------------+------+-----+---------------------+----------------+
| id         | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| connection | text             | NO   |     | NULL                |                |
| queue      | text             | NO   |     | NULL                |                |
| payload    | text             | NO   |     | NULL                |                |
| failed_at  | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
+------------+------------------+------+-----+---------------------+----------------+
5 rows in set (0.00 sec)

mysql> 

Show all filed jobs

mysql> select * from my_failed_jobs;

Laravel Beanstalkd Queuing Service Exception Handling

Retry ID 2 failed job

$ php artisan queue:retry 2
The failed job has been pushed back onto the queue!
Laravel Beanstalkd Queuing Service Exception Handling
32 votes, 4.61 avg. rating (92% score)