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';
//...
}
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.
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:
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:
AMQP Interop maximum priority is 10 by default and higher value means higher priority.
As I see Gearman also supports priorities
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.
And use code like
Or something like this.