2

I have a fresh Laravel 10 app and I'm trying to test queues.

I created a job with php artisan make:job TestJob.

routes/web.php

Route::get('/test-job', function () {
    \App\Jobs\TestJob::dispatch();
    return 'Job dispatched';
});

.env

QUEUE_CONNECTION=database

TestJob.php

<?php
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    public function __construct() { /**/ }

    public function handle()
    {
        \Log::info('TestJob executed successfully.');
    }
}

When the job runs, it should write a log entry to storage/logs/laravel.log.

Ran migrations and started the worker:

php artisan queue:work

Problem: When I visit /test-job, the job gets added to the jobs table, but it never executes.

Question: What configuration step am I missing to ensure my Laravel 10 jobs execute with the database queue?

5
  • Yes, I’ve checked the logs (storage/logs/laravel.log), and there are no errors recorded when dispatching the job. The job is added to the jobs table, but the worker does not seem to process it. Commented Sep 16 at 6:53
  • before launching the queue, did you check the table jobs in your database if the job got inserted correctly. after launching queue, you can check the table again. if the entry disappeared then it launched successfully, otherwise it would have failed count increased Commented Sep 16 at 9:52
  • Clear cached config php artisan config:clear Commented Sep 19 at 11:49
  • If you haven’t tried any other debugging methods and are relying only on the log entry to confirm execution, I’d suggest adding a simple fallback like file_put_contents() in the handle() method. For example, write to public/job-executed.txt to verify the job ran. It’s a quick way to rule out logging issues and confirm the job is actually being processed. Commented Oct 4 at 6:24
  • 1) Is there any two database connection please (check are there any tow relation databases configed or a redis connection) ? 2) Please provide "config/queue.php" and "config/database.php" 3) Try "php artisan queue:work database" 4) In the job class constructor set "$this->onConnection('database');" . 5) Try to create a instance of the job class and dispatch ,dont execute statically in the route . 6) If you are using docker check are there any other containers running with the queue worker . Commented Oct 19 at 18:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.