Fixed startup scan
This commit is contained in:
@@ -674,6 +674,7 @@ def create_app(args):
|
|||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
"""Lifespan context manager for startup and shutdown events"""
|
"""Lifespan context manager for startup and shutdown events"""
|
||||||
# Startup logic
|
# Startup logic
|
||||||
|
if args.auto_scan_at_startup:
|
||||||
try:
|
try:
|
||||||
new_files = doc_manager.scan_directory()
|
new_files = doc_manager.scan_directory()
|
||||||
for file_path in new_files:
|
for file_path in new_files:
|
||||||
@@ -683,7 +684,7 @@ def create_app(args):
|
|||||||
trace_exception(e)
|
trace_exception(e)
|
||||||
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
||||||
|
|
||||||
logging.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
|
ASCIIColors.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error during startup indexing: {str(e)}")
|
logging.error(f"Error during startup indexing: {str(e)}")
|
||||||
yield
|
yield
|
||||||
@@ -916,28 +917,6 @@ def create_app(args):
|
|||||||
else:
|
else:
|
||||||
logging.warning(f"No content extracted from file: {file_path}")
|
logging.warning(f"No content extracted from file: {file_path}")
|
||||||
|
|
||||||
@asynccontextmanager
|
|
||||||
async def lifespan(app: FastAPI):
|
|
||||||
"""Lifespan context manager for startup and shutdown events"""
|
|
||||||
# Startup logic
|
|
||||||
# Now only if this option is active, we can scan. This is better for big databases where there are hundreds of
|
|
||||||
# files. Makes the startup faster
|
|
||||||
if args.auto_scan_at_startup:
|
|
||||||
ASCIIColors.info("Auto scan is active, rescanning the input directory.")
|
|
||||||
try:
|
|
||||||
new_files = doc_manager.scan_directory()
|
|
||||||
for file_path in new_files:
|
|
||||||
try:
|
|
||||||
await index_file(file_path)
|
|
||||||
except Exception as e:
|
|
||||||
trace_exception(e)
|
|
||||||
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
|
||||||
|
|
||||||
logging.info(
|
|
||||||
f"Indexed {len(new_files)} documents from {args.input_dir}"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during startup indexing: {str(e)}")
|
|
||||||
|
|
||||||
@app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
|
@app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
|
||||||
async def scan_for_new_documents():
|
async def scan_for_new_documents():
|
||||||
|
Reference in New Issue
Block a user