Still no working. I was trying use database queue driver and delay was working but job dispatching give me SQL errors about deadlock when select in jobs table
Deadlock found when trying to get lock; try restarting transaction (SQL: select * from 'jobs' where 'reserved_at' = 7405457) OR ...
Now, I switch QUEUE_CONNECTION to database and I don't have any errors but jobs work immediate. New rows are added to the jobs table and disappear when delay time. I can't understand this.
I've had similar issues with ->delay() method running straight away, instead of delayed.
To resolve the issue, I first declare the Carbon instance as a variable (without the ->addMinutes(5))
This doesn't work for me (fires jobs straight away)
Me too delay on the dispatched job didn't work instead it processed the jobs immediately without any delays even though I changed the connection from sync to in .env file:
QUEUE_CONNECTION=database
<?php
use App\Jobs\MyJob;
use App\Models\User;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
$user = User::first();
MyJob::dispatch($user)->delay(5); // does not take effects
// MyJob::dispatch($user)->delay(now()->addSeconds(5)); // even this
return view('welcome');
});
when I run job worker by calling
php artisan queue:work
all the jobs are processed immediately without delays
but if I used:
php artisan queue:work --rest=5
everything is fine
can anyone know what's going on?
@Snapey Normally I use:
php artisan queue:work
with the code provided but I noticed that the jobs are processed immediately with no delays even though I chained the delay method with the dispatch.
Actually, the chained delay method does not take effect (exist or not = the same)
the result I would like to get is the same as if you run: