use Illuminate\Support\Facades\Cache;
public function handle()
{
$lock = Cache::lock('order_' . $this->order->id, 10); // 10 seconds TTL
if ($lock->get()) {
try {
// Process the order safely
$this->order->process();
} finally {
$lock->release();
}
} else {
Log::warning('Order already being processed: ' . $this->order->id);
}
}
Add retries for jobs that fail to acquire the lock: