public function runAction()
    {
        $lock = $this->container->get('tenside.taskrun_lock');

        if ($this->getTensideConfig()->isForkingAvailable() && !$lock->lock()) {
            throw new NotAcceptableHttpException('Task already running');
        }

        // Fetch the next queued task.
        $task = $this->getTensideTasks()->getNext();

        if (!$task) {
            throw new NotFoundHttpException('Task not found');
        }

        if ($task::STATE_PENDING !== $task->getStatus()) {
            return $this->createJsonResponse([$this->convertTaskToArray($task)]);
        }

        // Now spawn a runner.
        try {
            $this->spawn($task);
        } finally {
            if ($this->getTensideConfig()->isForkingAvailable()) {
                $lock->release();
            }
        }

        return $this->createJsonResponse([$this->convertTaskToArray($task)]);
    }