Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Horizon not executing pending jobs - Kubernetes and Docker environment

We have two different pods in Kubernetes for our Laravel app,

  • one running apache serving on port 80, (CMD /usr/sbin/apache2ctl -D FOREGROUND)
  • and another running worker (Laravel Horizon) (CMD php /var/www/artisan horizon)

The issue is when I check the horizon dashboard, it says 'Active', and I can see the Jobs in the 'Pending Jobs' section, but they never actually execute. They are just sitting there idle.

Now, when I SSH in the pod running apache and manually and run the command 'php artisan horizon' than it actually executes all pending jobs.

I have already ensured the followings:

  1. Both the pods are connected with the same Redis database service
  2. Horizon Prefix is the same for both the pods
like image 614
Ambuj Soni Avatar asked Jun 06 '20 19:06

Ambuj Soni


3 Answers

Double check your APP_ENV matches one of the environments in the horizon.php config. Otherwise horizon will not start any queue workers.

By default only local and production environments are provided:

https://laravel.com/docs/8.x/horizon#environments

like image 95
Mostafa Bahri Avatar answered Nov 10 '22 20:11

Mostafa Bahri


After struggling for days, I got the answer to this problem.

While using Redis as a cache, queue, or broadcast broker in the docker environment, we need to make sure that the following environment variables are defined properly and they must be the same across all the pods.

  • CACHE_PREFIX
  • REDIS_PREFIX
  • REDIS_CACHE_DB
  • HORIZON_PREFIX

Hope this will help others trying to deploy the Laravel apps using Kubernetes and Docker.

like image 31
Ambuj Soni Avatar answered Nov 10 '22 22:11

Ambuj Soni


In my case, I need to change my app environment from prod to production

APP_ENV=production
like image 5
Linh Pham Avatar answered Nov 10 '22 20:11

Linh Pham