/** * @param string $queueName * @param string $priority * @param int $nbTries * * @return AdapterInterface * @throws \Exception */ private function deleteQueueLock($queueName, $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new InvalidArgumentException('Queue ' . $queueName . " doesn't exist, please create it before use it."); } $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new \Exception('Lock timeout for file ' . $queueFilePath); } usleep(10); return $this->deleteQueueLock($queueName, $priority, $nbTries + 1); } $this->fs->remove($queueFilePath); $lockHandler->release(); return $this; }
/** * @param string $queueName * @param Priority $priority * @param int $nbTries * * @return AdapterInterface * @throws QueueAccessException */ private function deleteQueueLock($queueName, Priority $priority, $nbTries = 0) { if (!$this->fs->exists($this->getQueuePath($queueName, $priority))) { throw new QueueAccessException("Queue " . $queueName . " doesn't exist, please create it before using it."); } $queueFilePath = $this->getQueuePath($queueName, $priority); $lockHandler = $this->lockHandlerFactory->getLockHandler($queueFilePath); if (!$lockHandler->lock()) { if ($nbTries >= static::MAX_LOCK_TRIES) { throw new QueueAccessException('Reach max retry for locking queue file ' . $queueFilePath); } usleep(10); return $this->deleteQueueLock($queueName, $priority, $nbTries + 1); } $this->fs->remove($queueFilePath); $lockHandler->release(); return $this; }