Skip to content

Commit e629b07

Browse files
authored
Use Laravel Horizon as a queue supervisor (#753)
* feat(queue): manage queue using laravel/horizon package * chore: only export prometheus metrics from backend pods * chore: source horizon config from env * fix: composer.lock is out of sync * fix: install fails on platform reqs * chore: only run horizon when explicitly enabled * chore: scope down ignore arg * docs: add CHANGELOG
1 parent 00c5872 commit e629b07

17 files changed

+1571
-227
lines changed

.github/workflows/composer.test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
with:
2525
php_version: 8.2
2626
command: install
27+
args: --ignore-platform-req=ext-pcntl
2728

2829
- name: Copy example .env file
2930
run: cp .env.example .env

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# api
22

3+
## 10x.1.0 - 14 March 2024
4+
- Use Laravel Horizon to supervise queue workers if enabled T342866
5+
36
## 10x.0.0 - 26 February 2024
47
- Update Laravel to v10.10 - T341797
58
- schedule redis stale tag pruning

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ COPY ./composer.json /tmp/src1/composer.json
44
COPY ./composer.lock /tmp/src1/composer.lock
55

66
WORKDIR /tmp/src1
7-
RUN composer install --no-dev --no-progress --no-autoloader
7+
RUN composer install --no-dev --no-progress --no-autoloader --ignore-platform-req=ext-pcntl
88

99
COPY ./ /tmp/src2
1010
RUN cp -r /tmp/src1/vendor /tmp/src2/vendor
1111
WORKDIR /tmp/src2
12-
RUN composer install --no-dev --no-progress --optimize-autoloader
12+
RUN composer install --no-dev --no-progress --optimize-autoloader --ignore-platform-req=ext-pcntl
1313

1414

1515
FROM php:8.2-apache
1616

1717
RUN apt-get update \
1818
# Needed for the imagick php extension install
19-
&& apt-get install -y --no-install-recommends libmagickwand-dev \
19+
&& apt-get install -y --no-install-recommends libmagickwand-dev libpq-dev \
2020
&& echo "" | pecl install imagick \
2121
&& docker-php-ext-enable imagick \
22+
&& docker-php-ext-configure pcntl --enable-pcntl \
23+
&& docker-php-ext-install pcntl \
24+
&& docker-php-ext-enable pcntl \
2225
# Obviously needed for mysql connection
2326
&& docker-php-ext-install pdo pdo_mysql \
2427
# For rewrite rules
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\Facades\Gate;
6+
use Laravel\Horizon\Horizon;
7+
use Laravel\Horizon\HorizonApplicationServiceProvider;
8+
9+
class HorizonServiceProvider extends HorizonApplicationServiceProvider
10+
{
11+
/**
12+
* Bootstrap any application services.
13+
*/
14+
public function boot(): void
15+
{
16+
parent::boot();
17+
18+
// Horizon::routeSmsNotificationsTo('15556667777');
19+
// Horizon::routeMailNotificationsTo('[email protected]');
20+
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
21+
}
22+
23+
/**
24+
* Register the Horizon gate.
25+
*
26+
* This gate determines who can access Horizon in non-local environments.
27+
*/
28+
protected function gate(): void
29+
{
30+
Gate::define('viewHorizon', function ($user) {
31+
return in_array($user->email, [
32+
//
33+
]);
34+
});
35+
}
36+
}

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
"hackzilla/password-generator": "^1.6",
1919
"intervention/image": "^2.5",
2020
"laravel/framework": "^10.10",
21+
"laravel/horizon": "^5.23",
2122
"laravel/passport": "^11.0",
2223
"laravel/tinker": "^2.8",
2324
"laravel/ui": "^4.4",
2425
"lcobucci/jwt": "^4.1",
2526
"league/flysystem-aws-s3-v3": "^3.22",
27+
"lkaemmerling/laravel-horizon-prometheus-exporter": "^1.7",
2628
"maclof/kubernetes-client": "^0.29.0",
2729
"mxl/laravel-job": "^1.5",
2830
"percymamedy/laravel-dev-booter": "^4.0",

0 commit comments

Comments
 (0)