task_update.py
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# coding=utf-8
#author: 4N
#createtime: 2020/9/4
#email: nheweijun@sina.com
from ..models import db,Task,Process
from app.util.component.ApiTemplate import ApiTemplate
import datetime
import json
import uuid
class Api(ApiTemplate):
api_name = "任务更新"
def para_check(self):
if not self.para.get("task_guid"):
raise Exception("缺乏task_guid参数。")
def process(self):
res = {}
try:
task_guid = self.para.get("task_guid")
msg = self.para.get("msg")
task:Task = Task.query.filter_by(guid=task_guid)
update = json.loads(self.para.get("update"))
update["update_time"] = datetime.datetime.now()
task.update(update)
if msg:
message = "{} {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msg)
task_process_guid = uuid.uuid1().__str__()
task_process = Process(guid=task_process_guid, message=message, time=datetime.datetime.now(),
task_guid=task_guid)
db.session.add(task_process)
db.session.commit()
except Exception as e:
raise e
return res
api_doc={
"tags":["任务接口"],
"parameters":[
{"name": "task_guid",
"in": "formData",
"type": "string"},
{"name": "update",
"in": "formData",
"type": "string"},
{"name": "msg",
"in": "formData",
"type": "string"},
],
"responses":{
200:{
"schema":{
"properties":{
}
}
}
}
}