def refresh_status(tiid, myredis):
    task_ids = myredis.get_provider_task_ids(tiid)

    if not task_ids:
        status = "SUCCESS: no recent refresh"
        return {"short": status, "long": status}

    statuses = {}

    if "STARTED" in task_ids:
        if (len(task_ids) > 1):
            task_ids.remove("STARTED")
        else:
            status = "started_queueing"
            return {"short": status, "long": status}

    for task_id in task_ids:
        task_result = AsyncResult(task_id)
        try:
            state = task_result.state
        except __HOLE__:
            state = "unknown_state" 
        
        statuses[task_id] = state

    # logger.debug(u"refresh_status statuses: tiid={tiid}, statuses={statuses}".format(
    #     tiid=tiid, statuses=statuses))

    done_updating = all([(status.startswith("SUCCESS") or status.startswith("FAILURE")) for status in statuses.values()])
    has_failures = any([status.startswith("FAILURE") for status in statuses.values()])
    has_pending = any([status.startswith("PENDING") for status in statuses.values()])
    has_started = any([status.startswith("STARTED") for status in statuses.values()])

    status_short = "unknown"
    if done_updating and not has_failures:
        status_short = u"SUCCESS: refresh finished"
    elif done_updating and has_failures:
        status_short = u"SUCCESS with FAILURES"
    elif has_failures:
        status_short = u"SUCCESS with FAILURES (and not all providers ran)"
    elif has_pending:
        status_short = u"PENDING"
    elif has_started:
        status_short = u"STARTED"

    status_long = u"{status_short}; task_ids: {statuses}".format(
        status_short=status_short, statuses=statuses)


    # if not refresh_status.startswith("SUCCESS"):
    #     # logger.debug(u"refresh_status: task_id={task_id}, refresh_status={refresh_status}, tiid={tiid}".format(
    #     #     task_id=task_id, refresh_status=refresh_status, tiid=tiid))
    #     pass

    return {"short": status_short, "long": status_long}
dataset/ETHPy150Open Impactstory/total-impact-webapp/totalimpactwebapp/product.py/refresh_status