Skip to content

Commit 83b0168

Browse files
committed
feat(horizon): integrate Laravel Horizon for queue management, add Horizon service provider, and update related configurations
1 parent 35ff71d commit 83b0168

23 files changed

Lines changed: 463 additions & 145 deletions

File tree

‎.cursor/rules/laravel-boost.mdc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This application is a Laravel application and its main Laravel ecosystems packag
1515
- inertiajs/inertia-laravel (INERTIA) - v2
1616
- laravel/fortify (FORTIFY) - v1
1717
- laravel/framework (LARAVEL) - v12
18+
- laravel/horizon (HORIZON) - v5
1819
- laravel/prompts (PROMPTS) - v0
1920
- laravel/wayfinder (WAYFINDER) - v0
2021
- larastan/larastan (LARASTAN) - v3

‎CLAUDE.md‎

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ This application is a Laravel application and its main Laravel ecosystems packag
496496
- inertiajs/inertia-laravel (INERTIA) - v2
497497
- laravel/fortify (FORTIFY) - v1
498498
- laravel/framework (LARAVEL) - v12
499+
- laravel/horizon (HORIZON) - v5
499500
- laravel/prompts (PROMPTS) - v0
500501
- laravel/wayfinder (WAYFINDER) - v0
501502
- larastan/larastan (LARASTAN) - v3
@@ -771,62 +772,6 @@ If your application uses the `<Form>` component from Inertia, you can use Wayfin
771772

772773
</code-snippet>
773774

774-
### Common Patterns & Gotchas
775-
776-
#### Multiple Route Parameters
777-
When your route has multiple parameters (e.g., `organizations/{organization}/members/{member}`), you **must** pass them as an array to Wayfinder functions.
778-
779-
<code-snippet name="Multiple Route Parameters" lang="typescript">
780-
// routes/web.php
781-
Route::patch('organizations/{organization}/members/{member}', [MemberController::class, 'update']);
782-
783-
// ❌ WRONG - Will cause "Cannot read properties of undefined (reading 'toString')"
784-
update.url(organization, memberUuid)
785-
update.url(organization.slug, memberUuid)
786-
update.url(organization, { member: memberUuid })
787-
788-
// ✅ CORRECT - Use array for multiple parameters
789-
update.url([organization.slug, memberUuid])
790-
791-
// Also works with router methods
792-
router.patch(update.url([organization.slug, memberUuid]), { role: 'admin' })
793-
router.delete(destroy.url([organization.slug, memberUuid]))
794-
</code-snippet>
795-
796-
#### Form Helper Availability
797-
Not all Wayfinder actions have the `.form()` helper method. When it's unavailable, use explicit `action` and `method` props instead.
798-
799-
<code-snippet name="Form Helper Alternatives" lang="typescript">
800-
// ❌ WRONG - May cause "form is not a function" error
801-
<Form {...store.form(organization)}>
802-
<Form {...update.form([organization.slug])}>
803-
804-
// ✅ CORRECT - Use explicit action and method props
805-
<Form action={store.url(organization.slug)} method="post">
806-
<input name="email" type="email" />
807-
<button type="submit">Add</button>
808-
</Form>
809-
810-
<Form action={update.url([organization.slug])} method="patch">
811-
<input name="name" defaultValue={organization.name} />
812-
<button type="submit">Save</button>
813-
</Form>
814-
</code-snippet>
815-
816-
#### Route Parameter Order
817-
Parameters must be passed in the same order as they appear in the route definition.
818-
819-
<code-snippet name="Parameter Order Matters" lang="typescript">
820-
// routes/web.php
821-
Route::get('organizations/{organization}/packages/{package}', [PackageController::class, 'show']);
822-
823-
// ✅ CORRECT - Parameters in route order: organization, then package
824-
show.url([organizationSlug, packageId])
825-
826-
// ❌ WRONG - Parameters reversed
827-
show.url([packageId, organizationSlug]) // Will generate incorrect URL
828-
</code-snippet>
829-
830775

