Skip to content

Commit 86c58bb

Browse files
committed
feat: basic redis queue setup
1 parent e3e5cb1 commit 86c58bb

5 files changed

Lines changed: 64 additions & 13 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ SESSION_DOMAIN="${APP_HOST}"
4343

4444
BROADCAST_CONNECTION=reverb
4545
FILESYSTEM_DISK=local
46-
QUEUE_CONNECTION=database
46+
QUEUE_CONNECTION=redis
4747

4848
CACHE_DRIVER=file
4949
CACHE_STORE=database

app/Jobs/IndexFiles.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
4040
* Create a new job instance.
4141
*/
4242
public function __construct($taskId) {
43+
if (config('queue.default') === 'redis') {
44+
$this->onQueue('pipeline');
45+
}
46+
4347
$subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Index Files']); //
4448
$this->taskId = $taskId;
4549
$this->subTaskId = $subTask->id;

app/Jobs/SyncFiles.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ class SyncFiles implements ShouldBeUnique, ShouldQueue {
3333
* Create a new job instance.
3434
*/
3535
public function __construct($taskId) {
36-
//
36+
if (config('queue.default') === 'redis') {
37+
$this->onQueue('pipeline');
38+
}
3739
$subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Sync Files']); //
3840
$this->taskId = $taskId;
3941
$this->subTaskId = $subTask->id;

app/Providers/HorizonServiceProvider.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
use Laravel\Horizon\Horizon;
77
use Laravel\Horizon\HorizonApplicationServiceProvider;
88

9-
class HorizonServiceProvider extends HorizonApplicationServiceProvider
10-
{
9+
class HorizonServiceProvider extends HorizonApplicationServiceProvider {
1110
/**
1211
* Bootstrap any application services.
1312
*/
14-
public function boot(): void
15-
{
13+
public function boot(): void {
1614
parent::boot();
1715

1816
// Horizon::routeSmsNotificationsTo('15556667777');
@@ -25,8 +23,7 @@ public function boot(): void
2523
*
2624
* This gate determines who can access Horizon in non-local environments.
2725
*/
28-
protected function gate(): void
29-
{
26+
protected function gate(): void {
3027
Gate::define('viewHorizon', function ($user = null) {
3128
return in_array(optional($user)->email, [
3229
//

config/horizon.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Str;
4+
use Laravel\Pulse\Http\Middleware\Authorize;
45

56
return [
67

@@ -56,7 +57,7 @@
5657

5758
'prefix' => env(
5859
'HORIZON_PREFIX',
59-
Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
60+
Str::slug(env('APP_NAME', 'laravel'), '_') . '_horizon:'
6061
),
6162

6263
/*
@@ -70,7 +71,11 @@
7071
|
7172
*/
7273

73-
'middleware' => ['web'],
74+
'middleware' => [
75+
'web',
76+
'api',
77+
Authorize::class,
78+
],
7479

7580
/*
7681
|--------------------------------------------------------------------------
@@ -180,7 +185,7 @@
180185
*/
181186

182187
'defaults' => [
183-
'supervisor-1' => [
188+
'supervisor-default' => [
184189
'connection' => 'redis',
185190
'queue' => ['default'],
186191
'balance' => 'auto',
@@ -193,21 +198,64 @@
193198
'timeout' => 60,
194199
'nice' => 0,
195200
],
201+
'supervisor-high' => [
202+
'connection' => 'redis',
203+
'queue' => ['high'],
204+
'balance' => 'auto',
205+
'autoScalingStrategy' => 'time',
206+
'maxProcesses' => 1,
207+
'maxTime' => 0,
208+
'maxJobs' => 0,
209+
'memory' => 128,
210+
'tries' => 1,
211+
'timeout' => 60,
212+
'nice' => 0,
213+
],
214+
'supervisor-pipeline' => [
215+
'connection' => 'redis',
216+
'queue' => ['pipeline'],
217+
'balance' => false,
218+
'processes' => 1, // enforced order
219+
'tries' => 3,
220+
],
196221
],
197222

198223
'environments' => [
199224
'production' => [
200-
'supervisor-1' => [
225+
'supervisor-default' => [
201226
'maxProcesses' => 10,
202227
'balanceMaxShift' => 1,
203228
'balanceCooldown' => 3,
204229
],
230+
'supervisor-high' => [
231+
'connection' => 'redis',
232+
'queue' => ['high'],
233+
'maxProcesses' => 5,
234+
'balanceMaxShift' => 1,
235+
'balanceCooldown' => 3,
236+
],
237+
'supervisor-pipeline' => [
238+
'connection' => env('QUEUE_CONNECTION', 'database'),
239+
'queue' => ['pipeline'],
240+
],
205241
],
206242

207243
'local' => [
208-
'supervisor-1' => [
244+
'supervisor-default' => [
245+
'connection' => env('QUEUE_CONNECTION', 'database'),
246+
'queue' => ['default'],
209247
'maxProcesses' => 3,
210248
],
249+
'supervisor-high' => [
250+
'connection' => env('QUEUE_CONNECTION', 'database'),
251+
'queue' => ['high'],
252+
'balance' => 'auto',
253+
'maxProcesses' => 3,
254+
],
255+
'supervisor-pipeline' => [
256+
'connection' => env('QUEUE_CONNECTION', 'database'),
257+
'queue' => ['pipeline'],
258+
],
211259
],
212260
],
213261
];

0 commit comments

Comments
 (0)