digbang/safe-queue

一个适用于Laravel Doctrine的友好的守护进程化队列工作进程,用于Laravel

v1.1.0 2022-02-25 14:24 UTC

This package is auto-updated.

Last update: 2024-09-25 20:05:44 UTC


README

一个安全用于与Laravel Doctrine一起使用的Laravel队列工作进程

何时使用SafeQueue

  • 您使用Laravel 6或更高版本
  • 您使用Laravel Doctrine
  • Devops说queue:listen的CPU使用率不可接受
  • 您想在没有触发级联EntityManager is closed异常的情况下使用php artisan queue:work --daemon

兼容性

工作原理

SafeQueue通过覆盖Laravel功能的一小部分,使得队列工作进程守护程序在使用Doctrine时更加安全。它确保在发生异常后,如果EntityManager被关闭,则工作进程退出。为了万无一失,它还在处理每个工作之前清除EM。

安装

使用composer安装

composer require digbang/safe-queue

一旦您有了代码,请将以下内容添加到app.php中的服务提供者中

Digbang\SafeQueue\DoctrineQueueProvider::class
Lumen

创建配置文件config/safequeue.php并加载:$app->configure('safequeue');

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Worker Command Name
    |--------------------------------------------------------------------------
    |
    | Configure the signature / name of the Work Command here. The default
    | is to rename the command to 'doctrine:queue:work', however you can
    | rename it to whatever you want by changing this value.
    |
    | To override the Laravel 'queue:work' command name just set this
    | to a false value or 'queue:work'.
    |
    */
    'command_name' => 'doctrine:queue:work',

];

使用方法

php artisan doctrine:queue:work  connection --daemon --sleep=3 --tries=3 ...

所有选项与Laravel自己的queue:work方法相同。