This commit is contained in:
@@ -22,7 +22,11 @@ if DB_URL.startswith("postgres"):
|
||||
max_overflow=20,
|
||||
pool_timeout=30, # Время ожидания свободного соединения
|
||||
pool_recycle=1800, # Время жизни соединения
|
||||
connect_args={"sslmode": "disable"},
|
||||
pool_pre_ping=True, # Добавить проверку соединений
|
||||
connect_args={
|
||||
"sslmode": "disable",
|
||||
"connect_timeout": 40 # Добавить таймаут подключения
|
||||
}
|
||||
)
|
||||
else:
|
||||
engine = create_engine(DB_URL, echo=False, connect_args={"check_same_thread": False})
|
||||
|
@@ -166,7 +166,19 @@ class SearchService:
|
||||
|
||||
async def perform_index(self, shout, index_body):
|
||||
if self.client:
|
||||
self.client.index(index=self.index_name, id=str(shout.id), body=index_body)
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
self.client.index(
|
||||
index=self.index_name,
|
||||
id=str(shout.id),
|
||||
body=index_body
|
||||
),
|
||||
timeout=40.0
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.error(f"Indexing timeout for shout {shout.id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Indexing error for shout {shout.id}: {e}")
|
||||
|
||||
async def search(self, text, limit, offset):
|
||||
logger.info(f"Ищем: {text} {offset}+{limit}")
|
||||
|
@@ -37,6 +37,12 @@ class ViewedStorage:
|
||||
auth_result = None
|
||||
disabled = False
|
||||
start_date = datetime.now().strftime("%Y-%m-%d")
|
||||
running = True
|
||||
|
||||
@staticmethod
|
||||
async def stop():
|
||||
self = ViewedStorage
|
||||
self.running = False
|
||||
|
||||
@staticmethod
|
||||
async def init():
|
||||
@@ -196,22 +202,26 @@ class ViewedStorage:
|
||||
if self.disabled:
|
||||
return
|
||||
|
||||
while True:
|
||||
try:
|
||||
await self.update_pages()
|
||||
failed = 0
|
||||
except Exception as exc:
|
||||
failed += 1
|
||||
logger.debug(exc)
|
||||
logger.info(" - update failed #%d, wait 10 secs" % failed)
|
||||
if failed > 3:
|
||||
logger.info(" - views update failed, not trying anymore")
|
||||
break
|
||||
if failed == 0:
|
||||
when = datetime.now(timezone.utc) + timedelta(seconds=self.period)
|
||||
t = format(when.astimezone().isoformat())
|
||||
logger.info(" ⎩ next update: %s" % (t.split("T")[0] + " " + t.split("T")[1].split(".")[0]))
|
||||
await asyncio.sleep(self.period)
|
||||
else:
|
||||
await asyncio.sleep(10)
|
||||
logger.info(" - try to update views again")
|
||||
try:
|
||||
while self.running:
|
||||
try:
|
||||
await self.update_pages()
|
||||
failed = 0
|
||||
except Exception as exc:
|
||||
failed += 1
|
||||
logger.debug(exc)
|
||||
logger.warning(" - update failed #%d, wait 10 secs" % failed)
|
||||
if failed > 3 or isinstance(exc, asyncio.CancelledError):
|
||||
logger.error("ViewedStorage worker cancelled")
|
||||
break
|
||||
finally:
|
||||
self.running = False
|
||||
|
||||
if failed == 0:
|
||||
when = datetime.now(timezone.utc) + timedelta(seconds=self.period)
|
||||
t = format(when.astimezone().isoformat())
|
||||
logger.info(" ⎩ next update: %s" % (t.split("T")[0] + " " + t.split("T")[1].split(".")[0]))
|
||||
await asyncio.sleep(self.period)
|
||||
else:
|
||||
await asyncio.sleep(10)
|
||||
logger.info(" - try to update views again")
|
||||
|
Reference in New Issue
Block a user