Skip to content

Commit eccc804

Browse files
Allow naming of horizon instances (#1621)
* Allow naming of horizon instances * Run config normalize first * Add docblock * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 2b9194d commit eccc804

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

config/horizon.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44

55
return [
66

7+
/*
8+
|--------------------------------------------------------------------------
9+
| Horizon Name
10+
|--------------------------------------------------------------------------
11+
|
12+
| This name appears in notifications and in the Horizon UI. Unique names
13+
| can be useful while running multiple instances of Horizon within an
14+
| application, allowing you to identify the Horizon you're viewing.
15+
|
16+
*/
17+
18+
'name' => env('HORIZON_NAME'),
19+
720
/*
821
|--------------------------------------------------------------------------
922
| Horizon Domain

resources/views/layout.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="csrf-token" content="{{ csrf_token() }}">
88
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAipJREFUeNrEV8txwjAQtQ2HHCmB3JKbSQOYCoA0gD0pgFBBwpEToQAGKmDglpwgFdg5kZtNB1BBsuusZ4RY2ZZjYGd2jGWh97Q/rUwjpziPT3V4dECboDZoXZoSka5Al5vFNMqzrpkD2IFHn8B1ZAM6BCKbQgQAuAaPWQFgjoinsoipAEcTr0FrRjmyJxLLTAI5wXFXAehBGMPYcDKIIIm5kkAGOJpwAjqHRfYpbkOXvTBBypIwpT+HCvA3Cqi9Rta8EhHOHS1YCy1oWMKHmQIcGQ90wGMfLaZIoEGAoiDGOHmxhFTr5PGZJgncZYszEGC6ogX6nNn/Ay6RGDCfYveYVOFCJuAaumbPiIk1kyUNS2H6SZngyZrMWM+i/JVlXjK4QUVI3pRTpYPlaG6yeyGvm0Jef1ItiArwQBKu8G5bTMEIhKLkU3q65D+HgieE7+MCBHbygMVMOlCK+CnVDOUZ5s00ghCt2T45C+DDD2MBW/O066YFLYGvuXU5C9i6GYaLUzqr+olQtS5aIMwwtW6QfQnv7awNVanolEWgo9nABBb1cNeSmMDyigRWZkqdPrdEkDm3SRYMr7D7odwRXdIK8e7lOuAxh8W5pHtSiOhw8S4A7iX9IErlyC5b/7t+/7Ar4TKiEuyyRuJA5cQ5Wz8gEhgPNyXvfCQPVtgI+SPxAT/vSqiSEbXh70Uvp27GRSMNeJjV2Jp5V6MGpUeuUR0wAemKuwdy8ivAAJcc0R2NFxWtAAAAAElFTkSuQmCC">
99

10-
<title>Horizon{{ config('app.name') ? ' - ' . config('app.name') : '' }}</title>
10+
<title>Horizon{{ config('horizon.name') ? ' - ' . config('horizon.name') : '' }}</title>
1111

1212
<!-- Style sheets-->
1313
<link rel="preconnect" href="https://fonts.bunny.net">
@@ -32,7 +32,7 @@
3232
</svg>
3333

3434
<h1 class="h4 mb-0 ms-2">
35-
<strong>Laravel</strong> Horizon{{ config('app.name') ? ' - ' . config('app.name') : '' }}
35+
<strong>Laravel</strong> Horizon{{ config('horizon.name') ? ' - ' . config('horizon.name') : '' }}
3636
</h1>
3737
</router-link>
3838

src/HorizonServiceProvider.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,26 @@ class HorizonServiceProvider extends ServiceProvider
2020
*/
2121
public function boot()
2222
{
23+
$this->normalizeConfig();
2324
$this->registerEvents();
2425
$this->registerRoutes();
2526
$this->registerResources();
2627
$this->offerPublishing();
2728
$this->registerCommands();
2829
}
2930

31+
/**
32+
* Normalize the Horizon configuration.
33+
*
34+
* @return void
35+
*/
36+
protected function normalizeConfig()
37+
{
38+
if (! $this->app['config']->get('horizon.name')) {
39+
$this->app['config']->set('horizon.name', $this->app['config']->get('app.name'));
40+
}
41+
}
42+
3043
/**
3144
* Register the Horizon job events.
3245
*

src/Notifications/LongWaitDetected.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function toMail($notifiable)
7878
{
7979
return (new MailMessage)
8080
->error()
81-
->subject(config('app.name').': Long Queue Wait Detected')
81+
->subject(config('horizon.name').': Long Queue Wait Detected')
8282
->greeting('Oh no! Something needs your attention.')
8383
->line(sprintf(
8484
'The "%s" queue on the "%s" connection has a wait time of %s seconds.',
@@ -101,7 +101,7 @@ public function toSlack($notifiable)
101101

102102
$content = sprintf(
103103
'[%s] The "%s" queue on the "%s" connection has a wait time of %s seconds.',
104-
config('app.name'),
104+
config('horizon.name'),
105105
$this->longWaitQueue,
106106
$this->longWaitConnection,
107107
$this->seconds
@@ -142,7 +142,7 @@ public function toNexmo($notifiable)
142142
{
143143
return (new NexmoMessage)->content(sprintf( // @phpstan-ignore-line
144144
'[%s] The "%s" queue on the "%s" connection has a wait time of %s seconds.',
145-
config('app.name'), $this->longWaitQueue, $this->longWaitConnection, $this->seconds
145+
config('horizon.name'), $this->longWaitQueue, $this->longWaitConnection, $this->seconds
146146
));
147147
}
148148

0 commit comments

Comments
 (0)