What queue driver are you using in config/queue.php? Check QUEUE_DRIVER in your .env file and make sure it's not set to sync because that will execute the jobs immediately.
Queued tasks are executing as part of the controller, causing app to freeze
OK I'm new to job queues in Laravel but I've read all the documentation and I thought I understood them.
My app needs to queue hundreds of jobs to run one-after-another in the background.
I'm testing with dummy jobs first that just log their status, and sometimes error out. Everything seemed to be working. When I ran it, the logs filled right up with hundreds of messages in the correct order.
Since each actual task will take between 5-10 seconds to complete, I added in a simulated delay by putting a sleep() command in the handle function. So I pressed "go" and the app... just... hung. Because it wasn't queueing the tasks after all. It was trying to execute ALL of them before it would load the next page! What am I doing wrong here? Here's the code that calls the job, from inside a controller:
foreach($to_publish as $info){
Publish::dispatch($info);
}
It should be adding it to the queue and running it in the background, right? I don't get it.
Here's the test handle() function I created in the Publish job:
public function handle()
{
try{
if(rand(0,20) < 3){
$x = 1/0;
}
sleep(1);
$this->my_log('info' , 'Published successfully');
} catch (Exception $e) {
$m = $e->getMessage();
$this->my_log('error', $m);
}
}
What did I miss? What am I doing wrong? There's a lot of documentation about setting up workers to handle the tasks but they seemed to just be running so I thought it was setting one up automatically.
Please or to participate in this conversation.