Search code examples
laravellaravel-queuelaravel-scheduler

Laravel Queues (Database driver) + Cron job (task scheduler) stacked and are not being sent anymore after server crashed


I have configured a laravel queue to send emails, and it used to work fine sending the emails immediately.

I also used laravel task scheduler and configured the queue:listen to be executed every minute, resulting in the server crashing because cron job was calling the queue:work loop over and over again.... The site crashed. And it was the live site of the client, so the issue is pretty serious.

The hosting company modified my laravel cron job to run every 5 minutes. And since it crashed, all mails now stay in the database and the database queue doesn't work at all. I guess the process is not running at all.

I have these questions:

  • How do I execute the stacked queue records in the database?
  • How do I make the database queues work again?
  • How configure the cron job & laravel schedule to work properly.

NOTE: I want it working with the database driver and NOT with redis or sync or something else, so please stay focused on the database driver, thanks.


Solution

  • laravel task scheduler and configured the queue:listen to be executed every minute

    This is wrong. You should never call queue:listen via the cron scheduler, otherwise you'll get unexpected behavior like what occurred to you.

    You should configure the queue:listen to run as a daemon process forever. Once the queue worker is running - it will run forever and process jobs as needed. You can use Supervisor to ensure it remains running.