0

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.

mi-ho
  • 167
  • 3
  • 14

3 Answers3

2

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.

Laurence
  • 58,936
  • 21
  • 171
  • 212
  • Thanks, This is probably what I am missing. I will try to do this tomorrow and be back here later. – mi-ho May 08 '17 at 22:19
  • I've a similar question, `queue:listen` unexpectedly execute the `schedule()` function. Can you help me. [laravel cannot run scheduled command](https://stackoverflow.com/q/47548220/6521116) – LF00 Nov 30 '17 at 03:32
1

I think the problem is that the queue:listen command was actually executed every minute. This shouldn't be happening. It should only be executed when it is not listening at the specific moment. Hence, there should be a check if the listener is running, or not. See this gist, should work for you.

As of to execute all the hanging queue tasks from the database, try:

php artisan queue:restart

And:

php artisan queue:work

Hope this helps.

Jan Willem
  • 1,280
  • 1
  • 9
  • 9
0

In Laravel 8 (not sure in previous versions)

php artisan queue:work --stop-when-empty

This command can be "croned" without any problem.

M. Saba
  • 34
  • 4