Exemplo n.º 1
0
def taskstatus(task_id):
    from app.tasks import long_task
    task = long_task.AsyncResult(task_id)
    if task.state == 'PENDING':
        # job did not start yet
        response = {
            'state': task.state,
            'current': 0,
            'total': 1,
            'status': 'Pending...'
        }
    elif task.state != 'FAILURE':
        response = {
            'state': task.state,
            'current': task.info.get('current', 0),
            'total': task.info.get('total', 1),
            'status': task.info.get('status', '')
        }
        if 'result' in task.info:
            response['result'] = task.info['result']
    else:
        # something went wrong in the background job
        response = {
            'state': task.state,
            'current': 1,
            'total': 1,
            'status': str(task.info),  # this is the exception raised
        }
    return jsonify(response)
Exemplo n.º 2
0
 def get(self):
     tid = request.args.get("id")
     print(tid)
     r = long_task.AsyncResult(tid)
     if r.status == 'SUCCESS':
         return {"msg": r.get()}
     return {"msg": r.status}
Exemplo n.º 3
0
 def get(self, task_id):
     from app.tasks import long_task
     current_app.logger.debug("{} {}".format(request.method,
                                             request.url_rule))
     task = long_task.AsyncResult(task_id)
     current_app.logger.info(
         "Task (id: {}, state: {}, queue: {}) is retrieved from backend {}."
         .format(task.task_id, task.state, task.queue, task.backend))
     return {"state": task.state}
Exemplo n.º 4
0
def taskprogress(task_id):
    # 获取异步任务结果
    task = long_task.AsyncResult(task_id)
    # 等待处理
    if task.state == 'PENDING':
        response = {'state': task.state, 'current': 0, 'total': 1}
    elif task.state != 'FAILURE':
        response = {'state': task.state, 'current': task.info.get('current', 0), 'total': task.info.get('total', 1)}
        # 处理完成
        if 'result' in task.info:
            response['result'] = task.info['result']
    else:
        # 后台任务出错
        response = {'state': task.state, 'current': 1, 'total': 1}
    return jsonify(response)
Exemplo n.º 5
0
def inspect(task_id):
    from app.tasks import long_task

    # checking for a running task
    if not task_id:
        return make_response(jsonify({
            "msg": "there is no task running",
        }), 400)

    # retreiving the task states
    task = long_task.AsyncResult(task_id)
    return make_response(
        jsonify({
            "state": str(task.state),
            "info": task.info
        }), 200)
Exemplo n.º 6
0
def get_status():
    # checking for a running task
    task_id = r.get('taskid')
    if not task_id:
        return make_response(jsonify({
            "msg": "there is no task running",
        }), 400)

    # retreiving the task states
    from app.tasks import long_task
    task = long_task.AsyncResult(task_id)
    return make_response(
        jsonify({
            "task_id": task.id,
            "task_state": task.state,
            "data": task.info
        }), 200)
Exemplo n.º 7
0
def press_button():
    from app.tasks import long_task
    # checking for a running task
    task_id = r.get('taskid')
    if task_id:
        task = long_task.AsyncResult(task_id)
        if task.state == "PENDING" or task.state == "PROGRESS":
            return make_response(
                jsonify({
                    "msg": "there is another task running",
                    "task": task.id
                }), 429)

    # creating a new task
    task = long_task.apply_async()
    return make_response(jsonify({
        "state": task.state,
        "id": task.id,
    }), 200)