pastafari2/libraries/check_task.py

41 lines
1 KiB
Python

from time import time
from flask import flash
def check_task_status(flash_text, db, task_id):
first_time=time()
check_task=True
log={'error': 1, 'status': 1, 'message': ''}
while check_task:
with db.query('select * from logtask where task_id=%s order by id DESC limit 1', [task_id]) as cursor:
arr_log=cursor.fetchone()
if arr_log:
if arr_log['status']==1:
check_task=False
if not arr_log['error']:
flash(flash_text)
log=arr_log
return log
if time()-first_time>300:
log['message']='Error: task time out!, view task log!'
log['error']=1
break
return log