feat: 缓存队列

This commit is contained in:
maxmon 2023-04-11 23:30:36 +08:00
parent ebb0dafc82
commit 7fc844b27c
3 changed files with 35 additions and 14 deletions

View File

@ -11,6 +11,28 @@ from ...libs.tools import read_file, write_json, read_json_file, make_dir
api = RedPrint('anno')
waiting_list_dic = {}
def create_anno_2_file(project_name, anno_cont, all_anno=None):
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
# 判断路径是否存在
if not os.path.exists(anno_output_path):
write_json(anno_output_path, [anno_cont])
else:
output_anno = OutputAnno()
output_anno.all_anno = read_json_file(anno_output_path)
output_anno.add_anno(anno_cont)
write_json(anno_output_path, output_anno.all_anno)
waiting_list_dic[project_name] = waiting_list_dic[project_name][1:]
if len(waiting_list_dic[project_name]) > 0:
create_anno_2_file(project_name, waiting_list_dic[project_name][0], all_anno)
return True
return True
@ -29,19 +51,11 @@ def create_anno():
anno_cont.annoDetails = anno_details
anno_cont.isAnno = True
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
# 判断路径是否存在
if not os.path.exists(anno_output_path):
write_json(anno_output_path, [anno_cont])
ret_info.errCode = 0
else:
output_anno = OutputAnno()
output_anno.all_anno = read_json_file(anno_output_path)
output_anno.add_anno(anno_cont)
write_json(anno_output_path, output_anno.all_anno)
ret_info.errCode = 0
if project_name not in waiting_list_dic:
waiting_list_dic[project_name] = []
waiting_list_dic[project_name].append(anno_cont)
if (len(waiting_list_dic[project_name]) == 1): # 自己位于第一个才处理,其他在第一个结束时处理
create_anno_2_file(project_name, waiting_list_dic[project_name][0])
except Exception as e:
print(e)

View File

@ -30,6 +30,8 @@ def query_file():
file_names.remove('anno.json')
anno_output_path = ANNO_OUTPUT_PATH.format(project_name)
if not os.path.exists(anno_output_path):
open(anno_output_path, 'w', encoding='utf-8').write('[]').close()
# 判断路径是否存在
if not os.path.exists(anno_output_path):
@ -116,7 +118,10 @@ def get_json():
project_file_list = get_project_file(project_path)
anno_data_set = set()
download_json = []
anno_data = read_json_file(PROJECT_PATH.format(project_name) + '/anno.json')
anno_file_path = PROJECT_PATH.format(project_name) + '/anno.json'
if not os.path.exists(anno_file_path):
open(anno_file_path, 'w', encoding='utf-8').write('[]').close()
anno_data = read_json_file(anno_file_path)
for item in anno_data:
item_dict = {}
item_dict['file'] = item['fileName']

View File

@ -22,9 +22,11 @@ def make_dir(path):
if not folder:
os.mkdir(path)
json_cache_dic = {}
# 将json数据写入.json文件
def write_json(json_file_path, data):
json_cache_dic[json_file_path] = data
with open(json_file_path, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, default=lambda o: o.__dict__)