Update lightrag_server.py
This commit is contained in:
@@ -408,6 +408,13 @@ def parse_args() -> argparse.Namespace:
|
|||||||
default=get_env_value("SSL_KEYFILE", None),
|
default=get_env_value("SSL_KEYFILE", None),
|
||||||
help="Path to SSL private key file (required if --ssl is enabled)",
|
help="Path to SSL private key file (required if --ssl is enabled)",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--auto-scan-at-startup',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Enable automatic scanning when the program starts'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
display_splash_screen(args)
|
display_splash_screen(args)
|
||||||
@@ -800,18 +807,21 @@ 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
|
||||||
try:
|
# Now only if this option is active, we can scan. This is better for big databases where there are hundreds of
|
||||||
new_files = doc_manager.scan_directory()
|
# files. Makes the startup faster
|
||||||
for file_path in new_files:
|
if args.auto_scan_at_startup:
|
||||||
try:
|
try:
|
||||||
await index_file(file_path)
|
new_files = doc_manager.scan_directory()
|
||||||
except Exception as e:
|
for file_path in new_files:
|
||||||
trace_exception(e)
|
try:
|
||||||
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
await index_file(file_path)
|
||||||
|
except Exception as e:
|
||||||
logging.info(f"Indexed {len(new_files)} documents from {args.input_dir}")
|
trace_exception(e)
|
||||||
except Exception as e:
|
logging.error(f"Error indexing file {file_path}: {str(e)}")
|
||||||
logging.error(f"Error during startup indexing: {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