All Projects → romanzipp → Laravel Queue Monitor

romanzipp / Laravel Queue Monitor

Licence: mit
Monitoring Laravel Jobs with your Database

Projects that are alternatives of or similar to Laravel Queue Monitor

Laravel Rate Limited Job Middleware
A job middleware to rate limit jobs
Stars: ✭ 166 (+22.06%)
Mutual labels:  laravel, queue
Laravel Failed Job Monitor
Get notified when a queued job fails
Stars: ✭ 582 (+327.94%)
Mutual labels:  laravel, queue
Laravel Queue
Laravel Enqueue message queue extension. Supports AMQP, Amazon SQS, Kafka, Google PubSub, Redis, STOMP, Gearman, Beanstalk and others
Stars: ✭ 155 (+13.97%)
Mutual labels:  laravel, queue
Laravel Couchbase
Couchbase providers for Laravel
Stars: ✭ 31 (-77.21%)
Mutual labels:  laravel, queue
Laravel Queue Rabbitmq
RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.
Stars: ✭ 1,175 (+763.97%)
Mutual labels:  laravel, queue
Sansdaemon
Batch process Laravel Queue without a daemon; Processes queue jobs and kills the process
Stars: ✭ 119 (-12.5%)
Mutual labels:  laravel, queue
Laravel Job Status
Add ability to track Job progress, status and result dispatched to Queue.
Stars: ✭ 279 (+105.15%)
Mutual labels:  laravel, queue
Laravel Queue Database Ph4
Laravel Database Queue with Optimistic locking
Stars: ✭ 37 (-72.79%)
Mutual labels:  laravel, queue
Laravel Elasticbeanstalk Queue Worker
Stars: ✭ 48 (-64.71%)
Mutual labels:  laravel, queue
Rabbitevents
Nuwber's events provide a simple observer implementation, allowing you to listen for various events that occur in your current and another application. For example, if you need to react to some event published from another API.
Stars: ✭ 84 (-38.24%)
Mutual labels:  laravel, queue
Laravel Seo
SEO package made for maximum customization and flexibility
Stars: ✭ 130 (-4.41%)
Mutual labels:  laravel, showcase
Paste.laravel.io
The Laravel.io Pastebin.
Stars: ✭ 135 (-0.74%)
Mutual labels:  laravel
Laravel Queue Kafka
Kafka Queue driver for Laravel
Stars: ✭ 134 (-1.47%)
Mutual labels:  laravel
Mpesa Php Sdk
A PHP sdk for the new Mpesa RESTful APIs
Stars: ✭ 134 (-1.47%)
Mutual labels:  laravel
Simple Qrcode
An easy-to-use PHP QrCode generator with first-party support for Laravel.
Stars: ✭ 1,923 (+1313.97%)
Mutual labels:  laravel
Timequeue.js
A queue with custom concurrency and time limit.
Stars: ✭ 135 (-0.74%)
Mutual labels:  queue
Laravel Artisan Dd
Quickly run some code via Artisan
Stars: ✭ 136 (+0%)
Mutual labels:  laravel
F Admin
f-admin是一套基于Laravel框架开发的基础权限后台系统
Stars: ✭ 134 (-1.47%)
Mutual labels:  laravel
Hdcms
支持 PC、H5、微信公众号、微信小程序多应用平台
Stars: ✭ 134 (-1.47%)
Mutual labels:  laravel
Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Stars: ✭ 134 (-1.47%)
Mutual labels:  laravel

Laravel Queue Monitor

Latest Stable Version Total Downloads License GitHub Build Status

This package offers monitoring like Laravel Horizon for database queue.

Features

  • Monitor jobs like Laravel Horizon for any queue
  • Handle failing jobs with storing exception
  • Monitor job progress
  • Get an estimated time remaining for a job
  • Store additional data for a job monitoring

Installation

composer require romanzipp/laravel-queue-monitor

Configuration

Copy configuration & migration to your project:

php artisan vendor:publish --provider="romanzipp\QueueMonitor\Providers\QueueMonitorProvider"

Migrate the Queue Monitoring table. The table name can be configured in the config file or via the published migration.

php artisan migrate

Usage

