Commit 897b3f56 by ‘chizw’

[+]限制优化

1 parent 38862d9e
......@@ -183,7 +183,8 @@ def deal_worker(task_id: str):
log.info(f"Worker {task_id} is running... url:{url}")
consuming_start_time = time.perf_counter()
# 解析音频
output_res = FunasrService(url).transform()
funasr_instance = FunasrService(url)
output_res = funasr_instance.transform()
if len(output_res) < 1:
log.info("output_res: %s" % output_res)
funasr_db.update_ali_asr_model_res(task_id, str(output_res), 0)
......@@ -200,10 +201,13 @@ def deal_worker(task_id: str):
# 强制进行垃圾回收
gc.collect()
except Exception as e:
log.error(f"Worker error:{traceback.format_exc()}")
log.error(f"task_id:{task_id} Worker error:{traceback.format_exc()}")
funasr_db.update_ali_asr_model_res_fail(task_id, str(e), traceback.format_exc())
# funasr_producer.send_task_id(task_id)
return
finally:
funasr_instance = None
gc.collect()
def fine_grained_transform_output(sentence_info):
......
......@@ -175,5 +175,6 @@ def select_extract_data():
# run("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_172075478615417207538825792.mp3", "东联")
# run("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_172119302897717211886442290.mp3", "李钰达")
# run("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17205900068901720588971648.mp3", "张东华")
run("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/车辆知识_保险基础知识培训-视频.mp3", "保险基础知识培训")
select_extract_data()
\ No newline at end of file
# select_extract_data()
\ No newline at end of file
......@@ -20,6 +20,8 @@ pool = ConnPool(
**config
)
EXCEPTION_LIMIT = 5
def insert_ali_asr_model_res(task_id: str, url: str):
insert_sql = (
......@@ -37,18 +39,19 @@ def update_ali_asr_model_res(task_id: str, json_output: str, execute_time: int):
def update_ali_asr_model_res_fail(task_id: str, exception_msg: str, exception: str):
update_sql = (
"update ali_asr_model_res t set t.task_status = 2, t.exception_msg = %s, t.exception_log = %s, "
"update ali_asr_model_res t set t.task_status = case when exception_limit >= %s then 2 else 0 end, "
"t.exception_msg = %s, t.exception_log = %s, "
"exception_limit = exception_limit + 1 "
"where t.task_id = %s and del_flag = 0;")
return pool.update_one(update_sql, (exception_msg, exception, task_id,))
return pool.update_one(update_sql, (EXCEPTION_LIMIT, exception_msg, exception, task_id,))
def update_ali_asr_model_res_skip(task_id: str):
update_sql = (
"update ali_asr_model_res t set t.task_status = 2,"
"update ali_asr_model_res t set t.task_status = case when exception_limit >= %s then 2 else 0 end,"
"exception_limit = exception_limit + 1 "
"where t.task_id = %s and del_flag = 0;")
return pool.update_one(update_sql, (task_id,))
return pool.update_one(update_sql, (EXCEPTION_LIMIT, task_id,))
def select_ali_asr_model_res(task_id: str):
......@@ -56,17 +59,17 @@ def select_ali_asr_model_res(task_id: str):
"select id,task_id,file_url,task_status,output_data,exception_msg"
" from ali_asr_model_res aamr"
" where del_flag = 0 and "
" task_id = %s and exception_limit < 3 "
" task_id = %s and exception_limit < %s "
" order by created_time desc;"
)
return pool.select_all(select_sql, (task_id,))
return pool.select_all(select_sql, (task_id, EXCEPTION_LIMIT))
def select_ali_asr_model_wait():
select_sql = (
"select id,task_id,file_url,task_status,output_data from ali_asr_model_res aamr where aamr.del_flag = 0 and "
"aamr.output_data is null and aamr.task_status != %s and exception_limit < 3;")
return pool.select_all(select_sql, 1)
"aamr.output_data is null and aamr.task_status != %s and exception_limit < %s;")
return pool.select_all(select_sql, (1, EXCEPTION_LIMIT))
def select_process_fail_task(process_name: str):
......@@ -96,11 +99,11 @@ def select_process_all_end():
def select_time_out_task():
sql = (
"select id,task_id,file_url,task_status from ali_asr_model_res aamr where aamr.del_flag = 0 "
"and aamr.output_data is null and exception_limit < 3 "
"and aamr.output_data is null and exception_limit < %s "
# "and aamr.execute_process_name is not null "
"and aamr.updated_time < TIMESTAMPADD(HOUR, -%s, NOW());"
)
return pool.select_all(sql, (2))
return pool.select_all(sql, (EXCEPTION_LIMIT, 2))
def select_voice_data(id):
......
......@@ -298,7 +298,7 @@ def upload_files(name, file_path):
# crop_audio_by_rule(500 * 1000 * 3600)
def format_audio_and_text():
append_sys_param("env", "release")
append_sys_param("env", "dev")
import funasr_service
from mysql_service import funasr_db
audio_path = f'D:/software/python/project/funasr_web/audios/train_audio/down_audio/'
......@@ -382,4 +382,4 @@ def down_file_upload_release(table_name):
print(sql)
upload_file("1_1120_赛力斯、平安智驾项目对接会议.m4a","D:\\software\\python\\project\\funasr_web\\log\\1_1120_赛力斯、平安智驾项目对接会议.m4a")
upload_file("1_1120_赛力斯、平安智驾项目对接会议.m4a","D:\\software\\python\\project\\funasr_web\\dataset\\20241205152115-车辆知识_保险基础知识培训-视频-1 - 副本.mp3")
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!