Skip to content

Commit 35e11a6

Browse files
committed
update: add horizon
1 parent 1d87a1b commit 35e11a6

12 files changed

+1076
-2
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
parent::boot();
19+
20+
// Horizon::routeSmsNotificationsTo('15556667777');
21+
// Horizon::routeMailNotificationsTo('example@example.com');
22+
// Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel');
23+
24+
// Horizon::night();
25+
}
26+
27+
/**
28+
* Register the Horizon gate.
29+
*
30+
* This gate determines who can access Horizon in non-local environments.
31+
*
32+
* @return void
33+
*/
34+
protected function gate()
35+
{
36+
Gate::define('viewHorizon', function ($user) {
37+
return in_array($user->email, [
38+
//
39+
]);
40+
});
41+
}
42+
}

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
1818
"laravel/framework": "^7.29",
1919
"laravel/tinker": "^2.5",
20+
"laravel/horizon": "^4.3.5",
2021
"google/recaptcha": "^1.2",
2122
"lokielse/omnipay-alipay": "3.1.2",
2223
"lokielse/omnipay-wechatpay": "^3.0",

config/app.php

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
App\Providers\AuthServiceProvider::class,
174174
// App\Providers\BroadcastServiceProvider::class,
175175
App\Providers\EventServiceProvider::class,
176+
App\Providers\HorizonServiceProvider::class,
176177
App\Providers\RouteServiceProvider::class,
177178

178179
],

