private function acquireLock()
    {
        $this->logger->info('Acquire lock file.');

        if (!$this->lock->lock()) {
            $locked = false;
            $retry  = 3;
            // Try up to 3 times to acquire with short delay in between.
            while ($retry > 0) {
                usleep(1000);
                if ($locked = $this->lock->lock()) {
                    break;
                }
                $retry--;
            }
            if (!$locked) {
                $this->logger->error('Could not acquire lock file.');
                throw new \RuntimeException(
                    'Another task appears to be running. If this is not the case, please remove the lock file.'
                );
            }
        }
    }