正在显示
6 个修改的文件
包含
206 行增加
和
11 行删除
| @@ -11,6 +11,7 @@ from . import task_detail | @@ -11,6 +11,7 @@ from . import task_detail | ||
| 11 | from . import task_delete | 11 | from . import task_delete |
| 12 | from . import task_count | 12 | from . import task_count |
| 13 | from . import task_kill | 13 | from . import task_kill |
| 14 | +from . import task_update | ||
| 14 | from app.decorators.token_decorator import token_decorator | 15 | from app.decorators.token_decorator import token_decorator |
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -64,3 +65,13 @@ class DataManager(BlueprintApi): | @@ -64,3 +65,13 @@ class DataManager(BlueprintApi): | ||
| 64 | 任务统计 | 65 | 任务统计 |
| 65 | """ | 66 | """ |
| 66 | return task_count.Api().result | 67 | return task_count.Api().result |
| 68 | + | ||
| 69 | + | ||
| 70 | + @staticmethod | ||
| 71 | + @bp.route('/Update', methods=['POST']) | ||
| 72 | + @swag_from(task_update.Api.api_doc) | ||
| 73 | + def task_update(): | ||
| 74 | + """ | ||
| 75 | + 任务信息更新 | ||
| 76 | + """ | ||
| 77 | + return task_update.Api().result |
app/modules/data/task/task_update.py
0 → 100644
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2020/9/4 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +from ..models import db,Task,Process | ||
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 8 | +import datetime | ||
| 9 | +import json | ||
| 10 | +import uuid | ||
| 11 | +class Api(ApiTemplate): | ||
| 12 | + api_name = "任务更新" | ||
| 13 | + def para_check(self): | ||
| 14 | + if not self.para.get("task_guid"): | ||
| 15 | + raise Exception("缺乏task_guid参数。") | ||
| 16 | + | ||
| 17 | + def process(self): | ||
| 18 | + | ||
| 19 | + res = {} | ||
| 20 | + try: | ||
| 21 | + task_guid = self.para.get("task_guid") | ||
| 22 | + msg = self.para.get("msg") | ||
| 23 | + task:Task = Task.query.filter_by(guid=task_guid) | ||
| 24 | + task.update(json.loads(self.para.get("update"))) | ||
| 25 | + | ||
| 26 | + if msg: | ||
| 27 | + message = "{} {}".format(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), msg) | ||
| 28 | + task_process_guid = uuid.uuid1().__str__() | ||
| 29 | + task_process = Process(guid=task_process_guid, message=message, time=datetime.datetime.now(), | ||
| 30 | + task_guid=task_guid) | ||
| 31 | + db.session.add(task_process) | ||
| 32 | + db.session.commit() | ||
| 33 | + except Exception as e: | ||
| 34 | + raise e | ||
| 35 | + return res | ||
| 36 | + | ||
| 37 | + api_doc={ | ||
| 38 | + "tags":["任务接口"], | ||
| 39 | + "parameters":[ | ||
| 40 | + {"name": "task_guid", | ||
| 41 | + "in": "formData", | ||
| 42 | + "type": "string"}, | ||
| 43 | + {"name": "update", | ||
| 44 | + "in": "formData", | ||
| 45 | + "type": "string"}, | ||
| 46 | + {"name": "msg", | ||
| 47 | + "in": "formData", | ||
| 48 | + "type": "string"}, | ||
| 49 | + | ||
| 50 | + ], | ||
| 51 | + "responses":{ | ||
| 52 | + 200:{ | ||
| 53 | + "schema":{ | ||
| 54 | + "properties":{ | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + } |
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | #createtime: 2021/7/19 | 3 | #createtime: 2021/7/19 |
| 4 | #email: nheweijun@sina.com | 4 | #email: nheweijun@sina.com |
| 5 | 5 | ||
| 6 | - | 6 | +import configure |
| 7 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | from app.util.component.StructurePrint import StructurePrint | 8 | from app.util.component.StructurePrint import StructurePrint |
| 9 | from app.models import db | 9 | from app.models import db |
| @@ -35,8 +35,7 @@ class Api(ApiTemplate): | @@ -35,8 +35,7 @@ class Api(ApiTemplate): | ||
| 35 | state=0, | 35 | state=0, |
| 36 | task_type=5, | 36 | task_type=5, |
| 37 | creator=self.para.get("creator"), | 37 | creator=self.para.get("creator"), |
| 38 | - process="影像创建金字塔中", | ||
| 39 | - task_pid=pyramid_process.pid) | 38 | + process="影像创建金字塔中") |
| 40 | 39 | ||
| 41 | db.session.add(task) | 40 | db.session.add(task) |
| 42 | db.session.commit() | 41 | db.session.commit() |
| @@ -62,17 +61,20 @@ class Api(ApiTemplate): | @@ -62,17 +61,20 @@ class Api(ApiTemplate): | ||
| 62 | task_writer.update_process("开始创建...") | 61 | task_writer.update_process("开始创建...") |
| 63 | 62 | ||
| 64 | url = "{}/API/Service/Image/BuildPyramid".format(para.get("url")) | 63 | url = "{}/API/Service/Image/BuildPyramid".format(para.get("url")) |
| 64 | + | ||
| 65 | + | ||
| 66 | + self.para["from"] = configure.deploy_ip_host | ||
| 67 | + self.para["task_guid"] = task_guid | ||
| 68 | + | ||
| 65 | response:requests.Response = requests.post(url,data=self.para) | 69 | response:requests.Response = requests.post(url,data=self.para) |
| 66 | 70 | ||
| 67 | if not response.json().get("result"): | 71 | if not response.json().get("result"): |
| 68 | raise Exception("由于{},影像服务修改失败!".format(response.json().get("msg"))) | 72 | raise Exception("由于{},影像服务修改失败!".format(response.json().get("msg"))) |
| 69 | - | ||
| 70 | - task_writer.update_task({"state":1,"update_time":datetime.datetime.now(),"process" : "创建完成"}) | ||
| 71 | - task_writer.update_process("创建完成!") | ||
| 72 | - | 73 | + else: |
| 74 | + task_writer.update_task({"task_pid": int(response.json().get("data"))}) | ||
| 73 | except Exception as e: | 75 | except Exception as e: |
| 74 | try: | 76 | try: |
| 75 | - task_writer.update_task({"state": -1,"update_time":datetime.datetime.now(),"process": "下载失败"}) | 77 | + task_writer.update_task({"state": -1,"update_time":datetime.datetime.now(),"process": "创建失败"}) |
| 76 | task_writer.update_process( e.__str__()) | 78 | task_writer.update_process( e.__str__()) |
| 77 | task_writer.update_process("任务中止!") | 79 | task_writer.update_process("任务中止!") |
| 78 | except Exception as ee: | 80 | except Exception as ee: |
| 1 | +# coding=utf-8 | ||
| 2 | +#author: 4N | ||
| 3 | +#createtime: 2021/7/19 | ||
| 4 | +#email: nheweijun@sina.com | ||
| 5 | + | ||
| 6 | +import configure | ||
| 7 | +from app.util.component.ApiTemplate import ApiTemplate | ||
| 8 | +from app.util.component.StructurePrint import StructurePrint | ||
| 9 | +from app.models import db | ||
| 10 | +from app.modules.data.models import Task | ||
| 11 | +import multiprocessing | ||
| 12 | +import uuid | ||
| 13 | +import datetime | ||
| 14 | +import requests | ||
| 15 | +from app.util.component.TaskController import TaskController | ||
| 16 | +from app.util.component.TaskWriter import TaskWriter | ||
| 17 | +class Api(ApiTemplate): | ||
| 18 | + | ||
| 19 | + api_name = "创建影像金字塔" | ||
| 20 | + | ||
| 21 | + def process(self): | ||
| 22 | + | ||
| 23 | + # 返回结果 | ||
| 24 | + res = {} | ||
| 25 | + try: | ||
| 26 | + task_guid = uuid.uuid1().__str__() | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + pyramid_process = multiprocessing.Process(target=self.task, args=(task_guid,self.para)) | ||
| 30 | + pyramid_process.start() | ||
| 31 | + | ||
| 32 | + task = Task(guid=task_guid, | ||
| 33 | + name="{}构建影像金字塔".format(self.para.get("alias")), | ||
| 34 | + create_time=datetime.datetime.now(), | ||
| 35 | + state=0, | ||
| 36 | + task_type=5, | ||
| 37 | + creator=self.para.get("creator"), | ||
| 38 | + process="影像创建金字塔中", | ||
| 39 | + task_pid=pyramid_process.pid) | ||
| 40 | + | ||
| 41 | + db.session.add(task) | ||
| 42 | + db.session.commit() | ||
| 43 | + | ||
| 44 | + res["data"] = "创建影像金字塔任务已提交!" | ||
| 45 | + res["result"] = True | ||
| 46 | + | ||
| 47 | + except Exception as e: | ||
| 48 | + raise Exception("数据库错误!") | ||
| 49 | + | ||
| 50 | + return res | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + def task(self,task_guid,para): | ||
| 54 | + task_writer = None | ||
| 55 | + try: | ||
| 56 | + | ||
| 57 | + #任务控制,等待执行 | ||
| 58 | + TaskController.wait(task_guid) | ||
| 59 | + task_writer = TaskWriter(task_guid) | ||
| 60 | + | ||
| 61 | + task_writer.update_task({"state":2,"update_time":datetime.datetime.now(),"process" : "创建中"}) | ||
| 62 | + task_writer.update_process("开始创建...") | ||
| 63 | + | ||
| 64 | + url = "{}/API/Service/Image/BuildPyramid".format(para.get("url")) | ||
| 65 | + | ||
| 66 | + # s = requests.session() | ||
| 67 | + # s.keep_alive = True | ||
| 68 | + # s.post() | ||
| 69 | + | ||
| 70 | + self.para["from"] = configure.deploy_ip_host | ||
| 71 | + | ||
| 72 | + response:requests.Response = requests.post(url,data=self.para) | ||
| 73 | + | ||
| 74 | + if not response.json().get("result"): | ||
| 75 | + raise Exception("由于{},影像服务修改失败!".format(response.json().get("msg"))) | ||
| 76 | + | ||
| 77 | + task_writer.update_task({"state":1,"update_time":datetime.datetime.now(),"process" : "创建完成"}) | ||
| 78 | + task_writer.update_process("创建完成!") | ||
| 79 | + | ||
| 80 | + except Exception as e: | ||
| 81 | + try: | ||
| 82 | + task_writer.update_task({"state": -1,"update_time":datetime.datetime.now(),"process": "创建失败"}) | ||
| 83 | + task_writer.update_process(e.__str__()) | ||
| 84 | + task_writer.update_process("任务中止!") | ||
| 85 | + except Exception as ee: | ||
| 86 | + StructurePrint().print(ee.__str__()) | ||
| 87 | + raise e | ||
| 88 | + finally: | ||
| 89 | + try: | ||
| 90 | + task_writer.close() | ||
| 91 | + except Exception as e: | ||
| 92 | + StructurePrint().print(e.__str__()) | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + api_doc = { | ||
| 96 | + "tags": ["影像服务接口"], | ||
| 97 | + "parameters": [ | ||
| 98 | + {"name": "guid", | ||
| 99 | + "in": "formData", | ||
| 100 | + "type": "string", | ||
| 101 | + "description": "guid"}, | ||
| 102 | + {"name": "url", | ||
| 103 | + "in": "formData", | ||
| 104 | + "type": "string", | ||
| 105 | + "description": "url"}, | ||
| 106 | + {"name": "alias", | ||
| 107 | + "in": "formData", | ||
| 108 | + "type": "string", | ||
| 109 | + "description": "影像alias"}, | ||
| 110 | + ], | ||
| 111 | + "responses": { | ||
| 112 | + 200: { | ||
| 113 | + "schema": { | ||
| 114 | + "properties": { | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + |
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | from app.util.component.ApiTemplate import ApiTemplate | 7 | from app.util.component.ApiTemplate import ApiTemplate |
| 8 | +from app.util.component.StructurePrint import StructurePrint | ||
| 8 | import requests | 9 | import requests |
| 9 | from app.util.component.UserCheck import UserCheck | 10 | from app.util.component.UserCheck import UserCheck |
| 10 | 11 | ||
| @@ -17,15 +18,17 @@ class Api(ApiTemplate): | @@ -17,15 +18,17 @@ class Api(ApiTemplate): | ||
| 17 | res = {} | 18 | res = {} |
| 18 | try: | 19 | try: |
| 19 | 20 | ||
| 20 | - user_req: requests.Response = requests.post("{}/API/Service/Info".format(self.para.get("url")), | 21 | + user_req: requests.Response = requests.post("{}/ImageServer/API/Service/Info".format(self.para.get("url")), |
| 21 | data={"guid":self.para.get("guid")}) | 22 | data={"guid":self.para.get("guid")}) |
| 23 | + | ||
| 22 | if not user_req.json().get("result"): | 24 | if not user_req.json().get("result"): |
| 23 | raise Exception("服务不存在!") | 25 | raise Exception("服务不存在!") |
| 24 | # 验证权限 | 26 | # 验证权限 |
| 25 | UserCheck.verify(user_req.json().get("data").get("service").get("creator")) | 27 | UserCheck.verify(user_req.json().get("data").get("service").get("creator")) |
| 26 | 28 | ||
| 27 | - url = "{}/API/Service/Delete".format(self.para.get("url")) | 29 | + url = "{}/ImageServer/API/Service/Delete".format(self.para.get("url")) |
| 28 | response:requests.Response = requests.post(url,data=self.para) | 30 | response:requests.Response = requests.post(url,data=self.para) |
| 31 | + | ||
| 29 | if not response.json().get("result"): | 32 | if not response.json().get("result"): |
| 30 | raise Exception("由于{},影像地图删除失败!".format(response.json().get("msg"))) | 33 | raise Exception("由于{},影像地图删除失败!".format(response.json().get("msg"))) |
| 31 | res["result"] = True | 34 | res["result"] = True |
| @@ -41,7 +41,7 @@ class Api(ApiTemplate): | @@ -41,7 +41,7 @@ class Api(ApiTemplate): | ||
| 41 | 41 | ||
| 42 | elif s_type in [ServiceType.image_service.value]: | 42 | elif s_type in [ServiceType.image_service.value]: |
| 43 | 43 | ||
| 44 | - edit_url = "{}/API/Service/Info".format(self.para.get("url")) | 44 | + edit_url = "{}/ImageServer/API/Service/Info".format(self.para.get("url")) |
| 45 | response:requests.Response = requests.post(edit_url,self.para) | 45 | response:requests.Response = requests.post(edit_url,self.para) |
| 46 | if not response.json().get("result"): | 46 | if not response.json().get("result"): |
| 47 | raise Exception("查询影像地图失败!") | 47 | raise Exception("查询影像地图失败!") |
请
注册
或
登录
后发表评论