public function perform($logFile)
    {
        if (self::STATE_PENDING !== $this->getStatus()) {
            throw new \LogicException('Attempted to run task ' . $this->getId() . ' twice.');
        }

        try {
            if (!is_dir(dirname($logFile))) {
                mkdir(dirname($logFile), 0777, true);
            }

            file_put_contents($logFile, '', FILE_BINARY);

            $this->logFile = $logFile;
            $this->file->set('log', $logFile);

            $this->setStatus(self::STATE_RUNNING);
            $this->addOutput('Task ' . $this->getId() . ' started.' . "\n");

            $this->doPerform();
        } catch (\Exception $exception) {
            $this->addOutput('--------------------------------------------------------' . "\n");
            $this->addOutput('Exception occured: ' . $exception->getMessage() . "\n");
            $this->addOutput($exception->getTraceAsString() . "\n");
            $loopException = $exception;
            while ($loopException = $loopException->getPrevious()) {
                $this->addOutput('Chained exception: ' . $loopException->getMessage() . "\n");
                $this->addOutput($loopException->getTraceAsString() . "\n");
            }
            $this->addOutput('--------------------------------------------------------' . "\n");

            $this->setStatus(self::STATE_ERROR);

            throw new \RuntimeException(
                'Task ' . $this->getId() . ' errored: ' . $exception->getMessage(),
                1,
                $exception
            );
        }

        $this->addOutput('Finished without error.' . "\n");
        $this->setStatus(self::STATE_FINISHED);
    }