GithubHelp home page GithubHelp logo

gilbitron / laravel-queue-monitor Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 4.0 5 KB

A Laravel package to monitor queue jobs

Home Page: https://packagist.org/packages/gilbitron/laravel-queue-monitor

License: MIT License

PHP 100.00%

laravel-queue-monitor's Introduction

Laravel Queue Monitor

A Laravel package to monitor queue jobs. Logs certain information about queue jobs in a database table:

  • The elapsed time of the job including start and finish timestamps
  • If --tries is being used the attempt number for each job
  • If the job failed and the exception given (if available)
  • Custom data (optional)

Requirements

  • Laravel 5.3+

Install

Install the composer package:

composer require gilbitron/laravel-queue-monitor

Add the service provider in config/app.php:

/*
 * Package Service Providers...
 */
Gilbitron\LaravelQueueMonitor\LaravelQueueMonitorProvider::class,

Run a migration to setup the queue_monitor database table:

php artisan migrate

Usage

All queue jobs will now be monitored and results stored to the queue_monitor database table. No other configuration is required.

Custom Data

To save custom data with the queue monitor results you need to include the QueueMonitorData trait in your Job and use the saveQueueMonitorData() method. For example:

<?php

namespace App\Jobs;

use Gilbitron\LaravelQueueMonitor\Jobs\QueueMonitorData;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class ExampleJob implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels, QueueMonitorData;

    protected $results = 0;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->results = rand(1, 100);

        $this->saveQueueMonitorData([
            'results' => $this->results,
        ]);

        // ...
    }
}

Credits

Laravel Queue Monitor was created by Gilbert Pellegrom from Dev7studios. Released under the MIT license.

laravel-queue-monitor's People

Contributors

gilbitron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-queue-monitor's Issues

Record payload of the job

At the moment we get to see that a job of a given name started and ended. We don't know anything about what that job was working on or processing. The payload() of the job gives us these details, and it would be great to capture that information too. Without that, the monitor is really only good for statistics.

Laravel 5.5 auto-discovery

Laravel 5.5 allows the provider to be auto-discovered using an entry in composer.json. That would be a very nice update for this package.

I'll send a PR after I've played with this package a bit first, if it's something you would like.

Reattempted jobs update the wrong record

If a job fails quickly and is restarted immediately, then the second (and potentially subsequent) attempts will update the first attempt record. This leaves the second attempt record in an incomplete state (no finish time) and the first attempt record with its exception overwritten.

This happens when the first and second attempt run in the same second.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.