#task_histories

This commit is contained in:
xieshen 2020-11-04 17:10:15 +08:00
parent 7f7cfa3666
commit fe2162ad68
1 changed files with 63 additions and 21 deletions

View File

@ -62,36 +62,78 @@ def alarm(request):
return HttpResponse(json.dumps({
"status": "1",
"name": name,
"res":res
"res": res
}))
def task_histories(request):
histories = []
task_id = []
def task_histories(request):
# task_id = []
# res = []
# row1 = None
# with connection.cursor() as cursor:
# cursor.execute("select * from task_histories order by run_time desc limit 20;")
# row = cursor.fetchall()
# task = []
#
# for r in row:
# task_id.append(r[1])
# o = dict()
# o['status'] = r[2]
# o['run_time'] = r[3]
# o['output'] = r[4][1:-1]
# task.append(o)
#
# with connection.cursor() as cursor1:
# cursor1.execute("select * from tasks where id = '%s' limit 1" % (r[1]))
# row1 = cursor1.fetchone()
# task.append(row1[1])
# task.append(row1[2])
# task.append(row1[8])
# res.append(task)
task_id = []
res = []
row1 = None
with connection.cursor() as cursor:
cursor.execute("select * from task_histories order by run_time desc limit 20;")
cursor.execute("select task_id from task_histories group by task_id ;")
row = cursor.fetchall()
task = []
data = []
for r in row:
task_id.append(r[1])
o = dict()
o['status'] = r[2]
o['run_time'] = r[3]
o['output'] = r[4][1:-1]
task.append(o)
task_id.append(r[0])
# o['status'] = r[2]
# o['run_time'] = r[3]
# o['output'] = r[4][1:-1]
# data.append(o)
print(task_id)
for id in list(set(task_id)):
with connection.cursor() as cursor:
cursor.execute(
"select * from task_histories where task_id = '%s' order by run_time desc limit 20;" % (id))
row = cursor.fetchall()
task = []
for r in row:
task_id.append(r[1])
o = dict()
o['status'] = r[2]
o['run_time'] = r[3]
o['output'] = r[4][1:-1]
task.append(o)
with connection.cursor() as cursor1:
cursor1.execute("select * from tasks where id = '%s' limit 1" % (r[1]))
row1 = cursor1.fetchone()
task.append(row1[1])
task.append(row1[2])
task.append(row1[8])
res.append(task)
cursor1.execute("select * from tasks where id = '%s'" % (id))
row1 = cursor1.fetchall()
print(row1)
for r1 in row1:
o1 = dict()
o1['name'] = r1[1]
o1['type'] = r1[2]
o1['desc'] = r1[8]
o1['data'] = task
res.append(o1)
return HttpResponse(json.dumps({
"status":"1",
"res":res
}))
"status": "1",
"res": res
}))