优化flask
This commit is contained in:
119
scheduled_task/queue_storage.py
Normal file
119
scheduled_task/queue_storage.py
Normal file
@ -0,0 +1,119 @@
|
||||
# coding: utf-8
|
||||
# Author:tajochen
|
||||
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from application.settings import Config
|
||||
from common.tools.dms import dms_login, dms_task_record
|
||||
from util.upload_client import upload_file_client
|
||||
|
||||
from util.http_util import httpUtil
|
||||
|
||||
|
||||
# 动态调用函数
|
||||
# @param tag 标签名
|
||||
# @param text 文本
|
||||
# @return True:OK, False:NG
|
||||
def item_check(func_name, text):
|
||||
if type and text:
|
||||
try:
|
||||
# 调用导入模块中的函数,并传参
|
||||
return eval("__{0}".format(func_name))(text)
|
||||
except Exception:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# 动态调用遥感函数
|
||||
# @param tag 标签名
|
||||
# @param text 文本
|
||||
# @return True:OK, False:NG
|
||||
def analysis_remote_sensing_data(func_name, collection_code, path):
|
||||
"""
|
||||
解析JPSS-VJ102元数据
|
||||
:return:
|
||||
"""
|
||||
print('开始扫描VJ102IMG数据集')
|
||||
#collectionCode = 'VJ102IMG'
|
||||
# 用户登录
|
||||
token_s = dms_login()
|
||||
# 判断定时任务是否在进行
|
||||
task = dms_task_record(token_s, collection_code)
|
||||
# 如果不是空说明正在进行
|
||||
if task is not None and len(task) > 0:
|
||||
return 1
|
||||
|
||||
file_total_size = ""
|
||||
file_total_name = ""
|
||||
xmlPath = Config.XML_PATH # 解析出的xml文件保存的路径
|
||||
ThumbnailPath = Config.THUMBNAIL_PATH # 解析出的缩略图保存的路径
|
||||
|
||||
# 解析遥感数据文件(demo)
|
||||
remote_sensing_data_dic = globals().get('func_%s' % func_name)(path, xmlPath, ThumbnailPath)
|
||||
|
||||
# 配置文件服务器参数
|
||||
url = Config.DFS_UPLOAD_URL
|
||||
files = {'file': open(remote_sensing_data_dic['xmlPath'], 'rb')}
|
||||
options = {'output': 'json', 'path': '/archive_data/remote_sensing_data/' + collection_code}
|
||||
# 上传生成的xml文件到文件服务器
|
||||
xml = requests.post(url, data=options, files=files)
|
||||
|
||||
url = Config.DFS_UPLOAD_URL
|
||||
files = {'file': open(remote_sensing_data_dic['ThumbnailPath'], 'rb')}
|
||||
options = {'output': 'json', 'path': '/archive_data/remote_sensing_data/' + collection_code}
|
||||
# 上传生成的xml文件到文件服务器
|
||||
ThumbnailName = requests.post(url, data=options, files=files)
|
||||
|
||||
CollectionCode = remote_sensing_data_dic['CollectionCode']
|
||||
DirectoryDepth = remote_sensing_data_dic['DirectoryDepth']
|
||||
StartTime = remote_sensing_data_dic['StartTime']
|
||||
# uc = upload_client(path, DirectoryDepth, StartTime[0:19])
|
||||
uc = upload_file_client(path, DirectoryDepth, StartTime[0:19], collection_code)
|
||||
|
||||
StartTime = time.mktime(time.strptime(remote_sensing_data_dic['StartTime'][0:19], '%Y-%m-%d %H:%M:%S'))
|
||||
EndTime = time.mktime(time.strptime(remote_sensing_data_dic['EndTime'][0:19], '%Y-%m-%d %H:%M:%S'))
|
||||
|
||||
# 入库遥感数据
|
||||
res_data = httpUtil(url=Config.RESING_DATA_URL,
|
||||
data={"collectionCode": collection_code, "shootingTimeStartTs": StartTime,
|
||||
"shootingTimeEndTs": EndTime,
|
||||
"fileMd5": uc['md5'], "fileName": uc['fileName'], "filePath": uc['file_path'],
|
||||
"fileSize": uc['file_size'], "cloudCoverage": remote_sensing_data_dic['CloudPercent'],
|
||||
"metaInformationFile": xml.json()['path'],
|
||||
"thumbnailFile": ThumbnailName.json()['path'],
|
||||
"remarks": "", "boundaryGeomStr": remote_sensing_data_dic['boundaryGeomStr']},
|
||||
token=token_s).post_no_patam_herder()
|
||||
print(res_data.json()['data'])
|
||||
|
||||
file_total_size = file_total_size + str(uc['file_size'])
|
||||
file_total_size = file_total_size + ","
|
||||
|
||||
file_total_name = file_total_name + uc['fileName']
|
||||
file_total_name = file_total_name + ","
|
||||
|
||||
# 添加遥感数据归档任务
|
||||
res = httpUtil(url=Config.DATA_TASK_URL,
|
||||
data={"clientCode": "client1", "collectionCode": collection_code, "storageFileList": file_total_name,
|
||||
"storageFileSizeList": file_total_size, "remarks": ""}, token=token_s).post_no_patam_herder()
|
||||
task_code = res.json()['data']
|
||||
|
||||
# 结束遥感数据归档任务
|
||||
header = {"Authorization": token_s}
|
||||
res = requests.post(url=Config.DATA_END_TASK_URL,
|
||||
|
||||
params={"taskCode": task_code}, headers=header).json()
|
||||
if res_data.json()['status'] == 0:
|
||||
return 0
|
||||
else:
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = item_check("num", 123.23)
|
||||
print(result)
|
||||
strs = ['year', 'month']
|
||||
for s in strs:
|
||||
globals().get('func_%s' % s)(s)
|
Reference in New Issue
Block a user