定制 pierophp/laravel-queue-manager 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pierophp/laravel-queue-manager

Composer 安装命令:

composer require pierophp/laravel-queue-manager

包简介

Laravel Queue Manager

README 文档

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:

Method Description
getName() The name of the job
execute() The code of the job yourself

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.

Field Description
name It's the same of the return of the getName() method.
class_name The full path with namespace of your job class (\App\Jobs\TestJob)
active If the job is active or not
schedulable If the job is schedulable or not
schedule_config A JSON config of the schedule. {"method" : "The schedule methods from laravel", "params": "The params to the schedule method (optional)", "props": [ { "my_job_prop": 1 }, { "my_job_prop": 2 } ]}
max_attemps The max attempts of the queue
max_instances The max parallel instances of the queue
timeout The timeout of the queue
delay The delay to the next execution (Not implemented yet)
connection The connection name of the queue provider. (If null = default)
aggregator The aggregator is used to group the queues in a report
config The config is used to configure a dynamic functionality. Example json below
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:

Field Description Default
artisan_path The artisan path base_path('artisan')
log_path The log path storage_path('logs/worker.log')
supervisor_config_file The supervisor config file /etc/supervisor/conf.d/laravel-queue.conf
supervisor_bin The supervisor bin path /usr/bin/supervisorctl
supervisor_user The supervisor user docker
supervisor_update_timeout The supervisor update timeout to gracefully stop the process when a configuration change 600
execute_as_api Enable the queue as API mode false
api_url URL to run the queue as API mode http://127.0.0.1/queue/process
fallback_connections Array of fallback connections when first provider fails to dispatch []

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.

pierophp/laravel-queue-manager 适用场景与选型建议

pierophp/laravel-queue-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.35k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2016 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「laravel」 「supervisor」 「queue-manager」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pierophp/laravel-queue-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pierophp/laravel-queue-manager 我们能提供哪些服务?
定制开发 / 二次开发

基于 pierophp/laravel-queue-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-23