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
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
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
def get_task_status(task_id): task = celery.AsyncResult(task_id) return jsonify({'state': task.state})
def get(self, task_id): task = celery.AsyncResult(task_id) return jsonify(task.result)
def check_task(id): res = celery.AsyncResult(id) if res.state == states.PENDING: return res.state else: return str(res.result)