lockManager->lock(self::LOCK_NAME, 0)) { throw new \RuntimeException('Warehouse synchronization is already running.'); } try { $warehouses = $this->fetcher->fetchAll(); foreach ($warehouses as $warehouse) { $this->repository->saveMetadata($warehouse); } return ['warehouses' => count($warehouses)]; } finally { $this->lockManager->unlock(self::LOCK_NAME); } } }