This package offers monitoring like Laravel Horizon for database queue.
- Monitor all jobs like Laravel Horizon, but not only for redis
- Handles failed jobs with exception
- Support for milliseconds
- Model for Queue Monitorings
composer require romanzipp/laravel-queue-monitor
If you use Laravel 5.5+ you are already done, otherwise continue.
Add Service Provider to your app.php configuration file:
romanzipp\QueueMonitor\Providers\QueueMonitorProvider::class,
Copy configuration to config folder:
$ php artisan vendor:publish --provider="romanzipp\QueueMonitor\Providers\QueueMonitorProvider"
Migrate the Queue Monitoring table. The table name itself can be configured in the config file.
$ php artisan migrate
To monitor a job, add the romanzipp\QueueMonitor\Traits\QueueMonitor
Trait.
You can update the progress of the current job, like supported by FFMpeg
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use romanzipp\QueueMonitor\Traits\QueueMonitor; // <---
class ExampleJob implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use QueueMonitor; // <---
public function handle()
{
// Save progress, if job driver supports
$ffmpeg->on('progress', function ($percentage) {
$this->queueProgress($percentage);
});
// Save data if finished. Must be type of array
$this->queueData(['foo' => 'bar']);
}
}
use romanzipp\QueueMonitor\Models\Monitor;
$jobs = Monitor::ordered()->get();
foreach ($jobs as $job) {
// Exact start & finish dates with milliseconds
$job->startedAtExact();
$job->finishedAtExact();
}
// Filter by Status
Monitor::failed();
Monitor::succeeded();
// Filter by Date
Monitor::lastHour();
Monitor::today();
// Chain Scopes
Monitor::today()->failed();
// Get parsed custom Monitor data
$monitor = Monitor::find(1);
$monitor->data; // Raw data string
$monitor->parsed_data; // JSON decoded data, always array
- Add Job & Artisan Command for automatic cleanup of old database entries
The Idea has been inspirated by gilbitron's laravel-queue-monitor package.