Hi I am trying to develop some asynchronous functionality in my Yii2 web application.
I have some questions about Yii2-queue that are not answered by the info in the docs here: https://github.com/yiisoft/yii2-queue/tree/master/docs/guide
Most of my questions refer to the Usage page: https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/usage.md
1. Does a job execute immediately?If I push a job to a queue with no delay(), does execution start immediately?
2. queue property in Application class
The code to push a job to the queue:
Yii::$app->queue->push(new DownloadJob([ 'url' => 'http://example.com/image.jpg', 'file' => '/tmp/image.jpg', ]));
Yii Application class does not have a "queue" property. Is the "Yii::$app->queue" possible because of the Yii2-queue extension? [b]
- job property in Event class [/b]Code to push the job back into the queue after it’s had an error:
Yii::$app->queue->on(Queue::EVENT_AFTER_ERROR, function ($event) { if ($event->error instanceof TemporaryUnprocessableJobException) { $queue = $event->sender; $queue->delay(7200)->push($event->job); } });
[font=“Arial”]Similar to the question 1 above, the Event class does not have a “job” property. Is that also put there by the queue extension? Does that “job” property contain the data that was set to it before I originally pushed it to the queue? I need to show a progress bar that updates each time a job is completed. So I need to know which task was completed. I’m thinking of putting an ID or something as a member variable in the job class. [/font] [b]
- Job is run inside my Yii application? [/b]The docs mention Console operation and Cron in many places. I just want to execute code in my Yii application, without needing anything else.In the job’s execute() I may need access to my session state variables (not sure yet). Is this OK? Or is this queue extension designed for scheduling jobs for Console and Cron? If so it would help to know soon so I can find another solution.