12

I am using Laravel queues and Redis with Horizon. Supervisor is running artisan horizon which in turn spawns processes /usr/bin/php7.2 artisan horizon:work redis

Is there need to run queue:work at all or can Horizon already process the queue on its own?

Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83
Margus Pala
  • 8,433
  • 8
  • 42
  • 52

2 Answers2

15

With Horizon installed, the Artisan queue:work and horizon:work commands perform the same tasks, except that horizon:work accepts arguments that it uses to coordinate with a Horizon supervisor.

When running the Horizon supervisor process (via artisan horizon), we never need to execute horizon:work manually. The horizon:work command starts a queue worker process, and the supervisor runs it automatically when setting up worker pools.

By supervisor, I mean the Horizon manager process, not the system's supervisord which we use to start Horizon as a service.

In fact, horizon:work is marked hidden, so we won't even see it in the available commands shown by artisan list.

We can still execute artisan queue:work manually to run a single, standalone queue worker that isn't managed by Horizon.

The artisan queue:work --once <connection> command is more useful—this processes the next pending item in a queue and can help to debug misbehaving jobs in development.

For this to be effective, we need to run it after stopping any long-running queue workers so we can control when the job executes. Horizon makes this easy:

php artisan horizon:terminate
Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83
1

Cy Rossignol's answer is right. But I will add more.

From the official docs says:

Laravel Horizon requires that you use Redis to power your queue. Therefore, you should ensure that your queue connection is set to redis in your application's config/queue.php configuration file.

So the horizon is an enhancement of Laravel worker with dashboard and other features, but it will only work for Redis. Not like default Laravel queue worker that support file,database, and other drivers that are supported by Laravel.

The benefit of using horizon:

  • has a metrics dashboard which provides information regarding your job and queue wait times and throughput
  • has ability to send webhook or Slack or SMS notifications
  • has ability to pause and resume
  • has ability to see and retry failed job in dashboard
  • has worker balancing strategies (simple, auto, and false)
  • has more custom configurations like maxProcesses, balanceMaxShift, balanceCooldown, etc
Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73