Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible priority values for different drivers #217

Open
antonrybalko opened this issue Mar 1, 2018 · 1 comment
Open

Incompatible priority values for different drivers #217

antonrybalko opened this issue Mar 1, 2018 · 1 comment

Comments

@antonrybalko
Copy link

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.

@zhuravljov
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants