Compare commits
6 Commits
d7b85e4755
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| d871f1fe32 | |||
| 42df024940 | |||
| 22a3991c76 | |||
| e689e05fbe | |||
| 0cb045a2a4 | |||
| 1ef92eb768 |
@@ -13,7 +13,7 @@ APP_VERSION=1.0.0
|
||||
|
||||
# Server
|
||||
HOST=0.0.0.0
|
||||
PORT=5056
|
||||
PORT=5008
|
||||
RELOAD=True
|
||||
|
||||
#SFTP
|
||||
@@ -23,4 +23,6 @@ SFPT_PASSWORD = Audio4analy6!6
|
||||
|
||||
FILESAPTH = audiofiles
|
||||
|
||||
GIGAAM_API_URL = http://localhost:5001
|
||||
GIGAAM_API_URL = http://host.docker.internal:5002
|
||||
CALLS_WEB_CLIENT_URL=http://web_client_test:8642
|
||||
AUDIO_FILES_PATH_TEST=D:\SpeechAnalitics\audiofiles
|
||||
|
||||
+2
-2
@@ -25,14 +25,14 @@ PORT = int(os.getenv("PORT", "5008"))
|
||||
HOST = os.getenv("HOST", "localhost")
|
||||
|
||||
# GigaAM API Configuration
|
||||
GIGAAM_API_URL = os.getenv("GIGAAM_API_URL", "http://192.168.1.73:5002")
|
||||
GIGAAM_API_URL = os.getenv("GIGAAM_API_URL", "http://host.docker.internal:5002")
|
||||
|
||||
AUDIOFILES_PATH = os.path.join(os.getcwd(), os.getenv("FILESAPTH", "audiofiles"))
|
||||
|
||||
# Calls_WEB_Client_main Webhook Configuration
|
||||
CALLS_WEB_CLIENT_URL = os.getenv(
|
||||
"CALLS_WEB_CLIENT_URL",
|
||||
"http://192.168.1.73:8642"
|
||||
"http://host.docker.internal:8642"
|
||||
)
|
||||
WEBHOOK_ENDPOINT = f"{CALLS_WEB_CLIENT_URL}/api/transcription/webhook"
|
||||
WEBHOOK_API_KEY = os.getenv("WEBHOOK_API_KEY", "webhook_secret_key")
|
||||
|
||||
@@ -9,9 +9,10 @@ from apiApp.database import get_db
|
||||
from apiApp.database.Audio import Audio
|
||||
from apiApp.database.AiConclusion import AiConclusion
|
||||
from datetime import datetime
|
||||
import time
|
||||
import logging
|
||||
import requests
|
||||
from apiApp.config import WEBHOOK_ENDPOINT, WEBHOOK_API_KEY
|
||||
from apiApp.config import WEBHOOK_ENDPOINT, WEBHOOK_API_KEY, CALLS_WEB_CLIENT_URL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
ai_conclusion_router = APIRouter()
|
||||
@@ -168,8 +169,7 @@ async def save_ai_conclusion(request: AiConclusionRequest, db: Session = Depends
|
||||
if (audio.sourse or "").lower() == "external" and request.callback_url:
|
||||
_send_callback(request.callback_url, audio, conclusion_data)
|
||||
|
||||
# Отправляем webhook в Calls_WEB_Client_main для анализа
|
||||
try:
|
||||
# Отправляем webhook в Calls_WEB_Client_main для анализа (с retry при перезагрузке контейнера)
|
||||
if (audio.sourse or "").lower() != "external":
|
||||
logger.info(f"📤 Отправка webhook в Calls_WEB_Client_main для {request.filename}")
|
||||
|
||||
@@ -182,25 +182,35 @@ async def save_ai_conclusion(request: AiConclusionRequest, db: Session = Depends
|
||||
"processing_time_seconds": request.processing_time_seconds
|
||||
}
|
||||
|
||||
max_retries = 5
|
||||
delays = [2, 4, 8, 15, 30]
|
||||
delivered = False
|
||||
|
||||
for attempt in range(1, max_retries + 1):
|
||||
try:
|
||||
webhook_response = requests.post(
|
||||
WEBHOOK_ENDPOINT,
|
||||
json=webhook_payload,
|
||||
headers={"X-Webhook-Key": WEBHOOK_API_KEY},
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if webhook_response.status_code == 200:
|
||||
logger.info(f"✅ Webhook успешно отправлен для {request.filename}")
|
||||
if webhook_response.status_code in (200, 201):
|
||||
logger.info(f"✅ Webhook успешно отправлен для {request.filename} (попытка {attempt}/{max_retries})")
|
||||
delivered = True
|
||||
break
|
||||
else:
|
||||
logger.warning(f"⚠️ Webhook вернул статус {webhook_response.status_code}")
|
||||
logger.warning(f"Response: {webhook_response.text}")
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.error(f"❌ Не удалось подключиться к Calls_WEB_Client_main webhook: {WEBHOOK_ENDPOINT}")
|
||||
except requests.exceptions.Timeout:
|
||||
logger.warning(f"⚠️ Таймаут при отправке webhook для {request.filename}")
|
||||
logger.warning(f"⚠️ Webhook вернул статус {webhook_response.status_code} (попытка {attempt}/{max_retries})")
|
||||
logger.warning(f"Response: {webhook_response.text[:200]}")
|
||||
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
|
||||
logger.warning(f"⏳ Calls_WEB_Client_main временно недоступен ({type(e).__name__}), попытка {attempt}/{max_retries}...")
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Ошибка при отправке webhook: {e}")
|
||||
logger.error(f"❌ Непредвиденная ошибка при отправке webhook (попытка {attempt}): {e}")
|
||||
|
||||
if attempt < max_retries:
|
||||
time.sleep(delays[attempt - 1])
|
||||
|
||||
if not delivered:
|
||||
logger.error(f"❌ Не удалось доставить webhook для {request.filename} после {max_retries} попыток")
|
||||
|
||||
return AiConclusionResponse(
|
||||
success=True,
|
||||
|
||||
@@ -250,7 +250,7 @@ async def process_all_pending_audio(
|
||||
logger.info(f"🚀 Поиск Audio без AiConclusion (limit={limit})")
|
||||
|
||||
# Находим все Audio без AiConclusion используя вспомогательную функцию
|
||||
pending_audio = query_audio_without_conclusion(db, limit).all()
|
||||
pending_audio: list[Audio] = query_audio_without_conclusion(db, limit).all()
|
||||
total_pending = query_audio_without_conclusion(db).count()
|
||||
|
||||
if not pending_audio:
|
||||
|
||||
@@ -11,7 +11,15 @@ class Loader():
|
||||
self.call_types = ['in']
|
||||
self.loaded_files = [] # Список загруженных файлов
|
||||
|
||||
def filter_call(self, filename: str):
|
||||
def filter_call(self, filename: str) -> bool:
|
||||
if not filename or not filename.endswith('.wav'):
|
||||
return False
|
||||
|
||||
# Пропускаем раздельные каналы звонков (_r = receive/клиент, _t = transmit/оператор)
|
||||
name_without_ext = filename[:-4]
|
||||
if name_without_ext.endswith(('_r', '_t', '_in', '_out', '-r', '-t')):
|
||||
return False
|
||||
|
||||
if filename.split("-")[0] in self.call_types:
|
||||
return True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user