pierophp/laravel-queue-manager

Laravel Queue Manager

v0.0.66 2022-01-18 19:27 UTC

README

The Laravel Queue Manager, manage the queue process worker.

It uses Supervisor as Process Control System.

It also has a scheduler system built-in.

Installation

Composer

$ composer require pierophp/laravel-queue-manager

Publish

$ php artisan vendor:publish --provider="LaravelQueueManager\Providers\LaravelQueueManagerServiceProvider"

Running the migration

If you have MySQL version before 5.7, change in the migration the field "schedule_config" from "json" to "text".

$ php artisan migrate

Adding the provider

You need to add the provider at the file config/app.php

LaravelQueueManager\Providers\LaravelQueueManagerServiceProvider::class,

Configuration

Generating a job

You need generate a class that extends LaravelQueueManager\AbstractJob.

It's necessary to implement 2 methods:

Dispatching a new job

You need create a new instance of your job and call the dispatch() method.

Or use the CLI:

$ php artisan queue-manager:generate-queue queue_name

You can set optional params too:

$ php artisan queue-manager:generate-queue queue_name foo=test,bar=test

Database

To the job work correctly, it is necessary generate a row in the queue_config table.

Config field example
{
  "nextQueues":{
    "onError":[
      {
        "url":"url/test",
        "data":{
          "param":value
        },
        "name":"QUEUE_NAME",
        "method":"POST",
        "service":"SERVICE",
        "delay_seconds":1
      },
      {
        "url":"url/test",
        "data":{
          "param":value
        },
        "name":"QUEUE_NAME",
        "method":"GET",
        "service":"SERVICE",
        "delay_seconds":1
      }
    ],
    "onSuccess":[
      {
        "url":"url/test",
        "data":{
          "param":value
        },
        "name":"QUEUE_NAME",
        "method":"POST",
        "service":"SERVICE",
        "delay_seconds":1
      }
    ]
  }
}

Config

At the queue_manager.php config file you can configure:

Showing all available jobs

$ php artisan queue-manager:show-jobs

Getting error events

You need add to your AppServiceProvider and log as you like:

$this->app['events']->listen(\LaravelQueueManager\Events\ScheduleError::class, function(\LaravelQueueManager\Events\ScheduleError $error){
    // my code
});

$this->app['events']->listen(\LaravelQueueManager\Events\DispatchQueueError::class, function(\LaravelQueueManager\Events\DispatchQueueError $error){
    // my code
});

Deploying

Supervisor config

You need configure a cron to run as root every minute to generate the supervisor config

$ php artisan queue-manager:generate-config

Scheduler

You need configure a cron to run every minute to generate the scheduler

$ php artisan schedule:run

Queue Restart

Every time you change the PHP code, it's necessary to restart the queues. Put this at your deploy script.

$ php artisan queue:restart

API Mode

Introduction

To easily scale your jobs machine, you can run the queues in API mode. An API is much more easy to apply auto-scale.

Configuration

In your route configuration file add:

$api->post('queue/process', 'LaravelQueueManager\Http\Controllers\QueueController@process');

Edit in your "queue_manager.php" config file the execute_as_api and api_url options.