Use WithoutOverlapping when two jobs may both be queued but must not modify the same resource at the same time. This is different from unique dispatch: overlapping jobs wait or release until the lock is available.
use Illuminate\Queue\Middleware\WithoutOverlapping;
public function middleware(): array
{
return [
(new WithoutOverlapping("account:{$this->accountId}"))
->releaseAfter(30)
->expireAfter(300),
];
}
The lock uses a cache store that supports atomic locks. Since a released job consumes an attempt, set the job's retry limit high enough for the expected contention.