Answer the question
In order to leave comments, you need to log in
How to create a queue and run a worker dynamically in yii2-queue?
The yii2-queue component allows you to create queues using a config like this:
return [
'bootstrap' => [
'queue', // The component registers own console commands
],
'components' => [
'queue' => [
'class' => \yii\queue\redis\Queue::class,
'channel' => 'my-queue',
],
],
];
php yii queue/listen
$queue = new yii\queue\redis\Queue([
'channel' => 'channel_group_' . $i,
]);
$queue->listen(5);
Answer the question
In order to leave comments, you need to log in
My solution:
Derived from redisCommand
use yii\queue\redis\Command;
class RedisCommand extends Command
{
public function actionRun($channel = null)
{
if ($channel !== null) {
$this->queue->channel = $channel;
}
return $this->queue->run(false);
}
}
'queue' => [
'class' => \yii\queue\redis\Queue::class,
'commandClass' => \app\commands\RedisCommand::class,
'redis' => 'redis',
'channel' => 'default', // Queue channel key
'as log' => \yii\queue\LogBehavior::class,
]
yii queue/run 3 channel_group_1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question