简体   繁体   English

Laravel 配置中的队列排序

[英]Laravel queue ordering in configuration

I know that queue in jobs is where you set the priority of the job, like when I run the command and specifying the queue ordering like this:我知道作业中的队列是您设置作业优先级的地方,例如当我运行命令并指定队列顺序时,如下所示:

php artisan queue:listen --queue=High,Mid,Low

But in Laravel queue config queue.php file there is a queue key in every driver array, ie:但是在 Laravel queue config queue.php文件中,每个驱动程序数组中都有一个队列键,即:

    'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            // this one
            'queue' => 'default',
            'retry_after' => 90,
        ],

What this have to do with jobs?这和工作有什么关系? I've never seen someone changing this!我从来没有见过有人改变这个! I am not seeing exactly what it is or what it has to do with the jobs in Laravel Doc , what the effect of changing this?我没有看到它到底是什么,或者它与Laravel Doc中的工作有什么关系,改变这个有什么影响? and can it be an array of queues or just a string?它可以是一个队列数组还是一个字符串?

When you do this;当你这样做时;

Queue::pushOn('high', new FooJob());

It is going to push into the queue named high .它将推入名为high的队列。 You may change it to mid or low .您可以将其更改为midlow If your queue driver is redis, then it is going to be like these after you push them.如果你的队列驱动是redis,那么你push之后就是这些了。

127.0.0.1:6379> keys *
1) "queues:high"
2) "queues:low"
3) "queues:mid"

If you want to consume these queues you need to execute the following command as you already mentioned;如果您想使用这些队列,您需要执行以下命令,正如您已经提到的;

php artisan queue:listen --queue=High,Mid,Low

If you don't explicitly define any queue while pushing such as;如果您在推送时没有明确定义任何queue ,例如;

Queue::push(new FooJob());
Queue::later(86400, new FooJob());

then it is going to use the default as default since you didn't explicitly define it while pushing.那么它将使用default作为默认值,因为您在推送时没有明确定义它。

127.0.0.1:6379> keys *
1) "queues:default"
2) "queues:default:delayed"

Then you may execute only to listen default queues.然后您可能只执行侦听默认队列。

php artisan queue:listen

For your last question, it has to be string.对于您的最后一个问题,它必须是字符串。 This is the method from RedisQueue class.这是来自RedisQueue class 的方法。

/**
 * Get the queue or return the default.
 *
 * @param  string|null  $queue
 * @return string
 */
protected function getQueue($queue)
{
    return 'queues:'.($queue ?: $this->default);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM