yii2-queue
yii2-queue copied to clipboard
Interface
Please add a interface that could use DI and not the service locator
How would you like to use it?
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();
}
Related: https://github.com/yiisoft/yii2/issues/14997
Sounds good. Let's implement it.
Here's something interesting: https://gist.github.com/exileed/27360c5f8d16023cdee3f72cca38bb9d
There's an issue with multiple queues. The code above probably could solve it...
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(/*...*/);
}