This is a package to monitor background jobs for FilamentPHP. It is inspired by Laravel Horizon and is compatible with all drivers.
![Screenshot 2023-09-13 at 23 18 44](https://private-user-images.githubusercontent.com/1169456/268304733-a5d5a088-865f-4265-bd37-13dce213f529.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwNjc5OTQsIm5iZiI6MTcyNTA2NzY5NCwicGF0aCI6Ii8xMTY5NDU2LzI2ODMwNDczMy1hNWQ1YTA4OC04NjVmLTQyNjUtYmQzNy0xM2RjZTIxM2Y1MjkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgzMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MzFUMDEyODE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OWMxNjFiOThmYzg1MDExYzI0NjkyOTkwOGM4MjU2OTFmZjdiYjZmMThmOTQ0ZDQzYjZhZTdhYWQ3ODE4Y2IyZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.U8Q9_BQ8itdYBBoqCQijlnInPZ33f8Jq7JNpgBjGcCQ)
![Screenshot 2023-09-13 at 23 18 23](https://private-user-images.githubusercontent.com/1169456/268304721-e0a7730e-f459-4d99-8a40-5f35337385eb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwNjc5OTQsIm5iZiI6MTcyNTA2NzY5NCwicGF0aCI6Ii8xMTY5NDU2LzI2ODMwNDcyMS1lMGE3NzMwZS1mNDU5LTRkOTktOGE0MC01ZjM1MzM3Mzg1ZWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgzMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MzFUMDEyODE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODM5OGMxMmQyZjk3N2VmMjNkODQ1YTExNzlhZTJkOGMzZmRkNzZlYjBjYzQ0YWVkMjdmODJjOTc4ODJkZjhlMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.99F4kBe3ciTcP9r4AuITzmrCKhpXlEOzjKU4BDYfPwU)
Check your filamentPHP version before installing:
Version | FilamentPHP | PHP |
---|---|---|
1.* | 2.* | 8.1.* |
2.* | 3.* | 8.1.| 8.2. |
Install the package via composer:
composer require croustibat/filament-jobs-monitor
Publish and run the migrations using:
php artisan vendor:publish --tag="filament-jobs-monitor-migrations"
php artisan migrate
The global plugin config can be published using the command below:
php artisan vendor:publish --tag="filament-jobs-monitor-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' => Croustibat\FilamentJobsMonitor\Resources\QueueMonitorResource::class,
],
'pruning' => [
'enabled' => true,
'retention_days' => 7,
],
];
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 \Croustibat\FilamentJobsMonitor\Models\QueueMonitor as CroustibatQueueMonitor;
class MyQueueMonitor extends CroustibatQueueMonitor {}
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 \Croustibat\FilamentJobsMonitor\FilamentJobsMonitorPlugin;
...
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentJobsMonitorPlugin::make()
]);
}
Just run a Background Job and go to the route /admin/queue-monitors
to see the jobs.
The QueueMonitorUpdates
trait provides a setProgress
method for updating the progress of your jobs. This method takes an integer value representing the progress percentage and updates it in the queue_monitors
table.
Example usage:
$this->setProgress(20); // Set progress to 20%
QueueMonitorUpdates
also supports custom fields, allowing for more flexible job monitoring. This feature enables storing and tracking additional, job-specific data in a JSON custom_fields
column.
// Updating a single custom field
$this->setCustomFields('fieldName', 'fieldValue');
// Updating multiple custom fields at once
$this->setCustomFields([
'firstField' => 'firstValue',
'secondField' => 'secondValue'
]);
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();
})
])
}
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.