Answer the question
In order to leave comments, you need to log in
Why do only triggers work in yii2 queues: Queue::EVENT_BEFORE_PUSH and Queue::EVENT_AFTER_PUSH?
Good afternoon,
I configured queue support as in the documentation:
https://github.com/yiisoft/yii2-queue
The queues themselves work fine. Specified 'db' as a driver and created a mysql table as in the dock
Further in the basics:
https://github.com/yiisoft/yii2-queue/blob/master/...
Trying to listen to events. It is most interesting for me to follow:
Queue::EVENT_AFTER_EXEC
ExecEvent
After each successful execution of the task,
But I can’t get into it, although the queue is working successfully. ./yii queue/listen --color --verbose --isolate
----------------------
2018-10-09 14:43:10 [156] common\jobs\DownloadJob (attempt: 1, pid: 4297) - Started
2018-10-09 14:43:11 [156] common\jobs\DownloadJob (attempt: 1, pid: 4297) - Done (0.379 s)
Catching :
EVENT_BEFORE_PUSH
EVENT_AFTER_PUSH
Not catching:
EVENT_BEFORE_EXEC
EVENT_AFTER_EXEC
EVENT_AFTER_ERROR
EVENT_WORKER_START EVENT_WORKER_LOOP
EVENT_WORKER_STOP
Catching
example:
$afterExecAlert = function($event) {
throw new \Exception('Hurra - EVENT_AFTER_EXEC');
};
Yii::$app->queue->on(Queue::EVENT_AFTER_EXEC, $afterExecAlert);
Yii::$app->queue->push(new DownloadJob([
'url' => 'https://picsum.photos/200/500',
'file' => $full_path,
]));
'queue' => [
'class' => \yii\queue\db\Queue::class,
'db' => 'db', // DB connection component or its config
'tableName' => '{{%queue}}', // Table name
'channel' => 'default', // Queue channel key
'mutex' => \yii\mutex\MysqlMutex::class, // Mutex used to sync queries
'as log' => \yii\queue\LogBehavior::class
],
Answer the question
In order to leave comments, you need to log in
Sending and receiving messages occurs in different processes. You hang up an EVENT_AFTER_EXEC handler on the process that sends messages. The worker process knows nothing about this, namely it triggers EVENT_AFTER_EXEC.
Design the event handler as a Behavior (of the LogBehavior type), and connect it to the general config. This will solve the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question