'Get CeleryTask status of an APIv2 based task'

def get(self, task_id):

    if current_app.config.get('CELERY_ALWAYS_EAGER'):
        state = TASK_RESULTS[task_id]['state']
        info = TASK_RESULTS[task_id]['result']
    else:
        from app import celery
        result = AsyncResult(id=task_id, app=celery)
        state = result.state
        info = result.info
    if (state == 'SUCCESS'):
        if (type(info) == dict):
            if ('__error' in info):
                return (info['result'], info['result']['code'])
        return jsonify(state='SUCCESS', result=info)
    elif (state == 'FAILURE'):
        return jsonify(state=state)
    else:
        return jsonify(state=state)
