Laravel 7 Job queue handle method is not working

2.4k views Asked by At

I am trying to execute a code after some delay using laravel 7 job queue. The constructor method is working but not the handle method. My code is given below:

Controller:

public function test()
{
    echo 'starting ....';
    $reset = (new ResetLockers())->delay(now()->addSeconds(10));
    dispatch($reset);
}

Job:

class ResetLockers implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    
    public function __construct()
    {
        echo 'constructing ...';
    }

    
    public function handle()
    {
        echo 'job dispatched';
    }
}

database:

enter image description here

output:

enter image description here

any clue?

2

There are 2 answers

3
dlawson90 On

I'm not sure how you have configured your queue, but the handle() method is only called when the job is being processed by your queue. Your code is is just delaying the dispatch by 10 seconds.

0
Rafael Abne On

try updating the

php artisan queue:restart

method and try again if the code is up to date