To monitor a job, simply add the romanzipp\QueueMonitor\Traits\IsMonitored Trait.

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\IsMonitored; // <---

class ExampleJob implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;
    use IsMonitored; // <---
}

Important! You need to implement the Illuminate\Contracts\Queue\ShouldQueue interface to your job class. Otherwise, Laravel will not dispatch any events containing status information for monitoring the job.

UI

You can enable the optional UI routes by calling Route::queueMonitor() inside your route file, similar to the official ui scaffolding.

Route::prefix('jobs')->group(function () {
    Route::queueMonitor();
});

Routes

Route Action
/ Show the jobs table

See the full configuration file for more information.

Preview

Extended usage

Progress

You can set a progress value (0-100) to get an estimation of a job progression.

use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;

class ExampleJob implements ShouldQueue
{
    use IsMonitored;

    public function handle()
    {
        $this->queueProgress(0);

        // Do something...

        $this->queueProgress(50);

        // Do something...

        $this->queueProgress(100);
    }
}

Chunk progress

A common scenario for a job is iterating through large collections.

This example job loops through a large amount of users and updates it's progress value with each chunk iteration.

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use romanzipp\QueueMonitor\Traits\IsMonitored;

class ChunkJob implements ShouldQueue
{
    use IsMonitored;

    public function handle()
    {
        $usersCount = User::count();

        $perChunk = 50;

        User::query()
            ->chunk($perChunk, function (Collection $users) use ($perChunk, $usersCount) {

                $this->queueProgressChunk($usersCount $perChunk);

                foreach ($users as $user) {
                    // ...
                }
            });
    }
}

Progress cooldown

To avoid flooding the database with rapidly repeating update queries, you can set override the progressCooldown method and specify a length in seconds to wait before each progress update is written to the database. Notice that cooldown will always be ignore for the values 0, 25, 50, 75 and 100.

use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;

class LazyJob implements ShouldQueue
{
    use IsMonitored;

    public function progressCooldown(): int
    {
        return 10; // Wait 10 seconds between each progress update
    }
}

Custom data

This package also allows setting custom data in array syntax on the monitoring model.

use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;

class CustomDataJob implements ShouldQueue
{
    use IsMonitored;

    public function handle()
    {
        $this->queueData(['foo' => 'Bar']);
        
        // WARNING! This is overriding the monitoring data
        $this->queueData(['bar' => 'Foo']);

        // To preserve previous data and merge the given payload, set the $merge parameter true
        $this->queueData(['bar' => 'Foo'], true);
    }
}

In order to show custom data on UI you need to add this line under config/queue-monitor.php

'ui' => [
    ...

    'show_custom_data' => true,

    ...
]

Only keep failed jobs

You can override the keepMonitorOnSuccess() method to only store failed monitor entries of an executed job. This can be used if you only want to keep failed monitors for jobs that are frequently executed but worth to monitor. Alternatively you can use Laravel's built in failed_jobs table.

use Illuminate\Contracts\Queue\ShouldQueue;
use romanzipp\QueueMonitor\Traits\IsMonitored;

class FrequentSucceedingJob implements ShouldQueue
{
    use IsMonitored;

    public static function keepMonitorOnSuccess(): bool
    {
        return false;
    }
}

Retrieve processed Jobs

use romanzipp\QueueMonitor\Models\Monitor;

$job = Monitor::query()->first();

// Check the current state of a job
$job->isFinished();
$job->hasFailed();
$job->hasSucceeded();

// Exact start & finish dates with milliseconds
$job->getStartedAtExact();
$job->getFinishedAtExact();

// If the job is still running, get the estimated seconds remaining
// Notice: This requires a progress to be set
$job->getRemainingSeconds();
$job->getRemainingInterval(); // Carbon\CarbonInterval

// Retrieve any data that has been set while execution
$job->getData();

// Get the base name of the executed job
$job->getBasename();

Model Scopes

use romanzipp\QueueMonitor\Models\Monitor;

// Filter by Status
Monitor::failed();
Monitor::succeeded();

// Filter by Date
Monitor::lastHour();
Monitor::today();

// Chain Scopes
Monitor::today()->failed();

Upgrading


This package was inspired by gilbitron's laravel-queue-monitor which is not maintained anymore.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].