Laravel Queues for multi user environment

Home - Laravel Queues for multi user environment

Chintia Widyasari asked 3 years ago

I am using Laravel 5.0, and I have a task that takes around 2 minutes to process, and this task particularly is generating a report…
Now, it is obvious that I can’t make the user wait for 2 minutes on the same page where I took user’s input, instead I should process this task in the background and notify the user later about task completion…
So, to achieve this, Laravel provides Queues that runs the tasks in background (If I didn’t understand wrong), Now for multi-user environment, i.e. if more than one user demands report generation (say there are 4 users), so being the feature named Queues, does it mean that tasks will be performed one after the other (i.e. when 4 users demand for report generation one after other, then 4th user’s report will only be generated when report of 3rd user is generated) ??
If Queues completes their tasks one after other, then is there anyway with which tasks are instantly processed in background, on request of user, and user can get notified later when its task is completed??

1 Answers
Girly Saputri Staff answered 3 years ago

Queue based architecture is little complicated than that. See the Queue provides you an interface to different messaging implementations like rabbitMQ, beanstalkd.
Now at any point in code you send send message to Queue which in this context is termed as a JOB. Now your queue will have multiple jobs which are ready to get out as in FIFO sequence.
As per your questions, there are worker which listens to queue, they get a job and execute them. It’s up to you how many workers you want. If you have one worker your tasks will be executed one after another, more the workers more the parallel processes.
Worker process are started with command line interface of laravel called Artisan. Each process means one worker. You can start multiple workers with supervisor.

Your Answer