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:
output:
any clue?
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.