yii2-queue icon indicating copy to clipboard operation
yii2-queue copied to clipboard

Incompatible priority values for different drivers

Open antonrybalko opened this issue 7 years ago • 1 comments

Some of drivers support priority queues. But priority values ​​for different drivers are not compatible. I used DB driver and had this code for high priority tasks:

Yii::$app->queue->priority(0)->push($someJob);

By default DB driver sets priority to 1024 and lesser value means higher priority.

Now I move to AMQP Interop driver (RabbitMQ). And I have to rewrite my code for high priority jobs:

Yii::$app->queue->priority(10)->push($someJob);

AMQP Interop maximum priority is 10 by default and higher value means higher priority.

As I see Gearman also supports priorities

PRIORITY METHOD
0 doHighBackground()
1 doBackground()
2 doLowBackground()

I understand that priority value depends on driver. But I'd like to have scalable system and I'd like to have ability to change driver without code rewriting. I propose to add three common priorities to driver classes.

namespace yii\queue\db;

class Queue extends CliQueue
{
    public $priorityLow = 2048;
    public $priorityMedium = 1024;
    public $priorityHigh = 0;
    //...
}
namespace yii\queue\amqp_interop;

class Queue extends CliQueue
{
    public $priorityLow = 1;
    public $priorityMedium = 5;
    public $priorityHigh = 10;
    //...
}
namespace yii\queue\gearman;

class Queue extends CliQueue
{
    public $priorityLow = 'low';
    public $priorityMedium = null;
    public $priorityHigh = 'high';
    //...
}

And use code like

Yii::$app->queue->priority(Yii::$app->queue->priorityHigh)->push($someJob);

Or something like this.

antonrybalko avatar Mar 01 '18 10:03 antonrybalko

It looks like as syntactic sugar to me. Moreover, some brokers aren't support message priorities. This will not work with amqp, file, redis and sqs drivers.

zhuravljov avatar Apr 29 '18 16:04 zhuravljov