I have the following job:
public function handle(): void
{
//
sleep(5);
echo "hello!";
}
Following controller:
public function index() {
ProcessPodcast::dispatch();
// return redirect('/api');
echo "finished!";
}
and route:
Route::get("/job", [JobTest::class, 'index']);
My problem is basically that the job is not executed in the background as expected. I used the command php artisan queue:work
and accessed the /job route that triggers this job, and what happens is that the page takes 5 seconds to be displayed because of sleep(5), but what I expected is that this delay would not occur and it would only be executed in the background.
I’m trying to use redis for this:
QUEUE_CONNECTION=redis
No error is displayed to me in the terminal, does anyone have any idea what might be happening?
2
Answers
I discovered the problem. It was simply that the information in my .env file was being ignored, so the value for QUEUE_CONNECTION was still being "synced".
Clearing the cache solved it for me:
php artisan config:clear
Be sure your job implement ShouldQueue interface