yiisoft / yiisoft/yii2-queue

Incompatible priority values for different drivers

Open
#217 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:under discussion type:enhancement
Dominant language
PHP
Stars
1.1k
Forks
285
Avg merge
5d 3h
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the DB, AMQP Interop, and Gearman Queue classes and the existing priority API first. Define how shared low, medium, and high priorities should map to each driver, then verify that callers can change drivers without rewriting priority values and that the supported drivers are covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, rabbitmq
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.