protected function stackIsReady()
    {
        $stacks = $this->describeMainStack();

        if (null === $stacks) {
            return false;
        }

        switch ($stacks[0]['StackStatus']) {
            case 'CREATE_COMPLETE':
            case 'UPDATE_COMPLETE':
            case 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS':
                return true;
            case 'UPDATE_IN_PROGRESS':
            case 'CREATE_IN_PROGRESS':
                $this->logRecentEvents();
            case '':
                return false;
            default:
                sleep(3);
                $this->logRecentEvents();
                throw new \BuildException('Failed to run stack ' . $this->getName() . ' (' . $stacks[0]['StackStatus'] . ') !');
        }
    }