Queue Monitoring for Laravel Database Job Queue

Queue Monitoring for Laravel Database Job Queue

README

Latest Stable Version
Total Downloads
License
Code Quality
Build Status
StyleCI

This package offers monitoring like Laravel Horizon for database queue.

Features

  • Monitor all jobs like Laravel Horizon, but not only for redis
  • Handles failed jobs with exception
  • Support for milliseconds
  • Model for Queue Monitorings

Installation

composer require romanzipp/laravel-queue-monitor

Or add romanzipp/laravel-queue-monitor to your composer.json

"romanzipp/laravel-queue-monitor": "*"

Run composer update to pull the latest version.

If you use Laravel 5.5+ you are already done, otherwise continue:

romanzippQueueMonitorProvidersQueueMonitorProvider::class,

Add Service Provider to your app.php configuration file:

Configuration

Copy configuration to config folder:

$ php artisan vendor:publish --provider="romanzippQueueMonitorProvidersQueueMonitorProvider"

Migrate the Queue Monitoring table. The table name itself can be configured in the config file.

$ php artisan migrate

Usage

To monitor a job, add the romanzippQueueMonitorTraitsQueueMonitor Trait.

Update Job Progress / Custom Data

You can update the progress of the current job, like supported by FFMpeg

use IlluminateBusQueueable;
use IlluminateQueueSerializesModels;
use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use romanzippQueueMonitorTraitsQueueMonitor; // <---

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']);
    }
}

Retrieve processed Jobs

use romanzippQueueMonitorModelsMonitor;

$jobs = Monitor::ordered()->get();

foreach ($jobs as $job) {

    // Exact start & finish dates with milliseconds
    $job->startedAtExact();
    $job->finishedAtExact();
}

Model Scopes

// 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

ToDo

  • Add Job & Artisan Command for automatic cleanup of old database entries

The Idea has been inspirated by gilbitron’s laravel-queue-monitor package.

Source

Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *