This commit is contained in:
Nate Sesti 2023-09-06 19:40:22 -07:00
commit f3a5e0f419
3 changed files with 30 additions and 4 deletions

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "continuedev"
version = "0.1.3"
version = "0.1.4"
description = ""
authors = ["Nate Sesti <sestinj@gmail.com>"]
readme = "README.md"

View file

@ -10,7 +10,7 @@ from ..libs.util.create_async_task import create_async_task
from ..libs.util.devdata import dev_data_logger
from ..libs.util.logging import logger
from ..libs.util.telemetry import posthog_logger
from ..server.meilisearch_server import poll_meilisearch_running
from ..server.meilisearch_server import poll_meilisearch_running, restart_meilisearch
from .main import ChatMessage, ContextItem, ContextItemDescription, ContextItemId
@ -269,7 +269,7 @@ class ContextManager:
timeout=20,
)
async def load_index(self, workspace_dir: str):
async def load_index(self, workspace_dir: str, should_retry: bool = True):
try:
async with Client("http://localhost:7700") as search_client:
# First, create the index if it doesn't exist
@ -327,6 +327,13 @@ class ContextManager:
except Exception as e:
logger.debug(f"Error loading meilisearch index: {e}")
if should_retry:
await restart_meilisearch()
try:
asyncio.wait_for(await poll_meilisearch_running(), timeout=20)
except asyncio.TimeoutError:
logger.warning("Meilisearch did not restart in less than 20 seconds. Stopping polling.")
await self.load_index(workspace_dir, False)
async def select_context_item(self, id: str, query: str):
"""

View file

@ -77,12 +77,13 @@ async def ensure_meilisearch_installed() -> bool:
except:
pass
existing_paths.remove(meilisearchPath)
await download_meilisearch()
# Clear the existing directories
for p in existing_paths:
shutil.rmtree(p, ignore_errors=True)
await download_meilisearch()
return False
@ -155,3 +156,21 @@ def stop_meilisearch():
meilisearch_process.terminate()
meilisearch_process.wait()
meilisearch_process = None
import psutil
def kill_proc(port):
for proc in psutil.process_iter():
try:
for conns in proc.connections(kind='inet'):
if conns.laddr.port == port:
proc.send_signal(psutil.signal.SIGTERM) # or SIGKILL
except psutil.AccessDenied:
logger.warning(f"Failed to kill process on port {port}")
async def restart_meilisearch():
stop_meilisearch()
kill_proc(7700)
await start_meilisearch()