The code below doesn't work. I think I have done all things correctly, but somehow I doesn't work.
The job is dispatched like this:
MyJob::dispatch($job)->onQueue('processing')->delay(Carbon::now()->addSeconds(30));
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class MyJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels, Dispatchable;
public function __construct($job)
{
// I described a logging code here and yes, there was change, but then...
}
public function handle()
{
// I described a logging code here, but there wasn't change
}
}
The problem is that dispatchNow()
did work, but dispatch with delay didn't work.
I also set .env correctly(I guess)
QUEUE_CONNECTION=database
'default' => env('QUEUE_CONNECTION', 'sync'),
Diagnostic steps;
Open tinker and run config('queue')
and check that the queue settings are as expected
Without running a queue worker, dispatch your job to the queue. Open your database tools and check that the jobs table contains one new record.
run the queue worker with php artisan queue:work
after the delay, the job should run.
Check that the job has gone from the jobs table, and that nothing is in the failed_jobs table.