Laravel程序员

laravel config queue

2017-12-17  本文已影响23人  3275508ab630

queue.php

default 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Default Queue Driver
    |--------------------------------------------------------------------------
    |
    | Laravel's queue API supports an assortment of back-ends via a single
    | API, giving you convenient access to each back-end using the same
    | syntax for each one. Here you may set the default queue driver.
    |
    | Supported: "sync", "database", "beanstalkd", "sqs", "redis", "null"
    |
    */

    'default' => env('QUEUE_DRIVER', 'sync'),
    /*
    |--------------------------------------------------------------------------
    | 默认队列驱动
    |--------------------------------------------------------------------------
    |
    | Laravel的队列API通过单个API支持各种后端,
    | 为每个后端使用相同的语法提供方便的访问。 
    | 在这里你可以设置默认的队列驱动程序。
    |
    | 支持: "sync", "database", "beanstalkd", "sqs", "redis", "null"
    |
    */

    'default' => env('QUEUE_DRIVER', 'sync'),

个人理解:队列的默认执行方式。sync 是直接执行, null 是不使用队列。

connections 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Queue Connections
    |--------------------------------------------------------------------------
    |
    | Here you may configure the connection information for each server that
    | is used by your application. A default configuration has been added
    | for each back-end shipped with Laravel. You are free to add more.
    |
    */

    'connections' => [...],
    /*
    |--------------------------------------------------------------------------
    | 队列连接
    |--------------------------------------------------------------------------
    |
    | 在这里,您可以为应用程序使用的每个服务器配置连接信息。
    |  Laravel附带的每个后端都添加了默认配置。 你可以自由添加更多。
    | 
    |
    */

    'connections' => [...],

个人理解:各个驱动的连接配置。redis 连接方式可以改一下,与 session cache 分开存储。文档原文:
config/queue.php 配置文件里,每一个队列连接都定义了一个 retry_after 选项。这个选项指定了任务最多处理多少秒后就被当做失败重试了。比如说,如果这个选项设置为 90,那么当这个任务持续执行了 90 秒而没有被删除,那么它将被释放回队列。通常情况下,你应该把 retry_after 设置为最长耗时的任务所对应的时间。
queue:work Artisan 命令对外有一个 --timeout 选项。这个选项指定了 Laravel 队列处理器最多执行多长时间后就应该被关闭掉。有时候一个队列的子进程会因为很多原因僵死,比如一个外部的 HTTP 请求没有响应。这个 --timeout 选项会移除超出指定事件限制的僵死进程。

php artisan queue:work --timeout=60

retry_after 配置选项和 --timeout 命令行选项是不一样的,但是可以同时工作来保证任务不会丢失并且不会重复执行。
--timeout 应该永远都要比 retry_after 短至少几秒钟的时间。这样就能保证任务进程总能在失败重试前就被杀死了。如果你的 --timeout 选项大于 retry_after 配置选项,你的任务可能被执行两次。

failed 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Failed Queue Jobs
    |--------------------------------------------------------------------------
    |
    | These options configure the behavior of failed queue job logging so you
    | can control which database and table are used to store the jobs that
    | have failed. You may change them to any database / table you wish.
    |
    */

    'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],
    /*
    |--------------------------------------------------------------------------
    | 失败的队列任务
    |--------------------------------------------------------------------------
    |
    | 这些选项配置失败的队列作业日志记录的行为, 
    | 以便可以控制使用哪个数据库和表来存储失败的作业。
    | 您可以将它们更改为任何您希望的数据库/表格。
    |
    */

    'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],

个人理解:失败任务存储位置,以供重试。看起来只能存在数据库里。

上一篇下一篇

猜你喜欢

热点阅读