task_kill.py
1.8 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
62
63
64
65
66
67
68
69
# coding=utf-8
#author: 4N
#createtime: 2020/9/4
#email: nheweijun@sina.com
from ..models import db,Task,Table
from app.util.component.ApiTemplate import ApiTemplate
import os
import signal
import platform
class Api(ApiTemplate):
api_name = "停止任务"
def para_check(self):
pass
def process(self):
res = {}
try:
task_guid = self.para.get("task_guid")
task = Task.query.filter_by(guid=task_guid).one_or_none()
pid = task.task_pid
if platform.system().lower().__contains__("windows"):
os.popen('taskkill.exe /pid:' + str(pid))
else:
os.kill(pid,signal.SIGILL)
#处理kill任务后的事情
self.fix_task()
res["msg"] = "Kill成功!"
res["result"] = True
except Exception as e:
db.session.rollback()
raise e
return res
def fix_task(self,task):
if task.task_type==1:
pass
if task.task_type==2:
table = Table.query.filter_by(guid=task.table_guid).one_or_none()
if len(table.relate_table_vacuates.all())>0:
Table.query.filter_by(guid=task.table_guid).update({"is_vacuate":1})
if task.task_type==3:
pass
if task.task_type==3:
pass
db.session.commit()
api_doc = {
"tags": ["任务接口"],
"parameters": [
{"name": "task_guid",
"in": "formData",
"type": "string"},
],
"responses": {
200: {
"schema": {
"properties": {
}
}
}
}
}