'Updates the counters per state of the tasks that were running. Can re-add
to tasks to run in case required.
:param ti_status: the internal status of the backfill job tasks
:type ti_status: BackfillJob._DagRunTaskStatus'

def _update_counters(self, ti_status):

    for (key, ti) in list(ti_status.started.items()):
        ti.refresh_from_db()
        if (ti.state == State.SUCCESS):
            ti_status.succeeded.add(key)
            self.logger.debug(u"Task    instance    {}    succeeded.    Don't    rerun.".format(ti))
            ti_status.started.pop(key)
            continue
        elif (ti.state == State.SKIPPED):
            ti_status.skipped.add(key)
            self.logger.debug(u"Task    instance    {}    skipped.    Don't    rerun.".format(ti))
            ti_status.started.pop(key)
            continue
        elif (ti.state == State.FAILED):
            self.logger.error(u'Task    instance    {}    failed'.format(ti))
            ti_status.failed.add(key)
            ti_status.started.pop(key)
            continue
        elif (ti.state == State.UP_FOR_RETRY):
            self.logger.warning(u'Task    instance    {}    is    up    for    retry'.format(ti))
            ti_status.started.pop(key)
            ti_status.to_run[key] = ti
        elif (ti.state == State.NONE):
            self.logger.warning(u'FIXME:    task    instance    {}    state    was    set    to    None    externally    or    reaching    concurrency    limits.    Re-adding    task    to    queue.'.format(ti))
            session = settings.Session()
            ti.set_state(State.SCHEDULED, session=session)
            session.close()
            ti_status.started.pop(key)
            ti_status.to_run[key] = ti