831776
=== pint/core rules ===
832777

‎app/Domains/Package/Contracts/Data/PackageData.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function __construct(
2222
public ?string $latestVersion,
2323
public CarbonInterface $updatedAt,
2424
public ?string $repositoryName,
25+
public ?string $repositoryIdentifier,
26+
public ?string $repositoryUuid,
2527
) {}
2628

2729
public static function fromModel(Package $package): self
@@ -49,6 +51,8 @@ public static function fromModel(Package $package): self
4951
latestVersion: $latestVersion?->version,
5052
updatedAt: $updatedAt,
5153
repositoryName: $package->repository?->name,
54+
repositoryIdentifier: $package->repository?->repo_identifier,
55+
repositoryUuid: $package->repository?->uuid,
5256
);
5357
}
5458
}

‎app/Domains/Repository/Actions/FindOrCreatePackageAction.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function handle(Repository $repository, string $packageName): Package
2020
'organization_uuid' => $repository->organization_uuid,
2121
'repository_uuid' => $repository->uuid,
2222
'name' => $packageName,
23-
'description' => "Automatically synced from {$repository->name}",
2423
'type' => 'library',
2524
'visibility' => 'private',
2625
]);

‎app/Domains/Repository/Http/Controllers/RepositoryController.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Domains\Repository\Contracts\Data\SyncLogData;
1010
use App\Domains\Repository\Contracts\Enums\GitProvider;
1111
use App\Domains\Repository\Http\Requests\StoreRepositoryRequest;
12+
use App\Domains\Repository\Jobs\SyncRepositoryJob;
1213
use App\Http\Controllers\Controller;
1314
use App\Models\Organization;
1415
use App\Models\Repository;
@@ -57,6 +58,8 @@ public function store(StoreRepositoryRequest $request, Organization $organizatio
5758
'default_branch' => $request->default_branch,
5859
]);
5960

61+
SyncRepositoryJob::dispatch($repository);
62+
6063
return redirect()
6164
->route('organizations.repositories.index', $organization)
6265
->with('success', 'Repository added successfully.');

‎app/Domains/Repository/Jobs/SyncRepositoryJob.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
use App\Exceptions\ComposerMetadataException;
1717
use App\Models\Repository;
1818
use App\Models\RepositorySyncLog;
19+
use Illuminate\Contracts\Queue\ShouldBeUnique;
1920
use Illuminate\Contracts\Queue\ShouldQueue;
2021
use Illuminate\Foundation\Queue\Queueable;
2122
use Illuminate\Support\Facades\Log;
2223
use Spatie\LaravelData\DataCollection;
2324
use Throwable;
2425

25-
class SyncRepositoryJob implements ShouldQueue
26+
class SyncRepositoryJob implements ShouldBeUnique, ShouldQueue
2627
{
2728
use Queueable;
2829

@@ -35,8 +36,11 @@ class SyncRepositoryJob implements ShouldQueue
3536
*/
3637
public function __construct(
3738
public Repository $repository
38-
) {
39-
//
39+
) {}
40+
41+
public function uniqueId(): string
42+
{
43+
return "sync-repository-{$this->repository->uuid}";
4044
}
4145

4246
/**
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('example@example.com');
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 = null) {
31+
return in_array(optional($user)->email, [
32+
//
33+
]);
34+
});
35+
}
36+
}

‎bootstrap/providers.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
return [
44
App\Providers\AppServiceProvider::class,
55
App\Providers\FortifyServiceProvider::class,
6+
App\Providers\HorizonServiceProvider::class,
67
];

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"inertiajs/inertia-laravel": "^2.0",
1515
"laravel/fortify": "^1.30",
1616
"laravel/framework": "^12.0",
17+
"laravel/horizon": "^5.40",
1718
"laravel/tinker": "^2.10.1",
1819
"laravel/wayfinder": "^0.1.9",
1920
"spatie/laravel-data": "^4.18",

‎composer.lock‎

Lines changed: 81 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)