Commit f38430d6 by 杨林龙

优化配置项导入

1 parent 61152415
import sys
from log.logger import log
environment = sys.argv[1] if len(sys.argv) > 1 else "default"
# environment = os.environ.get('ENV')
if environment == 'pro':
from config_release import Config
log.info(vars(Config))
elif environment == 'test':
from config_test import Config
log.info(vars(Config))
else:
from config_dev import Config
log.info(vars(Config))
class ConfigInfo:
environment = sys.argv[1] if len(sys.argv) > 1 else "dev"
# environment = os.environ.get('ENV')
if environment == 'pro':
from config.config_release import Config
log.info(vars(Config))
elif environment == 'test':
from config.config_test import Config
log.info(vars(Config))
else:
from config.config_dev import Config
log.info(vars(Config))
DEBUG = Config.DEBUG
env = Config.env
# 数据库连接配置
......@@ -30,5 +26,5 @@ class ConfigInfo:
kafka_consumer_bootstrap_servers = Config.kafka_consumer_bootstrap_servers
kafka_consumer_group_id = Config.kafka_consumer_group_id
kafka_consumer_auto_offset_reset = Config.kafka_consumer_auto_offset_reset
kafka_consumer_topic = Config.kafka_consumer_topic
kafka_consumer_analysis_topic = Config.kafka_consumer_analysis_topic
charset = Config.charset
......@@ -133,3 +133,12 @@
2024-03-15 18:39:43,949 12724 MysqlHelper.py[line:72] - INFO: execute_modify result:1
2024-03-15 18:39:43,949 12724 funasr_service.py[line:103] - INFO: Function create_upload_file executed in 40.10529479999968 s
2024-03-15 18:39:43,949 12724 funasr_service.py[line:106] - INFO: Worker 3363630e-e2b8-11ee-b8f9-a0e70be87132 finished.
2024-03-18 11:03:06,031 24452 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:03:06,170 24452 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:05:22,236 21236 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:05:22,617 21236 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:05:22,640 21236 config.py[line:15] - INFO: {'__module__': 'config.config_dev', 'DEBUG': False, 'env': 'dev', 'host': '192.168.3.227', 'port': 3306, 'user': 'dev_user', 'password': 'df234fl', 'database': 'glsx_car_service', 'kafka_consumer_bootstrap_servers': '192.168.3.131:9092', 'kafka_consumer_group_id': 'funasr_dev', 'kafka_consumer_auto_offset_reset': 'earliest', 'kafka_consumer_analysis_topic': 'funasr_analysis_topic', 'charset': 'utf8', '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': None}
2024-03-18 11:06:30,820 25204 funasr_consumer.py[line:17] - INFO: 启动2
2024-03-18 11:06:30,928 25204 funasr_consumer.py[line:32] - INFO: 启动3
2024-03-18 11:06:30,932 25204 config.py[line:15] - INFO: {'__module__': 'config.config_dev', 'DEBUG': False, 'env': 'dev', 'host': '192.168.3.227', 'port': 3306, 'user': 'dev_user', 'password': 'df234fl', 'database': 'glsx_car_service', 'kafka_consumer_bootstrap_servers': '192.168.3.131:9092', 'kafka_consumer_group_id': 'funasr_dev', 'kafka_consumer_auto_offset_reset': 'earliest', 'kafka_consumer_analysis_topic': 'funasr_analysis_topic', 'charset': 'utf8', '__dict__': <attribute '__dict__' of 'Config' objects>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': None}
2024-03-18 11:06:30,967 21780 funasr_consumer.py[line:58] - INFO: 启动consume_kafka
......@@ -53,18 +53,18 @@ def execute_sql(sql):
conn.close()
#
# 循环消费消息
def consume_kafka():
log.info("启动consume_kafka")
# 消费消息并进行逻辑处理
try:
for msg in consumer:
if msg is None:
for message in consumer:
if message is None:
continue
# 处理逻辑
start_time = time.time()
# funasr_service.handle_process(msg)
# funasr_service.handle_process(message)
funasr_service.handle_process(str(message.value.decode('utf-8')))
print("task handle")
end_time = time.time()
log.info("handle_process耗时:" + str(end_time - start_time))
......@@ -73,8 +73,8 @@ def consume_kafka():
# 循环消费消息
for message in consumer:
log.info(f"Received message: {message.value}")
if message is None:
continue
funasr_service.handle_process(str(message.value.decode('utf-8')))
\ No newline at end of file
# for message in consumer:
# log.info(f"Received message: {message.value}")
# if message is None:
# continue
# funasr_service.handle_process(str(message.value.decode('utf-8')))
\ No newline at end of file
......@@ -33,4 +33,4 @@ def setup_logging(log_file):
return logger
log=setup_logging('D:/software/python/project/funasr_web/log/funasr.log')
\ No newline at end of file
log=setup_logging('funasr.log')
\ No newline at end of file
......@@ -14,6 +14,8 @@ from fastapi import FastAPI, File, UploadFile
from funasr_service import FunasrService
from pydantic import BaseModel
from mysql_service import funasr_db
from kafka_service import funasr_consumer
from config.config import ConfigInfo
app = FastAPI()
......@@ -191,8 +193,14 @@ async def create_url(param: UrlParam):
traceback.print_exc()
return {"error": str(e)}
def start_kafka():
kafka_thread = threading.Thread(target=funasr_consumer.consume_kafka)
kafka_thread.daemon = True # 将线程设置为守护线程,当主线程结束时,该线程也会自动结束
kafka_thread.start()
if __name__ == "__main__":
start_kafka()
save_path = "./audio/"
if os.path.exists(save_path):
shutil.rmtree(save_path)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!