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

Interface

Open exileed opened this issue 7 years ago • 7 comments

Please add a interface that could use DI and not the service locator

exileed avatar Nov 10 '17 10:11 exileed

How would you like to use it?

samdark avatar Nov 10 '17 10:11 samdark

in config

'queue'       => [
			'class' => (YII_DEBUG)? \yii\queue\file\Queue::class : \yii\queue\redis\Queue::class,
		],

Controllers, Services, Classes

public function __construction(QueueInterface $queue){
$this->queue = $queue;
}
public function test(){
$this->queue->push();
}

exileed avatar Nov 10 '17 10:11 exileed

Related: https://github.com/yiisoft/yii2/issues/14997

rob006 avatar Nov 10 '17 11:11 rob006

Sounds good. Let's implement it.

samdark avatar Nov 10 '17 11:11 samdark

Here's something interesting: https://gist.github.com/exileed/27360c5f8d16023cdee3f72cca38bb9d

samdark avatar Nov 10 '17 19:11 samdark

There's an issue with multiple queues. The code above probably could solve it...

samdark avatar Nov 10 '17 19:11 samdark

To include queue component by DI, add a difinition to your container config:

'container' => [
    'definitions' => [
        \yii\queue\Queue::class => function () {
            return \Yii::$app->myDefaultQueue;
        },
    ],
],

And use:

public function __construct(\yii\queue\Queue $queue)
{
    $this->queue = $queue;
}

public function test()
{
    $this->queue->push(/*...*/);
}

zhuravljov avatar Nov 10 '17 19:11 zhuravljov