Reputation: 51
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'),
Upvotes: 4
Views: 5834
Reputation: 1
You could try clearing your cache as advised above. Additionally, also try to restart the queue
php artisan queue:restart
As for the queue:work question. Yes if you want the queue to run permanently supervisor is a good option to use. A sample config is as below.
[program:my-laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/project/artisan queue:work --queue=QUEUE_NAME--sleep=1 --tries=1
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/path/to/log/file.log
Upvotes: 0
Reputation: 4110
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.
Upvotes: 1