Commit 897b3f56 by ‘chizw’

[+]限制优化

1 parent 38862d9e
...@@ -183,7 +183,8 @@ def deal_worker(task_id: str): ...@@ -183,7 +183,8 @@ def deal_worker(task_id: str):
log.info(f"Worker {task_id} is running... url:{url}") log.info(f"Worker {task_id} is running... url:{url}")
consuming_start_time = time.perf_counter() 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: if len(output_res) < 1:
log.info("output_res: %s" % output_res) log.info("output_res: %s" % output_res)
funasr_db.update_ali_asr_model_res(task_id, str(output_res), 0) funasr_db.update_ali_asr_model_res(task_id, str(output_res), 0)
...@@ -200,10 +201,13 @@ def deal_worker(task_id: str): ...@@ -200,10 +201,13 @@ def deal_worker(task_id: str):
# 强制进行垃圾回收 # 强制进行垃圾回收
gc.collect() gc.collect()
except Exception as e: 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_db.update_ali_asr_model_res_fail(task_id, str(e), traceback.format_exc())
# funasr_producer.send_task_id(task_id) # funasr_producer.send_task_id(task_id)
return return
finally:
funasr_instance = None
gc.collect()
def fine_grained_transform_output(sentence_info): def fine_grained_transform_output(sentence_info):
......
...@@ -175,5 +175,6 @@ def select_extract_data(): ...@@ -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_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_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/merged_17205900068901720588971648.mp3", "张东华")
run("https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/车辆知识_保险基础知识培训-视频.mp3", "保险基础知识培训")
select_extract_data()
\ No newline at end of file \ No newline at end of file
# select_extract_data()
\ No newline at end of file \ No newline at end of file
...@@ -20,6 +20,8 @@ pool = ConnPool( ...@@ -20,6 +20,8 @@ pool = ConnPool(
**config **config
) )
EXCEPTION_LIMIT = 5
def insert_ali_asr_model_res(task_id: str, url: str): def insert_ali_asr_model_res(task_id: str, url: str):
insert_sql = ( insert_sql = (
...@@ -37,18 +39,19 @@ def update_ali_asr_model_res(task_id: str, json_output: str, execute_time: int): ...@@ -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): def update_ali_asr_model_res_fail(task_id: str, exception_msg: str, exception: str):
update_sql = ( 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 " "exception_limit = exception_limit + 1 "
"where t.task_id = %s and del_flag = 0;") "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): def update_ali_asr_model_res_skip(task_id: str):
update_sql = ( 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 " "exception_limit = exception_limit + 1 "
"where t.task_id = %s and del_flag = 0;") "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): def select_ali_asr_model_res(task_id: str):
...@@ -56,17 +59,17 @@ 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" "select id,task_id,file_url,task_status,output_data,exception_msg"
" from ali_asr_model_res aamr" " from ali_asr_model_res aamr"
" where del_flag = 0 and " " where del_flag = 0 and "
" task_id = %s and exception_limit < 3 " " task_id = %s and exception_limit < %s "
" order by created_time desc;" " 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(): def select_ali_asr_model_wait():
select_sql = ( select_sql = (
"select id,task_id,file_url,task_status,output_data from ali_asr_model_res aamr where aamr.del_flag = 0 and " "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;") "aamr.output_data is null and aamr.task_status != %s and exception_limit < %s;")
return pool.select_all(select_sql, 1) return pool.select_all(select_sql, (1, EXCEPTION_LIMIT))
def select_process_fail_task(process_name: str): def select_process_fail_task(process_name: str):
...@@ -96,11 +99,11 @@ def select_process_all_end(): ...@@ -96,11 +99,11 @@ def select_process_all_end():
def select_time_out_task(): def select_time_out_task():
sql = ( sql = (
"select id,task_id,file_url,task_status from ali_asr_model_res aamr where aamr.del_flag = 0 " "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.execute_process_name is not null "
"and aamr.updated_time < TIMESTAMPADD(HOUR, -%s, NOW());" "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): def select_voice_data(id):
......
...@@ -298,7 +298,7 @@ def upload_files(name, file_path): ...@@ -298,7 +298,7 @@ def upload_files(name, file_path):
# crop_audio_by_rule(500 * 1000 * 3600) # crop_audio_by_rule(500 * 1000 * 3600)
def format_audio_and_text(): def format_audio_and_text():
append_sys_param("env", "release") append_sys_param("env", "dev")
import funasr_service import funasr_service
from mysql_service import funasr_db from mysql_service import funasr_db
audio_path = f'D:/software/python/project/funasr_web/audios/train_audio/down_audio/' 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): ...@@ -382,4 +382,4 @@ def down_file_upload_release(table_name):
print(sql) 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!