Answer the question
In order to leave comments, you need to log in
How to send notification of successfully completed Yii2 Queue worker?
Friends, please help me solve the problem.
There is a GridView in which I implemented the ability to send multiple rows to a task.
Each line (id and title) is sent to a separate task, where a long API request is made.
In the worker, data is received via the API and stored in the corresponding (by id) model.
Everything would be fine, but for the third day I can not decide - how to notify in the interface that such and such a line has received data? You won't understand until you refresh the page and find this row in the table.
It is logical that you can hang the yii\queue\Queue::EVENT_BEFORE_EXEC event and refresh the page by sending session->setFlash(), which I tried to do:
In the config:
'on '.yii\queue\Queue::EVENT_BEFORE_EXEC => function($event) {
$model = new Model;
$model->trigger(Model::EVENT_NAME);
},
public function init()
{
$this->on(Model::EVENT_NAME, function(){
Yii::$app->session->setFlash('success', "Ok");
});
parent::init();
}
'on '.yii\queue\Queue::EVENT_BEFORE_EXEC => function($event) {
Yii::$app->controllerNamespace = "backend\controllers";
Yii::$app->runAction('default/event');
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question