예제 #1
0
def get_chat(task_id):
    task = celery.AsyncResult(task_id)
    if task.state == 'SUCCESS':
        if isinstance(task.result, list):
            return jsonify(task.result)
        else:
            return jsonify({'msg': task.result}), 400
    else:
        return jsonify({'msg': 'Task did not succeed.'}), 400
예제 #2
0
def download_csv(task_id):
    task = celery.AsyncResult(task_id)
    if task.state == 'SUCCESS':
        filename = f'{task_id}.csv'
        with open(filename, 'w', newline='', encoding='utf-8') as output_file:
            dict_writer = csv.DictWriter(output_file, task.result[0].keys())
            dict_writer.writeheader()
            dict_writer.writerows(task.result)
        return send_file(filename)
    else:
        return jsonify({'error': 'Task did not succeed.'}), 400
예제 #3
0
def start_chat_task():
    url = request.json.get('url')
    sc_only_postfix = '-sc' if request.json.get('scOnly') else ''
    video_id = get_video_id(url)
    if not video_id:
        return jsonify({'msg': 'Not a valid YouTube link'}), 400
    task_id = video_id + sc_only_postfix
    task = celery.AsyncResult(task_id)
    if not task.state == CUSTOM_SENT_STATE:
        print(f'Queued new task with id {task_id}')
        task = retrieve_chat.apply_async((url, request.json.get('scOnly')),
                                         task_id=task_id)
        return jsonify({'id': task.id}), 202
    return jsonify({'id': task.id}), 200
예제 #4
0
def get_task_status(task_id):
    task = celery.AsyncResult(task_id)
    return jsonify({'state': task.state})
예제 #5
0
 def get(self, task_id):
     task = celery.AsyncResult(task_id)
     return jsonify(task.result)
예제 #6
0
파일: app.py 프로젝트: tegia/demo-celery
def check_task(id):
    res = celery.AsyncResult(id)
    if res.state == states.PENDING:
        return res.state
    else:
        return str(res.result)