fatrex / filament-queue-tracker
Background Jobs monitoring like Horizon for all drivers for Filament (v4)
Fund package maintenance!
fatrex
Installs: 444
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 0
Forks: 0
pkg:composer/fatrex/filament-queue-tracker
Requires
- php: ^8.1|^8.2|^8.3|^8.4
- filament/filament: ^4.0
- illuminate/contracts: ^10.0|^11.0|^12.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- laravel/pint: ^1.0
README
This is a package to monitor background jobs for FilamentPHP (v4). It is inspired by Laravel Horizon and is compatible with all drivers.
Installation
Check your FilamentPHP version before installing:
| Package | FilamentPHP | PHP |
|---|---|---|
| 3.* | 4.* | >= 8.1 |
Acknowledgements & Filament v3 users
Huge thanks to the original creator and maintainer, Croustibat. This package now targets Filament v4 only. If you need Filament v3 support, please use the original library: croustibat/filament-jobs-monitor (v2.*).
Changelog
See CHANGELOG.md for local changes in this fork (v4-only).
Installation
Install the package via composer:
composer require fatrex/filament-queue-tracker
Publish and run the migrations using:
php artisan vendor:publish --tag="filament-queue-tracker-migrations"
php artisan migrate
Usage
Configuration
The global plugin config can be published using the command below:
php artisan vendor:publish --tag="filament-queue-tracker-config"
This is the content of the published config file:
return [ 'resources' => [ 'enabled' => true, 'label' => 'Job', 'plural_label' => 'Jobs', 'navigation_group' => 'Settings', 'navigation_icon' => 'heroicon-o-cpu-chip', 'navigation_sort' => null, 'navigation_count_badge' => false, 'resource' => Fatrex\FilamentQueueTracker\Resources\QueueMonitorResource::class, ], 'pruning' => [ 'enabled' => true, 'retention_days' => 7, ], 'queues' => [ 'default' ], ];
NOTE: Since there isn't a universal way to retrieve all used queues, it's necessary to define them to obtain all pending jobs.
Extending Model
Sometimes it's useful to extend the model to add some custom methods. You can do it by extending the model by creating your own model :
$ php artisan make:model MyQueueMonitor
Then you can extend the model by adding your own methods :
<?php namespace App\Models; use \Fatrex\FilamentQueueTracker\Models\QueueMonitor as FatrexQueueMonitor; class MyQueueMonitor extends FatrexQueueMonitor {}
Using Filament Panels
If you are using Filament Panels, you can register the Plugin to your Panel configuration. This will register the plugin's resources as well as allow you to set configuration using optional chainable methods.
For example in your app/Providers/Filament/AdminPanelProvider.php file:
<?php use \Fatrex\FilamentQueueTracker\FilamentQueueTrackerPlugin; ... public function panel(Panel $panel): Panel { return $panel ->plugins([ FilamentQueueTrackerPlugin::make() ]); }
Usage
Just run a Background Job and go to the route /admin/queue-monitors to see the jobs.
Example
Go to example folder to see a Job example file.
Then you can call your Job with the following code:
public static function table(Table $table): Table { return $table // rest of your code ... ->bulkActions([ BulkAction::make('export-jobs') ->label('Background Export') ->icon('heroicon-o-cog') ->action(function (Collection $records) { UsersCsvExportJob::dispatch($records, 'users.csv'); Notification::make() ->title('Export is ready') ->body('Your export is ready. You can download it from the exports page.') ->success() ->seconds(5) ->icon('heroicon-o-inbox-in') ->send(); }) ]) }
Enabling navigation
// AdminPanelProvider.php ->plugins([ // ... FilamentQueueTrackerPlugin::make() ->enableNavigation(), ])
Or you can use a closure to enable navigation only for specific users:
// AdminPanelProvider.php ->plugins([ // ... FilamentQueueTrackerPlugin::make() ->enableNavigation( fn () => auth()->user()->can('view_queue_job') || auth()->user()->can('view_any_queue_job)'), ), ])
Note for Filament v3 users
This package now targets Filament v4 only. If you need Filament v3 support, please use the original library we forked from: croustibat/filament-jobs-monitor (v2.*).