ParisNeo commited on
Commit
06434f2
·
1 Parent(s): 0553d6a

Fixed startup scan

Browse files
Files changed (1) hide show
  1. lightrag/api/lightrag_server.py +12 -33
lightrag/api/lightrag_server.py CHANGED
@@ -674,18 +674,19 @@ def create_app(args):
674
  async def lifespan(app: FastAPI):
675
  """Lifespan context manager for startup and shutdown events"""
676
  # Startup logic
677
- try:
678
- new_files = doc_manager.scan_directory()
679
- for file_path in new_files:
680
- try:
681
- await index_file(file_path)
682
- except Exception as e:
683
- trace_exception(e)
684
- logging.error(f"Error indexing file {file_path}: {str(e)}")
 
685
 
686
- logging.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
687
- except Exception as e:
688
- logging.error(f"Error during startup indexing: {str(e)}")
689
  yield
690
  # Cleanup logic (if needed)
691
  pass
@@ -916,28 +917,6 @@ def create_app(args):
916
  else:
917
  logging.warning(f"No content extracted from file: {file_path}")
918
 
919
- @asynccontextmanager
920
- async def lifespan(app: FastAPI):
921
- """Lifespan context manager for startup and shutdown events"""
922
- # Startup logic
923
- # Now only if this option is active, we can scan. This is better for big databases where there are hundreds of
924
- # files. Makes the startup faster
925
- if args.auto_scan_at_startup:
926
- ASCIIColors.info("Auto scan is active, rescanning the input directory.")
927
- try:
928
- new_files = doc_manager.scan_directory()
929
- for file_path in new_files:
930
- try:
931
- await index_file(file_path)
932
- except Exception as e:
933
- trace_exception(e)
934
- logging.error(f"Error indexing file {file_path}: {str(e)}")
935
-
936
- logging.info(
937
- f"Indexed {len(new_files)} documents from {args.input_dir}"
938
- )
939
- except Exception as e:
940
- logging.error(f"Error during startup indexing: {str(e)}")
941
 
942
  @app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
943
  async def scan_for_new_documents():
 
674
  async def lifespan(app: FastAPI):
675
  """Lifespan context manager for startup and shutdown events"""
676
  # Startup logic
677
+ if args.auto_scan_at_startup:
678
+ try:
679
+ new_files = doc_manager.scan_directory()
680
+ for file_path in new_files:
681
+ try:
682
+ await index_file(file_path)
683
+ except Exception as e:
684
+ trace_exception(e)
685
+ logging.error(f"Error indexing file {file_path}: {str(e)}")
686
 
687
+ ASCIIColors.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
688
+ except Exception as e:
689
+ logging.error(f"Error during startup indexing: {str(e)}")
690
  yield
691
  # Cleanup logic (if needed)
692
  pass
 
917
  else:
918
  logging.warning(f"No content extracted from file: {file_path}")
919
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
920
 
921
  @app.post("/documents/scan", dependencies=[Depends(optional_api_key)])
922
  async def scan_for_new_documents():