config/horizon.php

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
3+
use Illuminate\Support\Str;
4+
5+
return [
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Horizon Domain
10+
|--------------------------------------------------------------------------
11+
|
12+
| This is the subdomain where Horizon will be accessible from. If this
13+
| setting is null, Horizon will reside under the same domain as the
14+
| application. Otherwise, this value will serve as the subdomain.
15+
|
16+
*/
17+
18+
'domain' => null,
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Horizon Path
23+
|--------------------------------------------------------------------------
24+
|
25+
| This is the URI path where Horizon will be accessible from. Feel free
26+
| to change this path to anything you like. Note that the URI will not
27+
| affect the paths of its internal API that aren't exposed to users.
28+
|
29+
*/
30+
31+
'path' => 'horizon',
32+
33+
/*
34+
|--------------------------------------------------------------------------
35+
| Horizon Redis Connection
36+
|--------------------------------------------------------------------------
37+
|
38+
| This is the name of the Redis connection where Horizon will store the
39+
| meta information required for it to function. It includes the list
40+
| of supervisors, failed jobs, job metrics, and other information.
41+
|
42+
*/
43+
44+
'use' => 'default',
45+
46+
/*
47+
|--------------------------------------------------------------------------
48+
| Horizon Redis Prefix
49+
|--------------------------------------------------------------------------
50+
|
51+
| This prefix will be used when storing all Horizon data in Redis. You
52+
| may modify the prefix when you are running multiple installations
53+
| of Horizon on the same server so that they don't have problems.
54+
|
55+
*/
56+
57+
'prefix' => env(
58+
'HORIZON_PREFIX',
59+
Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
60+
),
61+
62+
/*
63+
|--------------------------------------------------------------------------
64+
| Horizon Route Middleware
65+
|--------------------------------------------------------------------------
66+
|
67+
| These middleware will get attached onto each Horizon route, giving you
68+
| the chance to add your own middleware to this list or change any of
69+
| the existing middleware. Or, you can simply stick with this list.
70+
|
71+
*/
72+
73+
'middleware' => ['web'],
74+
75+
/*
76+
|--------------------------------------------------------------------------
77+
| Queue Wait Time Thresholds
78+
|--------------------------------------------------------------------------
79+
|
80+
| This option allows you to configure when the LongWaitDetected event
81+
| will be fired. Every connection / queue combination may have its
82+
| own, unique threshold (in seconds) before this event is fired.
83+
|
84+
*/
85+
86+
'waits' => [
87+
'redis:default' => 60,
88+
],
89+
90+
/*
91+
|--------------------------------------------------------------------------
92+
| Job Trimming Times
93+
|--------------------------------------------------------------------------
94+
|
95+
| Here you can configure for how long (in minutes) you desire Horizon to
96+
| persist the recent and failed jobs. Typically, recent jobs are kept
97+
| for one hour while all failed jobs are stored for an entire week.
98+
|
99+
*/
100+
101+
'trim' => [
102+
'recent' => 60,
103+
'pending' => 60,
104+
'completed' => 60,
105+
'recent_failed' => 10080,
106+
'failed' => 10080,
107+
'monitored' => 10080,
108+
],
109+
110+
/*
111+
|--------------------------------------------------------------------------
112+
| Metrics
113+
|--------------------------------------------------------------------------
114+
|
115+
| Here you can configure how many snapshots should be kept to display in
116+
| the metrics graph. This will get used in combination with Horizon's
117+
| `horizon:snapshot` schedule to define how long to retain metrics.
118+
|
119+
*/
120+
121+
'metrics' => [
122+
'trim_snapshots' => [
123+
'job' => 24,
124+
'queue' => 24,
125+
],
126+
],
127+
128+
/*
129+
|--------------------------------------------------------------------------
130+
| Fast Termination
131+
|--------------------------------------------------------------------------
132+
|
133+
| When this option is enabled, Horizon's "terminate" command will not
134+
| wait on all of the workers to terminate unless the --wait option
135+
| is provided. Fast termination can shorten deployment delay by
136+
| allowing a new instance of Horizon to start while the last
137+
| instance will continue to terminate each of its workers.
138+
|
139+
*/
140+
141+
'fast_termination' => false,
142+
143+
/*
144+
|--------------------------------------------------------------------------
145+
| Memory Limit (MB)
146+
|--------------------------------------------------------------------------
147+
|
148+
| This value describes the maximum amount of memory the Horizon worker
149+
| may consume before it is terminated and restarted. You should set
150+
| this value according to the resources available to your server.
151+
|
152+
*/
153+
154+
'memory_limit' => 64,
155+
156+
/*
157+
|--------------------------------------------------------------------------
158+
| Queue Worker Configuration
159+
|--------------------------------------------------------------------------
160+
|
161+
| Here you may define the queue worker settings used by your application
162+
| in all environments. These supervisors and settings handle all your
163+
| queued jobs and will be provisioned by Horizon during deployment.
164+
|
165+
*/
166+
167+
'environments' => [
168+
'production' => [
169+
'supervisor-1' => [
170+
'connection' => 'redis',
171+
'queue' => ['default'],
172+
'balance' => 'simple',
173+
'processes' => 10,
174+
'tries' => 1,
175+
'nice' => 0,
176+
],
177+
],
178+
179+
'local' => [
180+
'supervisor-1' => [
181+
'connection' => 'redis',
182+
'queue' => [
183+
'traffic_fetch',
184+
'server_log',
185+
'send_email',
186+
'send_telegram',
187+
'stat_server'
188+
],
189+
'balance' => 'auto',
190+
'minProcesses' => 1,
191+
'maxProcesses' => 10,
192+
'tries' => 1,
193+
'nice' => 0,
194+
],
195+
],
196+
],
197+
];

pm2.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apps:
22
- name : 'V2Board'
3-
script : 'php artisan queue:work --queue=traffic_fetch,server_log,send_email,send_telegram,stat_server'
4-
instances: 4
3+
script : 'php artisan horizon'
4+
instances: 1
55
out_file : './storage/logs/queue/queue.log'

public/vendor/horizon/app-dark.css

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vendor/horizon/app.css

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vendor/horizon/app.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/vendor/horizon/img/favicon.png

648 Bytes
Loading

public/vendor/horizon/img/horizon.svg

+4
Loading

0 commit comments

Comments
 (0)