Skip to content

Commit fe437ff

Browse files
committed
Add support for Horizon
Signed-off-by: Cy Rossignol <[email protected]>
1 parent 5df5002 commit fe437ff

24 files changed

+1481
-51
lines changed

.travis.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: php
22
dist: trusty
3+
sudo: false
34

45
php:
56
- 5.6
@@ -11,7 +12,9 @@ env:
1112
- LARAVEL_VERSION=">=5.4.0 <5.4.20"
1213
- LARAVEL_VERSION=">=5.4.20 <5.5.0"
1314
- LARAVEL_VERSION="5.5.*"
15+
- LARAVEL_VERSION="5.5.*" HORIZON=1
1416
- LARAVEL_VERSION="5.6.*"
17+
- LARAVEL_VERSION="5.6.*" HORIZON=1
1518
- LUMEN_VERSION="5.4.*"
1619
- LUMEN_VERSION="5.5.*"
1720
- LUMEN_VERSION="5.6.*"
@@ -20,14 +23,22 @@ matrix:
2023
exclude:
2124
- php: 5.6
2225
env: LARAVEL_VERSION="5.5.*"
26+
- php: 5.6
27+
env: LARAVEL_VERSION="5.5.*" HORIZON=1
2328
- php: 5.6
2429
env: LUMEN_VERSION="5.5.*"
2530
- php: 5.6
2631
env: LARAVEL_VERSION="5.6.*"
32+
- php: 5.6
33+
env: LARAVEL_VERSION="5.6.*" HORIZON=1
2734
- php: 5.6
2835
env: LUMEN_VERSION="5.6.*"
36+
- php: 7.0
37+
env: LARAVEL_VERSION="5.5.*" HORIZON=1
2938
- php: 7.0
3039
env: LARAVEL_VERSION="5.6.*"
40+
- php: 7.0
41+
env: LARAVEL_VERSION="5.6.*" HORIZON=1
3142
- php: 7.0
3243
env: LUMEN_VERSION="5.6.*"
3344

@@ -36,9 +47,10 @@ before_install:
3647
- if [ -n "$LARAVEL_VERSION" ]; then composer require --no-update "laravel/framework:$LARAVEL_VERSION"; fi
3748
- if [ -n "$LUMEN_VERSION" ]; then composer remove --dev --no-update "laravel/framework"; fi
3849
- if [ -n "$LUMEN_VERSION" ]; then composer require --no-update "laravel/lumen-framework:$LUMEN_VERSION"; fi
50+
- if [ -z "$HORIZON" ]; then composer remove --dev --no-update "laravel/horizon"; fi
3951

40-
install: composer install --prefer-dist --no-interaction --no-suggest
52+
install: travis_retry composer install --prefer-dist --no-interaction --no-suggest
4153

