'Add single entry to task backlog
If :amount: is not specified, entry will only be injected on next execution.'

@with_session
def add_backlog(self, task, entry, amount=u'', session=None):

    snapshot = entry.snapshots.get(u'after_input')
    if (not snapshot):
        if (task.current_phase != u'input'):
            log.warning((u'No    input    snapshot    available    for    `%s`,    using    current    state' % entry[u'title']))
        snapshot = entry
    expire_time = (datetime.now() + parse_timedelta(amount))
    backlog_entry = session.query(BacklogEntry).filter((BacklogEntry.title == entry[u'title'])).filter((BacklogEntry.task == task.name)).first()
    if backlog_entry:
        if (backlog_entry.expire < expire_time):
            log.debug((u'Updating    expiry    time    for    %s' % entry[u'title']))
            backlog_entry.expire = expire_time
    else:
        log.debug((u'Saving    %s' % entry[u'title']))
        backlog_entry = BacklogEntry()
        backlog_entry.title = entry[u'title']
        backlog_entry.entry = snapshot
        backlog_entry.task = task.name
        backlog_entry.expire = expire_time
        session.add(backlog_entry)
