You need to sign in or sign up before continuing.
Commit 9bacdebc by ‘chizw’

服务重启任务优化

1 parent 8c9dc8c6
...@@ -4,6 +4,7 @@ import uuid ...@@ -4,6 +4,7 @@ import uuid
from log.logger import log from log.logger import log
from kafka import KafkaProducer from kafka import KafkaProducer
from config.config import ConfigInfo from config.config import ConfigInfo
from mysql_service import funasr_db
# 创建Kafka生产者 # 创建Kafka生产者
producer = KafkaProducer(bootstrap_servers=ConfigInfo.kafka_consumer_bootstrap_servers) # Kafka集群的地址 producer = KafkaProducer(bootstrap_servers=ConfigInfo.kafka_consumer_bootstrap_servers) # Kafka集群的地址
...@@ -19,3 +20,16 @@ def send_message_analysis(message): ...@@ -19,3 +20,16 @@ def send_message_analysis(message):
producer.send(ConfigInfo.kafka_consumer_analysis_topic, message) producer.send(ConfigInfo.kafka_consumer_analysis_topic, message)
# 等待所有消息发送完成 # 等待所有消息发送完成
producer.flush() producer.flush()
def send_wait_task():
res = funasr_db.select_ali_asr_model_wait()
json_res = json.loads(res)
print(f"服务启动推送等待任务:{json_res}")
for item in json_res:
task_id = item['task_id']
data = {"task_id": task_id}
message = json.dumps(data).encode('utf-8')
producer.send(ConfigInfo.kafka_consumer_analysis_topic, message)
print(f"send success{task_id}")
# 等待所有消息发送完成
producer.flush()
\ No newline at end of file \ No newline at end of file
...@@ -200,6 +200,7 @@ def start_kafka(): ...@@ -200,6 +200,7 @@ def start_kafka():
if __name__ == "__main__": if __name__ == "__main__":
start_kafka() start_kafka()
funasr_producer.send_wait_task()
save_path = "./audio/" save_path = "./audio/"
if os.path.exists(save_path): if os.path.exists(save_path):
shutil.rmtree(save_path) shutil.rmtree(save_path)
......
...@@ -33,5 +33,6 @@ def select_ali_asr_model_res(task_id: str): ...@@ -33,5 +33,6 @@ def select_ali_asr_model_res(task_id: str):
def select_ali_asr_model_wait(): def select_ali_asr_model_wait():
select_sql = ( select_sql = (
f"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;") f"select id,task_id,file_url,task_status,output_data from ali_asr_model_res aamr where aamr.del_flag = 0 and "
f"aamr.output_data is null and aamr.task_status = 0;")
return db.execute_select(select_sql) return db.execute_select(select_sql)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!