42-
before_script: SUPERVISE=no ./start-cluster.sh || { cat ./cluster/*.log; false; }
54+
before_script: SUPERVISE=no travis_retry ./start-cluster.sh || { cat ./cluster/*.log; false; }
4355

44-
script: vendor/bin/phpunit ${LUMEN_VERSION:+--exclude-group laravel-only}
56+
script: vendor/bin/phpunit --exclude-group ${LUMEN_VERSION:+laravel-only},${HORIZON:-horizon}

README.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ erases stored session information as well.
2020

2121
This package wraps the configuration of Laravel's broadcasting, cache, session,
2222
and queue APIs for Sentinel with the ability to set options for our Redis
23-
services independently. We configure the package separately from Laravel's
24-
standard Redis configuration so we can choose to use the Sentinel connections
25-
as needed by the environment. A developer may use a standalone Redis server in
26-
their local environment, while production environments operate a Redis Sentinel
27-
set of servers.
23+
services independently. It adds Sentinel support for [Laravel Horizon][s-horizon]
24+
and fixes other compatibility issues.
25+
26+
We configure the package separately from Laravel's standard Redis configuration
27+
so we can choose to use the Sentinel connections as needed by the environment.
28+
A developer may use a standalone Redis server in their local environment, while
29+
production environments operate a Redis Sentinel set of servers.
2830

2931

3032
Contents
@@ -42,6 +44,7 @@ Contents
4244
- [Executing Redis Commands (RedisSentinel Facade)][s-facade]
4345
- [Dependency Injection][s-dependency-injection]
4446
- [Other Sentinel Considerations][s-considerations]
47+
- [Laravel Horizon][s-horizon]
4548
- [Testing](#testing)
4649
- [License](#license)
4750
- [Appendix: Environment Variables][s-appx-env-vars]
@@ -598,6 +601,9 @@ service (`app('redis')`, etc) will operate using the Sentinel connections.
598601
This makes it easier for developers to use a standalone Redis server in their
599602
local environments and switch to a full Sentinel set of servers in production.
600603

604+
**Note:** When using the package with [Laravel Horizon][s-horizon], this change
605+
will cause Horizon to run over a Sentinel connection as well.
606+
601607

602608
Executing Redis Commands (RedisSentinel Facade)
603609
-------------------------------------------------
@@ -726,6 +732,67 @@ connection failure handling. For high-availability, use the Laravel API by
726732
passing a closure to `subscribe()` or `psubscribe()`.
727733

728734

735+
Laravel Horizon
736+
---------------
737+
738+
Versions 2.4.0 and greater of this package provide for the use of Sentinel
739+
connections with the [Laravel Horizon][laravel-horizon] queue management tool
740+
in compatible applications (Laravel 5.5+).
741+
742+
After [installing Horizon][laravel-horizon-install-docs], we need to update
743+
some configuration settings in *config/horizon.php*:
744+
745+
If needed, change `'use' => 'default'` to the name of the Sentinel connection
746+
to use for the Horizon backend as configured in *config/database.php*.
747+
748+
**Important:** The standard `'redis'` connections array in *config/database.php*
749+
must contain an element with the same key as the Sentinel connection specified
750+
for the `'use'` directive or Horizon throws an exception. Currently, Horizon
751+
does not provide a way for this package to handle this behavior, but an
752+
(in-progress) pull request may eliminate this requirement in the future. This
753+
element can contain any value (but a matching Redis connection config seems
754+
most appropriate).
755+
756+
Change the backend driver for Horizon's internal metadata to `'redis-sentinel'`
757+
by adding the following element to the top-level array:
758+
759+
```php
760+
'driver' => env('HORIZON_DRIVER', 'redis');
761+
```
762+
763+
...and assign the value of `redis-sentinel` to `HORIZON_DRIVER` in *.env*.
764+
765+
766+
Then, add an entry to the `'waits'` array for any Sentinel queues:
767+
768+
```php
769+
'waits' => [
770+
...
771+
'redis-sentinel:default' => 60,
772+
],
773+
```
774+
775+
Next, change the connection driver to `redis-sentinel` for each of the queue
776+
workers that should use Sentinel connections in the `'environments'` block:
777+
778+
```php
779+
...
780+
'supervisor-1' => [
781+
'connection' => 'redis-sentinel',
782+
...
783+
],
784+
...
785+
```
786+
787+
Horizon will now use the application's Redis Sentinel connections to monitor
788+
and process our queues.
789+
790+
**Note:** If we already configured the package to [override Laravel's standard
791+
Redis API][s-override-redis-api] (by setting `REDIS_DRIVER` to `redis-sentinel`,
792+
for example), we don't need to change `HORIZON_DRIVER` to `'redis-sentinel'`.
793+
The package already routes all Redis operations through Sentinel connections.
794+
795+
729796
Testing
730797
-------
731798

@@ -1117,6 +1184,7 @@ Sentinel Documentation][sentinel].
11171184
[s-env-config]: #environment-based-configuration
11181185
[s-env-config-examples]: #environment-based-configuration-examples
11191186
[s-facade]: #executing-redis-commands-redissentinel-facade
1187+
[s-horizon]: #laravel-horizon
11201188
[s-hybrid-config]: #hybrid-configuration
11211189
[s-integration-tests]: #integration-tests
11221190
[s-multi-sentinel-example]: #multi-sentinel-connection-configuration
@@ -1129,6 +1197,9 @@ Sentinel Documentation][sentinel].
11291197
[s-standard-config-examples]: #configuration-file-examples
11301198

11311199
[laravel-env-docs]: https://laravel.com/docs/configuration#environment-configuration
1200+
[laravel-horizon]: https://horizon.laravel.com
1201+
[laravel-horizon-docs]: https://laravel.com/docs/horizon
1202+
[laravel-horizon-install-docs]: https://laravel.com/docs/horizon#installation
11321203
[laravel-package-discovery-docs]: https://laravel.com/docs/packages#package-discovery
11331204
[laravel-redis-api-docs]: https://laravel.com/docs/redis#interacting-with-redis
11341205
[laravel-redis-docs]: https://laravel.com/docs/redis

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"require-dev": {
2525
"laravel/framework": "^5.4",
26+
"laravel/horizon": "^1.0",
2627
"laravel/lumen-framework": "^5.4",
2728
"mockery/mockery": "0.9.*",
2829
"phpunit/phpunit": "^4.8"

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
3+
<phpunit bootstrap="tests/bootstrap.php"
44
backupGlobals="false"
55
backupStaticAttributes="false"
66
colors="true"

0 commit comments

Comments
 (0)