'Adds entry to internal failed list, displayed with --failed'

def add_failed(self, entry, reason=None, config=None, **kwargs):

    reason = (str(reason) or u'Unknown')
    with Session() as session:
        item = session.query(FailedEntry).filter((FailedEntry.title == entry[u'title'])).filter((FailedEntry.url == entry[u'original_url'])).first()
        if (not item):
            item = FailedEntry(entry[u'title'], entry[u'original_url'], reason)
            item.count = 0
        if (item.count > FAIL_LIMIT):
            log.error(u"entry    with    title    '%s'    has    failed    over    %s    times", entry[u'title'], FAIL_LIMIT)
            return
        retry_time = self.retry_time(item.count, config)
        item.retry_time = (datetime.now() + retry_time)
        item.count += 1
        item.tof = datetime.now()
        item.reason = reason
        session.merge(item)
        log.debug(u'Marking    %s    in    failed    list.    Has    failed    %s    times.', item.title, item.count)
        if (self.backlog and (item.count <= config[u'max_retries'])):
            self.backlog.instance.add_backlog(entry.task, entry, amount=retry_time, session=session)
        entry.task.rerun(plugin=u'retry_failed')
